From f30527c64fdab6373e3fd779d22027e746436463 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Tue, 20 Jun 2023 15:48:37 -0400 Subject: [PATCH] Add tests for SaveSupportingItems --- src/store/store.spec.js | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 334118c23..e35e463c6 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -982,6 +982,81 @@ describe("Actions", () => { expect(dispatch).toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); }); + it("saveSupportingItems, should call mutations", () => { + // Arrange + const context = { + state: state, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + // Act + actions.saveSupportingItems(context, []); + + // Assert + expect(commit).toBeCalledWith(storeMutations.UPDATE_SUPPORTING_ITEMS, []); + }); + + it("saveSupportingItems, should call reset logic when value is new", () => { + // Arrange + const context = { + state: { + order: { + lineItems: { + supportingItems: [ + "TestValue1", + "TestValue2" + ], + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + // Act + actions.saveSupportingItems(context, [ "TestValue3", "TestValue4", "TestValue5" ]); + + // Assert + expect(dispatch).toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); + }); + + it("saveSupportingItems, should not call reset logic when value is the same", () => { + // Arrange + const context = { + state: { + order: { + lineItems: { + supportingItems: [ + "TestValue1", + "TestValue2" + ], + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + // Act + actions.saveSupportingItems(context, [ "TestValue1", "TestValue2" ]); + + // Assert + expect(dispatch).not.toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); + }); + it("clearVin, should call mutation", () => { // Arrange const context = state;