mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
app cache handler unit test (#604)
This commit is contained in:
committed by
Kiran Niranjan
parent
49a96d5e9f
commit
b04aee5b9e
@@ -126,6 +126,12 @@ const getCurrentWindow = jest.fn(() => {
|
||||
};
|
||||
});
|
||||
|
||||
export const session = {
|
||||
defaultSession: {
|
||||
clearCache: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
export const remote = {
|
||||
app,
|
||||
getCurrentWindow,
|
||||
|
||||
36
spec/appCacheHandler.spec.ts
Normal file
36
spec/appCacheHandler.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { cleanUpAppCache, createAppCacheFile } from '../src/app/app-cache-handler';
|
||||
import { app, session } from './__mocks__/electron';
|
||||
|
||||
jest.mock('fs', () => ({
|
||||
writeFileSync: jest.fn(),
|
||||
existsSync: jest.fn(() => true),
|
||||
unlinkSync: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('app cache handler', () => {
|
||||
const cachePathExpected = path.join(app.getPath('userData'), 'CacheCheck');
|
||||
|
||||
it('should call `cleanUpAppCache` correctly', () => {
|
||||
const spyFn = 'unlinkSync';
|
||||
const spy = jest.spyOn(fs, spyFn);
|
||||
cleanUpAppCache();
|
||||
expect(spy).toBeCalledWith(cachePathExpected);
|
||||
});
|
||||
|
||||
it('should call `clearCache` when `session.defaultSession` is not null', () => {
|
||||
jest.spyOn(fs, 'existsSync').mockImplementation(() => false);
|
||||
const spyFn = 'clearCache';
|
||||
const spy = jest.spyOn(session.defaultSession, spyFn);
|
||||
cleanUpAppCache();
|
||||
expect(spy).lastCalledWith(expect.any(Function));
|
||||
});
|
||||
|
||||
it('should call `createAppCacheFile` correctly', () => {
|
||||
const spyFn = 'writeFileSync';
|
||||
const spy = jest.spyOn(fs, spyFn);
|
||||
createAppCacheFile();
|
||||
expect(spy).lastCalledWith(cachePathExpected, '');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user