mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
basic auth unit test (#582)
This commit is contained in:
parent
e2dbf4087d
commit
8d2fa4f049
1131
spec/__snapshots__/basicAuth.spec.ts.snap
Normal file
1131
spec/__snapshots__/basicAuth.spec.ts.snap
Normal file
File diff suppressed because it is too large
Load Diff
75
spec/basicAuth.spec.ts
Normal file
75
spec/basicAuth.spec.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import * as React from 'react';
|
||||
import BasicAuth from '../src/renderer/components/basic-auth';
|
||||
|
||||
describe('basic auth', () => {
|
||||
const usernameTargetMock: object = { target: { id: 'username', value: 'foo' }};
|
||||
const passwordTargetMock: object = { target: { id: 'password', value: '123456' }};
|
||||
const basicAuthMock: object = {
|
||||
hostname: 'example',
|
||||
isValidCredentials: true,
|
||||
password: '123456',
|
||||
username: 'foo',
|
||||
};
|
||||
const usernameMock = { username: 'foo' };
|
||||
const passwordMock = { password: '123456' };
|
||||
|
||||
it('should render correctly', () => {
|
||||
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should call `setState` when `change` is called', () => {
|
||||
const spy: jest.SpyInstance = jest.spyOn(BasicAuth.prototype, 'setState');
|
||||
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
|
||||
wrapper.find('#username').simulate('change', usernameTargetMock);
|
||||
expect(spy).lastCalledWith(usernameMock);
|
||||
wrapper.find('#password').simulate('change', passwordTargetMock);
|
||||
expect(spy).lastCalledWith(passwordMock);
|
||||
});
|
||||
|
||||
it('should call submit login', () => {
|
||||
const { ipcRenderer } = require('./__mocks__/electron');
|
||||
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, 'send');
|
||||
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
|
||||
wrapper.find('#username').simulate('change', usernameTargetMock);
|
||||
wrapper.find('#password').simulate('change', passwordTargetMock);
|
||||
wrapper.find('#basicAuth').simulate('submit');
|
||||
expect(spy).lastCalledWith('basic-auth-login', { ...usernameMock, ...passwordMock });
|
||||
});
|
||||
|
||||
it('should call `basic-auth-closed` event when cancel button is clicked', () => {
|
||||
const { ipcRenderer } = require('./__mocks__/electron');
|
||||
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, 'send');
|
||||
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
|
||||
wrapper.find('#cancel').simulate('click');
|
||||
expect(spy).lastCalledWith('basic-auth-closed', false);
|
||||
});
|
||||
|
||||
describe('basic auth mount and unmount event', () => {
|
||||
const { ipcRenderer } = require('./__mocks__/electron');
|
||||
const basicAuthDataLabel: string = 'basic-auth-data';
|
||||
const onLabelEvent: string = 'on';
|
||||
const removeListenerLabelEvent: string = 'removeListener';
|
||||
|
||||
it('should call `basic-auth-data` event when component is mounted', () => {
|
||||
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, onLabelEvent);
|
||||
shallow(React.createElement(BasicAuth));
|
||||
expect(spy).toBeCalledWith(basicAuthDataLabel, expect.any(Function));
|
||||
});
|
||||
|
||||
it('should remove listen `basic-auth-data` when component is unmounted', () => {
|
||||
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, removeListenerLabelEvent);
|
||||
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
|
||||
wrapper.unmount();
|
||||
expect(spy).toBeCalledWith(basicAuthDataLabel, expect.any(Function));
|
||||
});
|
||||
|
||||
it('should call `updateState` when component is mounted', () => {
|
||||
const spy: jest.SpyInstance = jest.spyOn(BasicAuth.prototype, 'setState');
|
||||
shallow(React.createElement(BasicAuth));
|
||||
ipcRenderer.send('basic-auth-data', basicAuthMock);
|
||||
expect(spy).toBeCalledWith(basicAuthMock);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user