Skip to content

Commit

Permalink
chore(log): Fix resin isCurrentFileVersion is always true
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jul 22, 2020
1 parent 028af26 commit c8fac56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/common/BaseAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type FileOptions = {
activeId?: string;
};
fileVersionId?: string;
isCurrentFileVersion?: boolean;
};
};

Expand Down Expand Up @@ -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,
},
};
Expand Down
44 changes: 21 additions & 23 deletions src/common/__tests__/BaseAnnotator-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit c8fac56

Please sign in to comment.