debian-mirror-gitlab/spec/javascripts/notes/stores/getters_spec.js

113 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import * as getters from '~/notes/stores/getters';
2018-11-08 19:23:39 +05:30
import {
notesDataMock,
userDataMock,
noteableDataMock,
individualNote,
collapseNotesMock,
} from '../mock_data';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
2018-03-17 18:26:18 +05:30
describe('Getters Notes Store', () => {
let state;
2018-11-08 19:23:39 +05:30
preloadFixtures(discussionWithTwoUnresolvedNotes);
2018-03-17 18:26:18 +05:30
beforeEach(() => {
state = {
2018-11-08 19:23:39 +05:30
discussions: [individualNote],
2018-03-17 18:26:18 +05:30
targetNoteHash: 'hash',
lastFetchedAt: 'timestamp',
2018-11-08 19:23:39 +05:30
isNotesFetched: false,
2018-03-17 18:26:18 +05:30
notesData: notesDataMock,
userData: userDataMock,
noteableData: noteableDataMock,
};
});
2018-11-08 19:23:39 +05:30
describe('discussions', () => {
it('should return all discussions in the store', () => {
expect(getters.discussions(state)).toEqual([individualNote]);
});
});
describe('resolvedDiscussionsById', () => {
it('ignores unresolved system notes', () => {
const [discussion] = getJSONFixture(discussionWithTwoUnresolvedNotes);
discussion.notes[0].resolved = true;
discussion.notes[1].resolved = false;
state.discussions.push(discussion);
expect(getters.resolvedDiscussionsById(state)).toEqual({
[discussion.id]: discussion,
});
});
});
describe('Collapsed notes', () => {
const stateCollapsedNotes = {
discussions: collapseNotesMock,
targetNoteHash: 'hash',
lastFetchedAt: 'timestamp',
notesData: notesDataMock,
userData: userDataMock,
noteableData: noteableDataMock,
};
it('should return a single system note when a description was updated multiple times', () => {
expect(getters.discussions(stateCollapsedNotes).length).toEqual(1);
2018-03-17 18:26:18 +05:30
});
});
describe('targetNoteHash', () => {
it('should return `targetNoteHash`', () => {
expect(getters.targetNoteHash(state)).toEqual('hash');
});
});
describe('getNotesData', () => {
it('should return all data in `notesData`', () => {
expect(getters.getNotesData(state)).toEqual(notesDataMock);
});
});
describe('getNoteableData', () => {
it('should return all data in `noteableData`', () => {
expect(getters.getNoteableData(state)).toEqual(noteableDataMock);
});
});
describe('getUserData', () => {
it('should return all data in `userData`', () => {
expect(getters.getUserData(state)).toEqual(userDataMock);
});
});
describe('notesById', () => {
it('should return the note for the given id', () => {
expect(getters.notesById(state)).toEqual({ 1390: individualNote.notes[0] });
});
});
describe('getCurrentUserLastNote', () => {
it('should return the last note of the current user', () => {
expect(getters.getCurrentUserLastNote(state)).toEqual(individualNote.notes[0]);
});
});
2018-03-27 19:54:05 +05:30
describe('openState', () => {
it('should return the issue state', () => {
expect(getters.openState(state)).toEqual(noteableDataMock.state);
});
});
2018-11-08 19:23:39 +05:30
describe('isNotesFetched', () => {
it('should return the state for the fetching notes', () => {
expect(getters.isNotesFetched(state)).toBeFalsy();
});
});
2018-03-17 18:26:18 +05:30
});