-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the conflictDialog class
- Loading branch information
1 parent
4a9c276
commit 938b7de
Showing
2 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/web-app-files/tests/unit/helpers/resource/conflictHandling/conflictDialog.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { mockDeep } from 'jest-mock-extended' | ||
import { Resource } from 'web-client' | ||
import { ConflictDialog, ResolveConflict } from 'web-app-files/src/helpers/resource' | ||
|
||
const getConflictDialogInstance = ({ createModal = jest.fn() } = {}) => { | ||
return new ConflictDialog(createModal, jest.fn(), jest.fn(), jest.fn(), jest.fn(), jest.fn()) | ||
} | ||
|
||
describe('conflict dialog', () => { | ||
describe('method "resolveAllConflicts"', () => { | ||
it('should return the resolved conflicts including the resource(s) and the strategy', async () => { | ||
const conflictDialog = getConflictDialogInstance() | ||
const strategy = mockDeep<ResolveConflict>() | ||
conflictDialog.resolveFileExists = jest.fn().mockImplementation(() => ({ | ||
strategy, | ||
doForAllConflicts: false | ||
})) | ||
const resource = mockDeep<Resource>({ name: 'someFile.txt' }) | ||
const targetFolder = mockDeep<Resource>({ path: '/' }) | ||
const targetFolderResources = [mockDeep<Resource>({ path: '/someFile.txt' })] | ||
const resolvedConflicts = await conflictDialog.resolveAllConflicts( | ||
[resource], | ||
targetFolder, | ||
targetFolderResources | ||
) | ||
|
||
expect(resolvedConflicts.length).toBe(1) | ||
expect(resolvedConflicts[0].resource).toEqual(resource) | ||
expect(resolvedConflicts[0].strategy).toEqual(strategy) | ||
}) | ||
}) | ||
describe('method "resolveFileExists"', () => { | ||
it('should create the modal in the end', () => { | ||
const createModal = jest.fn() | ||
const conflictDialog = getConflictDialogInstance({ createModal }) | ||
conflictDialog.resolveFileExists(mockDeep<Resource>(), 2, true) | ||
expect(createModal).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |