SymphonyElectron/spec/welcome.spec.ts
Salah Benmoussati 33664a8410
SDA-3900 Third-party browser login (#1701)
* SDA-3901 (Add new implementation for welcome screen) (#1519)

* SDA-3901 - Add new welcome screen

* SDA-3901 - Change to global config

* SDA-3901 - Add locale

* SDA-3901 - Reposition protocol handling

* SDA-3901 - Fix protocol handler

* SDA-3901 - Fix protocol handler

* SDA-3901 - Fix welcome screen load

* SDA-3901 - Fix seamless login url

* SDA-3901 - Validate if pod is configured for SSO

* SDA-3900 Several bug fix

* SDA-3900 Ability to enable third-party browser login via command line install

* SDA-3900 Typo fix

---------

Co-authored-by: Kiran Niranjan <kiran.niranjan@symphony.com>
2023-02-08 09:14:17 +01:00

124 lines
3.9 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,
isPodConfigured: false,
isSeamlessLoginEnabled: true,
};
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,
};
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,
};
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 set pod url', () => {
const spy = jest.spyOn(Welcome.prototype, 'setState');
const setPodUrlSpy = jest.spyOn(Welcome.prototype, 'login');
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);
});
it('should not show pod url input field', () => {
const welcomeMock = {
url: 'https://my.symphony.com',
message: '',
urlValid: true,
isPodConfigured: true,
isSeamlessLoginEnabled: true,
};
const wrapper = shallow(React.createElement(Welcome));
ipcRenderer.send('welcome', welcomeMock);
const podUrlBox = `input.Welcome-main-container-podurl-box`;
expect(wrapper.find(podUrlBox).getElements()).toEqual([]);
});
});