From 2922ea054b5b77cfcb6c01e067ee437aa0591b8c Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Wed, 16 Aug 2023 13:23:10 -0700 Subject: [PATCH] fix: Merge persisted state into default state by default (#6898) This commit updates `PersistantStore.generateDefaultState` to merge in `persistedState` to `defaultState`, rather than just returning `persistedState` as-is. Addresses #6233. --- src/common/flux/persistent-store.ts | 7 ++++--- .../stores/assessment-card-selection-store.test.ts | 11 +++++++++++ .../tests/background/stores/persistent-store.test.ts | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/flux/persistent-store.ts b/src/common/flux/persistent-store.ts index aea0df426b0..99bc22c676b 100644 --- a/src/common/flux/persistent-store.ts +++ b/src/common/flux/persistent-store.ts @@ -4,7 +4,7 @@ import { BaseStoreImpl } from 'background/stores/base-store-impl'; import { IndexedDBAPI } from 'common/indexedDB/indexedDB'; import { Logger } from 'common/logging/logger'; import { StoreNames } from 'common/stores/store-names'; -import { cloneDeep, isEqual } from 'lodash'; +import { cloneDeep, isEmpty, isEqual, merge } from 'lodash'; export abstract class PersistentStore extends BaseStoreImpl> { private previouslyPersistedState: TState | null; @@ -30,13 +30,14 @@ export abstract class PersistentStore extends BaseStoreImpl { function createStoreForAssessmentCardSelectionActions( actionName: keyof AssessmentCardSelectionActions, ): StoreTester { + const assessmentStoreState: AssessmentStoreData = createAssessmentStoreDataWithStatus( + ManualTestStatus.UNKNOWN, + ); const factory = (actions: AssessmentCardSelectionActions) => new AssessmentCardSelectionStore( actions, @@ -763,6 +766,8 @@ describe('AssessmentCardSelectionStore Test', () => { null, ); + setupDataGeneratorMock(null, assessmentStoreState); + return new StoreTester(AssessmentCardSelectionActions, actionName, factory); } @@ -770,6 +775,10 @@ describe('AssessmentCardSelectionStore Test', () => { actionName: keyof AssessmentActions, assessmentsProvider?: AssessmentsProvider, ): StoreTester { + const assessmentStoreState: AssessmentStoreData = createAssessmentStoreDataWithStatus( + ManualTestStatus.UNKNOWN, + ); + const factory = (actions: AssessmentActions) => new AssessmentCardSelectionStore( new AssessmentCardSelectionActions(), @@ -784,6 +793,8 @@ describe('AssessmentCardSelectionStore Test', () => { null, ); + setupDataGeneratorMock(null, assessmentStoreState); + return new StoreTester(AssessmentActions, actionName, factory); } diff --git a/src/tests/unit/tests/background/stores/persistent-store.test.ts b/src/tests/unit/tests/background/stores/persistent-store.test.ts index ba89442fe17..c887d020db6 100644 --- a/src/tests/unit/tests/background/stores/persistent-store.test.ts +++ b/src/tests/unit/tests/background/stores/persistent-store.test.ts @@ -34,7 +34,7 @@ describe('PersistentStoreTest', () => { testObject.initialize(); - expect(testObject.getState()).toBe(persistedState); + expect(testObject.getState()).toStrictEqual(persistedState); }); test('Initialize without persisted data', async () => {