diff --git a/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts b/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts index 2219e3eacb..296765df33 100644 --- a/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts +++ b/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts @@ -404,35 +404,32 @@ describe('Gn4Repository', () => { }) }) describe('#clearRecordDraft', () => { - beforeEach(async () => { - await lastValueFrom( - repository.clearRecordDraft(DATASET_RECORD_SIMPLE.uniqueIdentifier) - ) + beforeEach(() => { + repository.clearRecordDraft(DATASET_RECORD_SIMPLE.uniqueIdentifier) }) it('removes the record draft', async () => { - const record = await lastValueFrom( + const [record] = await lastValueFrom( repository.openRecordForEdition( DATASET_RECORD_SIMPLE.uniqueIdentifier ) ) expect(record?.title).not.toBe('The title has been modified') - const hasDraft = await lastValueFrom( - repository.recordHasDraft(DATASET_RECORD_SIMPLE.uniqueIdentifier) + const hasDraft = repository.recordHasDraft( + DATASET_RECORD_SIMPLE.uniqueIdentifier ) + expect(hasDraft).toBe(false) }) }) describe('#recordHasDraft', () => { - it('returns true when there is a draft', async () => { - const hasDraft = await lastValueFrom( - repository.recordHasDraft(DATASET_RECORD_SIMPLE.uniqueIdentifier) + it('returns true when there is a draft', () => { + const hasDraft = repository.recordHasDraft( + DATASET_RECORD_SIMPLE.uniqueIdentifier ) expect(hasDraft).toBe(true) }) - it('returns false otherwise', async () => { - const hasDraft = await lastValueFrom( - repository.recordHasDraft('blargz') - ) + it('returns false otherwise', () => { + const hasDraft = repository.recordHasDraft('blargz') expect(hasDraft).toBe(false) }) }) diff --git a/libs/api/repository/src/lib/gn4/gn4-repository.ts b/libs/api/repository/src/lib/gn4/gn4-repository.ts index e1e71faaa7..387227b6c8 100644 --- a/libs/api/repository/src/lib/gn4/gn4-repository.ts +++ b/libs/api/repository/src/lib/gn4/gn4-repository.ts @@ -290,15 +290,14 @@ export class Gn4Repository implements RecordsRepositoryInterface { ) } - clearRecordDraft(uniqueIdentifier: string): Observable { + clearRecordDraft(uniqueIdentifier: string): void { window.localStorage.removeItem( this.getLocalStorageKeyForRecord(uniqueIdentifier) ) - return of(undefined) } - recordHasDraft(uniqueIdentifier: string): Observable { - return of( + recordHasDraft(uniqueIdentifier: string): boolean { + return ( window.localStorage.getItem( this.getLocalStorageKeyForRecord(uniqueIdentifier) ) !== null diff --git a/libs/common/domain/src/lib/repository/records-repository.interface.ts b/libs/common/domain/src/lib/repository/records-repository.interface.ts index 6940e53473..f7a9fb3026 100644 --- a/libs/common/domain/src/lib/repository/records-repository.interface.ts +++ b/libs/common/domain/src/lib/repository/records-repository.interface.ts @@ -50,6 +50,6 @@ export abstract class RecordsRepositoryInterface { referenceRecordSource?: string ): Observable - abstract clearRecordDraft(uniqueIdentifier: string): Observable - abstract recordHasDraft(uniqueIdentifier: string): Observable + abstract clearRecordDraft(uniqueIdentifier: string): void + abstract recordHasDraft(uniqueIdentifier: string): boolean } diff --git a/libs/feature/editor/src/lib/+state/editor.effects.spec.ts b/libs/feature/editor/src/lib/+state/editor.effects.spec.ts index d50b4eca99..631ad05807 100644 --- a/libs/feature/editor/src/lib/+state/editor.effects.spec.ts +++ b/libs/feature/editor/src/lib/+state/editor.effects.spec.ts @@ -15,7 +15,7 @@ class EditorServiceMock { saveRecordAsDraft = jest.fn(() => of('blabla')) } class RecordsRepositoryMock { - recordHasDraft = jest.fn(() => of(true)) + recordHasDraft = jest.fn(() => true) } describe('EditorEffects', () => { @@ -157,7 +157,7 @@ describe('EditorEffects', () => { beforeEach(() => { ;( TestBed.inject(RecordsRepositoryInterface).recordHasDraft as jest.Mock - ).mockImplementationOnce(() => of(false)) + ).mockImplementationOnce(() => false) }) it('dispatches nothing', () => { actions = hot('-a-|', { diff --git a/libs/feature/editor/src/lib/+state/editor.effects.ts b/libs/feature/editor/src/lib/+state/editor.effects.ts index 6df6eaa347..e435d0d335 100644 --- a/libs/feature/editor/src/lib/+state/editor.effects.ts +++ b/libs/feature/editor/src/lib/+state/editor.effects.ts @@ -67,7 +67,7 @@ export class EditorEffects { checkHasChangesOnOpen$ = createEffect(() => this.actions$.pipe( ofType(EditorActions.openRecord), - switchMap(({ record }) => + map(({ record }) => this.recordsRepository.recordHasDraft(record.uniqueIdentifier) ), filter((hasDraft) => hasDraft), diff --git a/libs/feature/search/src/lib/results-table/results-table.component.html b/libs/feature/search/src/lib/results-table/results-table.component.html index 4869709465..27c50e1217 100644 --- a/libs/feature/search/src/lib/results-table/results-table.component.html +++ b/libs/feature/search/src/lib/results-table/results-table.component.html @@ -37,7 +37,7 @@
{{ item.title }} of(false)) + recordHasDraft = jest.fn(() => false) } describe('ResultsTableComponent', () => { diff --git a/libs/feature/search/src/lib/results-table/results-table.component.ts b/libs/feature/search/src/lib/results-table/results-table.component.ts index 0f65fa6bd5..64f498ac98 100644 --- a/libs/feature/search/src/lib/results-table/results-table.component.ts +++ b/libs/feature/search/src/lib/results-table/results-table.component.ts @@ -166,7 +166,7 @@ export class ResultsTableComponent { ) } - hasDraft(record: CatalogRecord): Observable { + hasDraft(record: CatalogRecord): boolean { return this.recordsRepository.recordHasDraft(record.uniqueIdentifier) } }