mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-26 02:40:24 -06:00
a240621a17
* SDA-1983: create the new welcome window Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: add logic to validate pod url and open welcome page on startup conditionally Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: add unit tests and finish the full logic implementation Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: minor fixes Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: fix sso double slash Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: fix deleting url from global config object Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: simplify setting user config Co-Authored-By: Kiran Niranjan <kiranleo1992@gmail.com> * SDA-1983: delete unused variable Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1983: add japanese and french translations Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> Co-authored-by: Kiran Niranjan <kiranleo1992@gmail.com>
133 lines
4.5 KiB
TypeScript
133 lines
4.5 KiB
TypeScript
import { shallow } from 'enzyme';
|
|
import * as React from 'react';
|
|
import Welcome from '../src/renderer/components/welcome';
|
|
import { ipcRenderer } from './__mocks__/electron';
|
|
|
|
describe('welcome', () => {
|
|
const welcomeLabel = 'welcome';
|
|
const welcomeMock = {
|
|
url: 'https://my.symphony.com',
|
|
message: '',
|
|
urlValid: true,
|
|
sso: false,
|
|
};
|
|
const onLabelEvent = 'on';
|
|
const removeListenerLabelEvent = 'removeListener';
|
|
|
|
it('should render correctly', () => {
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('should call `welcome` event when component is mounted', () => {
|
|
const spy = jest.spyOn(ipcRenderer, onLabelEvent);
|
|
shallow(React.createElement(Welcome));
|
|
expect(spy).toBeCalledWith(welcomeLabel, expect.any(Function));
|
|
});
|
|
|
|
it('should remove listener `welcome` when component is unmounted', () => {
|
|
const spyMount = jest.spyOn(ipcRenderer, onLabelEvent);
|
|
const spyUnmount = jest.spyOn(ipcRenderer, removeListenerLabelEvent);
|
|
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
expect(spyMount).toBeCalledWith(welcomeLabel, expect.any(Function));
|
|
|
|
wrapper.unmount();
|
|
expect(spyUnmount).toBeCalledWith(welcomeLabel, expect.any(Function));
|
|
});
|
|
|
|
it('should call `updateState` when component is mounted', () => {
|
|
const spy = jest.spyOn(Welcome.prototype, 'setState');
|
|
shallow(React.createElement(Welcome));
|
|
|
|
ipcRenderer.send('welcome', welcomeMock);
|
|
|
|
expect(spy).toBeCalledWith(welcomeMock);
|
|
});
|
|
|
|
it('should change pod url in text box', () => {
|
|
const podUrlMock = {
|
|
url: 'https://corporate.symphony.com',
|
|
message: '',
|
|
urlValid: true,
|
|
sso: false,
|
|
};
|
|
|
|
const spy = jest.spyOn(Welcome.prototype, 'setState');
|
|
const updatePodUrlSpy = jest.spyOn(Welcome.prototype, 'updatePodUrl');
|
|
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
ipcRenderer.send('welcome', welcomeMock);
|
|
|
|
const welcomePodUrlBox = `input.Welcome-main-container-podurl-box`;
|
|
const input = wrapper.find(welcomePodUrlBox);
|
|
|
|
input.simulate('focus');
|
|
input.simulate('change', {target: {value: 'https://corporate.symphony.com'}});
|
|
|
|
expect(updatePodUrlSpy).toBeCalled();
|
|
expect(spy).toBeCalledWith(podUrlMock);
|
|
});
|
|
|
|
it('should show message for invalid pod url', () => {
|
|
const podUrlMock = {
|
|
url: 'abcdef',
|
|
message: 'Please enter a valid url',
|
|
urlValid: false,
|
|
sso: false,
|
|
};
|
|
|
|
const spy = jest.spyOn(Welcome.prototype, 'setState');
|
|
const updatePodUrlSpy = jest.spyOn(Welcome.prototype, 'updatePodUrl');
|
|
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
ipcRenderer.send('welcome', welcomeMock);
|
|
|
|
const welcomePodUrlBox = `input.Welcome-main-container-podurl-box`;
|
|
const input = wrapper.find(welcomePodUrlBox);
|
|
|
|
input.simulate('focus');
|
|
input.simulate('change', {target: {value: 'abcdef'}});
|
|
|
|
expect(updatePodUrlSpy).toBeCalled();
|
|
expect(spy).toBeCalledWith(podUrlMock);
|
|
});
|
|
|
|
it('should click sso checkbox', () => {
|
|
const podUrlMock = {
|
|
url: 'https://my.symphony.com',
|
|
message: '',
|
|
urlValid: true,
|
|
sso: true,
|
|
};
|
|
|
|
const spy = jest.spyOn(Welcome.prototype, 'setState');
|
|
const updatePodUrlSpy = jest.spyOn(Welcome.prototype, 'updateSsoCheckbox');
|
|
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
ipcRenderer.send('welcome', welcomeMock);
|
|
|
|
const welcomePodUrlBox = `input[type="checkbox"]`;
|
|
const input = wrapper.find(welcomePodUrlBox);
|
|
|
|
input.simulate('focus');
|
|
input.simulate('change', {target: {checked: true}});
|
|
|
|
expect(updatePodUrlSpy).toBeCalled();
|
|
expect(spy).toBeCalledWith(podUrlMock);
|
|
});
|
|
|
|
it('should set pod url', () => {
|
|
const spy = jest.spyOn(Welcome.prototype, 'setState');
|
|
const setPodUrlSpy = jest.spyOn(Welcome.prototype, 'setPodUrl');
|
|
|
|
const wrapper = shallow(React.createElement(Welcome));
|
|
ipcRenderer.send('welcome', welcomeMock);
|
|
const welcomeContinueButton = `button.Welcome-continue-button`;
|
|
wrapper.find(welcomeContinueButton).simulate('click');
|
|
|
|
expect(setPodUrlSpy).toBeCalled();
|
|
expect(spy).toBeCalledWith(welcomeMock);
|
|
});
|
|
});
|