Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core/presentation): add basic tests for ApplicationsPickerInput.tsx
- Loading branch information
1 parent
f1b0caf
commit cc7001d
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
app/scripts/modules/core/src/widgets/ApplicationsPickerInput.spec.tsx
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,36 @@ | ||
import { ApplicationReader } from 'core/application'; | ||
import { IValidator } from 'core/presentation'; | ||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
import { ApplicationsPickerInput } from './ApplicationsPickerInput'; | ||
|
||
describe('ApplicationsPickerInput', () => { | ||
function listApplicationsSpy() { | ||
return spyOn(ApplicationReader, 'listApplications').and.callFake(() => { | ||
return Promise.resolve([{ name: 'app1' }, { name: 'app2' }]); | ||
}); | ||
} | ||
|
||
function asyncTick() { | ||
return new Promise(resolve => setTimeout(resolve)); | ||
} | ||
|
||
it('lists applications on mount', () => { | ||
const spy = listApplicationsSpy(); | ||
mount(<ApplicationsPickerInput />); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('registers a validator that validates the selected application exists', async () => { | ||
listApplicationsSpy(); | ||
const validationSpy = jasmine.createSpyObj(['addValidator', 'removeValidator', 'revalidate']); | ||
mount(<ApplicationsPickerInput value={'app1'} validation={validationSpy} />); | ||
await asyncTick(); // let the listApplications promise resolve | ||
|
||
expect(validationSpy.addValidator).toHaveBeenCalledTimes(1); | ||
const validator: IValidator = validationSpy.addValidator.calls.mostRecent().args[0]; | ||
|
||
expect(validator('app1')).toBeFalsy(); | ||
expect(validator('notexists')).toContain('notexists does not exist'); | ||
}); | ||
}); |