PlatformService tests

This commit is contained in:
ziajka 2019-01-28 11:12:46 +01:00
parent 65acfbb11c
commit ed204d3229

View File

@ -1,12 +1,57 @@
import { TestBed } from '@angular/core/testing';
import { PlatformService } from './platform.service';
import { ElectronService } from 'ngx-electron';
class ElectronServiceMock {
process = {
platform: 'unknown'
};
}
describe('PlatformService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
let electronServiceMock: ElectronServiceMock;
let service: PlatformService;
beforeEach(() => {
electronServiceMock = new ElectronServiceMock();
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
PlatformService,
{provide: ElectronService, useValue: electronServiceMock}
]
});
});
beforeEach(() => {
service = TestBed.get(PlatformService);
})
it('should be created', () => {
const service: PlatformService = TestBed.get(PlatformService);
expect(service).toBeTruthy();
});
it('should be on windows platform', () => {
electronServiceMock.process.platform = 'win32';
expect(service.isWindows()).toBeTruthy();
expect(service.isDarwin()).toBeFalsy();
expect(service.isLinux()).toBeFalsy();
});
it('should be on linux platform', () => {
electronServiceMock.process.platform = 'linux';
expect(service.isWindows()).toBeFalsy();
expect(service.isDarwin()).toBeFalsy();
expect(service.isLinux()).toBeTruthy();
});
it('should be on darwin platform', () => {
electronServiceMock.process.platform = 'darwin';
expect(service.isWindows()).toBeFalsy();
expect(service.isDarwin()).toBeTruthy();
expect(service.isLinux()).toBeFalsy();
});
});