From c8fac5633d269b5beea31dbf9d883258ccb77e71 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Tue, 21 Jul 2020 22:54:31 -0700 Subject: [PATCH] chore(log): Fix resin isCurrentFileVersion is always true --- src/common/BaseAnnotator.ts | 3 +- src/common/__tests__/BaseAnnotator-test.ts | 44 +++++++++++----------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/common/BaseAnnotator.ts b/src/common/BaseAnnotator.ts index a57fd0384..e92f625ba 100644 --- a/src/common/BaseAnnotator.ts +++ b/src/common/BaseAnnotator.ts @@ -15,6 +15,7 @@ export type FileOptions = { activeId?: string; }; fileVersionId?: string; + isCurrentFileVersion?: boolean; }; }; @@ -63,7 +64,7 @@ export default class BaseAnnotator extends EventEmitter { options: { fileId: file.id, fileVersionId: fileOptionsVersionId ?? fileVersionId, - isCurrentFileVersion: !fileOptionsVersionId || fileOptionsVersionId === fileVersionId, + isCurrentFileVersion: !fileOptionsVersionId || !!fileOptionsValue?.isCurrentFileVersion, permissions: file.permissions, }, }; diff --git a/src/common/__tests__/BaseAnnotator-test.ts b/src/common/__tests__/BaseAnnotator-test.ts index 24ced7a9c..13049b058 100644 --- a/src/common/__tests__/BaseAnnotator-test.ts +++ b/src/common/__tests__/BaseAnnotator-test.ts @@ -109,31 +109,29 @@ describe('BaseAnnotator', () => { }); test.each` - fileOptionsVersionId | fileVersionId | isCurrentFileVersion - ${'0'} | ${'0'} | ${true} - ${undefined} | ${'0'} | ${true} - ${'1'} | ${'0'} | ${false} - `( - 'should set isCurrentFileVersion to $isCurrentFileVersion', - ({ fileOptionsVersionId, fileVersionId, isCurrentFileVersion }) => { - const file = { - ...defaults.file, - file_version: { id: fileVersionId }, - }; - const fileOptions = { - '12345': { - fileVersionId: fileOptionsVersionId, - }, - }; + fileOptionsVersionId | isCurrentFileVersion | result + ${'0'} | ${true} | ${true} + ${undefined} | ${false} | ${true} + ${'1'} | ${false} | ${false} + `('should set isCurrentFileVersion to $result', ({ fileOptionsVersionId, isCurrentFileVersion, result }) => { + const file = { + ...defaults.file, + file_version: { id: '0' }, + }; + const fileOptions = { + '12345': { + fileVersionId: fileOptionsVersionId, + isCurrentFileVersion, + }, + }; - annotator = getAnnotator({ file, fileOptions }); + annotator = getAnnotator({ file, fileOptions }); - expect(store.createStore).toHaveBeenLastCalledWith( - expect.objectContaining({ options: expect.objectContaining({ isCurrentFileVersion }) }), - expect.any(Object), - ); - }, - ); + expect(store.createStore).toHaveBeenLastCalledWith( + expect.objectContaining({ options: expect.objectContaining({ isCurrentFileVersion: result }) }), + expect.any(Object), + ); + }); }); describe('destroy()', () => {