mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
|
import electron from 'electron';
|
||
|
import { mocked } from 'ts-jest/utils';
|
||
|
|
||
|
import { getConfigSettings as _getConfigSettings } from '../../models/helpers/settings';
|
||
|
import { validateInsomniaConfig } from '../validate-insomnia-config';
|
||
|
|
||
|
jest.mock('electron');
|
||
|
jest.mock('../../models/helpers/settings');
|
||
|
const electronAppExit = mocked(electron.app.exit);
|
||
|
const electronShowErrorBox = mocked(electron.dialog.showErrorBox);
|
||
|
const getConfigSettings = mocked(_getConfigSettings);
|
||
|
|
||
|
describe('validateInsomniaConfig', () => {
|
||
|
it('should show error box and exit if there is an error', () => {
|
||
|
// Arrange
|
||
|
const errorReturn = {
|
||
|
error: {
|
||
|
errors: [],
|
||
|
insomniaConfig: 'abc',
|
||
|
configPath: 'configPath',
|
||
|
},
|
||
|
};
|
||
|
getConfigSettings.mockReturnValue(errorReturn);
|
||
|
|
||
|
// Act
|
||
|
validateInsomniaConfig();
|
||
|
|
||
|
// Assert
|
||
|
expect(electronShowErrorBox).toHaveBeenCalled();
|
||
|
expect(electronAppExit).toHaveBeenCalled();
|
||
|
});
|
||
|
|
||
|
it('should not exit if there are no errors', () => {
|
||
|
// Arrange
|
||
|
const validReturn = { enableAnalytics: true };
|
||
|
getConfigSettings.mockReturnValue(validReturn);
|
||
|
|
||
|
// Act
|
||
|
validateInsomniaConfig();
|
||
|
|
||
|
// Assert
|
||
|
expect(electronShowErrorBox).not.toHaveBeenCalled();
|
||
|
expect(electronAppExit).not.toHaveBeenCalled();
|
||
|
});
|
||
|
});
|