Adds specs for toggleFileDiscussions action
This commit is contained in:
parent
57c32c7dbd
commit
c5a514de76
2 changed files with 45 additions and 3 deletions
|
@ -103,9 +103,7 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => {
|
|||
|
||||
if (shouldCloseAll) {
|
||||
dispatch('collapseDiscussion', data, { root: true });
|
||||
} else if (shouldExpandAll) {
|
||||
dispatch('expandDiscussion', data, { root: true });
|
||||
} else if (!shouldCloseAll && !shouldExpandAll && !discussion.expanded) {
|
||||
} else if (shouldExpandAll || (!shouldCloseAll && !shouldExpandAll && !discussion.expanded)) {
|
||||
dispatch('expandDiscussion', data, { root: true });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -191,4 +191,48 @@ describe('DiffsStoreActions', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleFileDiscussions', () => {
|
||||
it('should dispatch collapseDiscussion when all discussions are expanded', () => {
|
||||
const getters = {
|
||||
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]),
|
||||
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(true),
|
||||
diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(false),
|
||||
};
|
||||
|
||||
const dispatch = jasmine.createSpy('dispatch');
|
||||
|
||||
actions.toggleFileDiscussions({ getters, dispatch });
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith('collapseDiscussion', { discussionId: 1 }, { root: true });
|
||||
});
|
||||
|
||||
it('should dispatch expandDiscussion when all discussions are collapsed', () => {
|
||||
const getters = {
|
||||
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]),
|
||||
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false),
|
||||
diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(true),
|
||||
};
|
||||
|
||||
const dispatch = jasmine.createSpy();
|
||||
|
||||
actions.toggleFileDiscussions({ getters, dispatch });
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true });
|
||||
});
|
||||
|
||||
it('should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion', () => {
|
||||
const getters = {
|
||||
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ expanded: false, id: 1 }]),
|
||||
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false),
|
||||
diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(false),
|
||||
};
|
||||
|
||||
const dispatch = jasmine.createSpy();
|
||||
|
||||
actions.toggleFileDiscussions({ getters, dispatch });
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue