diff --git a/src/services/workflow.service.js b/src/services/workflow.service.js index b1ec1b032b..d096123f9b 100644 --- a/src/services/workflow.service.js +++ b/src/services/workflow.service.js @@ -16,7 +16,7 @@ */ import isEqual from 'lodash/isEqual' -import union from 'lodash/union' +import unionBy from 'lodash/unionBy' import ViewState from '@/model/ViewState.model' import Subscription from '@/model/Subscription.model' import { @@ -324,7 +324,9 @@ class WorkflowService { throw new Error('Error recomputing subscription: Query variables do not match.') } this.mergeQueries(baseSubscriber.query.query, subscriber.query.query) - subscription.callbacks = union(subscription.callbacks, subscriber.query.callbacks) + // Combine the arrays of callbacks, creating an array of unique callbacks. + // The callbacks are compared by their class/constructor name. + subscription.callbacks = unionBy(subscription.callbacks, subscriber.query.callbacks, (callback) => callback.constructor.name) } const finalQuery = print(baseSubscriber.query.query) // TODO: consider using a better approach than print(a) === print(b) diff --git a/tests/unit/services/workflow.service.spec.js b/tests/unit/services/workflow.service.spec.js index bebb4c0f33..6d953b067b 100644 --- a/tests/unit/services/workflow.service.spec.js +++ b/tests/unit/services/workflow.service.spec.js @@ -35,6 +35,13 @@ const sandbox = sinon.createSandbox() Vue.use(Vuex) +if (!global.localStorage) { + global.localStorage = { + getItem () { return '{}' }, + setItem () {} + } +} + describe('WorkflowService', () => { /** * @type {String} @@ -264,7 +271,7 @@ describe('WorkflowService', () => { const finalQuery = print(service.subscriptions.root.query.query) expect(expectedQuery1).to.equal(finalQuery) }) - it('should not add duplicate action names', () => { + it('should not add duplicate callbacks', () => { const newCallbacks = [ new WorkflowCallback(), new TreeCallback() @@ -281,10 +288,10 @@ describe('WorkflowService', () => { query: newSubscriptionQuery } service.subscribe(anotherView) - // Same action names, Lodash's union should add to list like a set + // Same callbacks, Lodash's union should add to list like a set expect(subscriptionQuery.callbacks).to.deep.equal(newCallbacks) }) - it('should add new action names', () => { + it('should add new callbacks', () => { const baseCallbacks = [new WorkflowCallback()] subscriptionQuery.callbacks.push(...baseCallbacks) const newCallbacks = [new TreeCallback()] @@ -299,7 +306,7 @@ describe('WorkflowService', () => { query: newSubscriptionQuery } service.subscribe(anotherView) - // Same action names, Lodash's union should add to list like a set + // Same callbacks, Lodash's union should add to list like a set expect(subscription.callbacks).to.deep.equal([...baseCallbacks, new TreeCallback()]) }) it('should throw an error if there are no subscribers', () => {