ed-safari/test/Settings.test.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-05-17 14:43:14 -07:00
import {expect} from '@jest/globals';
import {Settings} from '../src/models/Settings';
jest.mock('fs');
describe('Settings', () => {
const settingsFile = {
minValue: 500000,
maxDistance: 10000,
matrixFile: '',
};
beforeEach(() => {
require('fs').__setFileContents(JSON.stringify(settingsFile));
});
describe('get()', () => {
it('should get instance', () => {
expect(Settings.get()).toBeInstanceOf(Settings);
});
it('should set initial values', () => {
const minValue = Settings.get().minValue;
expect(minValue).toBeDefined();
expect(typeof minValue).toBe('number');
const maxDistance = Settings.get().maxDistance;
expect(maxDistance).toBeDefined();
expect(typeof maxDistance).toBe('number');
const matrix = Settings.get().matrix;
expect(matrix).toBeUndefined();
});
});
describe('save()', () => {
it('should return boolean', async () => {
const result = await Settings.get().save(settingsFile);
expect(typeof result).toBe('boolean');
require('fs').__setWritePromise(true);
const resultResolve = await Settings.get().save(settingsFile);
expect(resultResolve).toBe(true);
require('fs').__setWritePromise(false);
const resultReject = await Settings.get().save(settingsFile);
expect(resultReject).toBe(false);
});
});
});