summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2018-07-11 15:30:41 +0100
committerFilipa Lacerda <filipa@gitlab.com>2018-07-11 15:30:41 +0100
commitc5a514de767f1d6b66443552bdc16d09370d9d07 (patch)
treeeeb2a127796232f29cce696beafa3f0f2cb924f9
parent57c32c7dbdd470b1ea31edf412e8bb0aa6261e21 (diff)
downloadgitlab-ce-c5a514de767f1d6b66443552bdc16d09370d9d07.tar.gz
Adds specs for toggleFileDiscussions action
-rw-r--r--app/assets/javascripts/diffs/store/actions.js4
-rw-r--r--spec/javascripts/diffs/store/actions_spec.js44
2 files changed, 45 insertions, 3 deletions
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js
index e5bb9904664..27001142257 100644
--- a/app/assets/javascripts/diffs/store/actions.js
+++ b/app/assets/javascripts/diffs/store/actions.js
@@ -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 });
}
});
diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js
index 6829c1e956a..c1560dac1a0 100644
--- a/spec/javascripts/diffs/store/actions_spec.js
+++ b/spec/javascripts/diffs/store/actions_spec.js
@@ -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 });
+ });
+ });
});