diff --git a/src/app/services/external-software-definition.service.spec.ts b/src/app/services/external-software-definition.service.spec.ts index 9939de78..de4b073d 100644 --- a/src/app/services/external-software-definition.service.spec.ts +++ b/src/app/services/external-software-definition.service.spec.ts @@ -1,12 +1,97 @@ import { TestBed } from '@angular/core/testing'; import { ExternalSoftwareDefinitionService } from './external-software-definition.service'; +import { PlatformService } from './platform.service'; + +import Spy = jasmine.Spy; + +class PlatformServiceMock { + platform: string; + isWindows() { + return this.platform == 'windows'; + } + isLinux() { + return this.platform == 'linux'; + } + isDarwin() { + return this.platform == 'darwin'; + } +} + describe('ExternalSoftwareDefinitionService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let platformServiceMock: PlatformServiceMock; + let service: ExternalSoftwareDefinitionService; + + beforeEach(() => { + platformServiceMock = new PlatformServiceMock(); + }); + + beforeEach(() => TestBed.configureTestingModule({ + providers: [ + ExternalSoftwareDefinitionService, + { provide: PlatformService, useValue: platformServiceMock} + ] + })); + + beforeEach(() => { + service = TestBed.get(ExternalSoftwareDefinitionService); + }) it('should be created', () => { - const service: ExternalSoftwareDefinitionService = TestBed.get(ExternalSoftwareDefinitionService); expect(service).toBeTruthy(); }); + + it('should return list for windows', () => { + let software = service.getForWindows(); + expect(software.length).toEqual(1); + }); + + it('should return list for linux', () => { + let software = service.getForLinux(); + expect(software.length).toEqual(0); + }); + + it('should return list for darwin', () => { + let software = service.getForDarwin(); + expect(software.length).toEqual(0); + }); + + describe('ExternalSoftwareDefinitionService.get', () => { + let windowsSpy: Spy; + let darwinSpy: Spy; + let linuxSpy: Spy; + + beforeEach(() => { + windowsSpy = spyOn(service, 'getForWindows').and.callThrough(); + darwinSpy = spyOn(service, 'getForDarwin').and.callThrough(); + linuxSpy = spyOn(service, 'getForLinux').and.callThrough(); + }); + + it('should return list when on windows', () => { + platformServiceMock.platform = 'windows'; + expect(service.get()).toBeDefined(); + expect(windowsSpy).toHaveBeenCalled(); + expect(darwinSpy).not.toHaveBeenCalled(); + expect(linuxSpy).not.toHaveBeenCalled(); + }); + + it('should return list when on linux', () => { + platformServiceMock.platform = 'linux'; + expect(service.get()).toBeDefined(); + expect(windowsSpy).not.toHaveBeenCalled(); + expect(darwinSpy).not.toHaveBeenCalled(); + expect(linuxSpy).toHaveBeenCalled(); + }); + + it('should return list when on darwin', () => { + platformServiceMock.platform = 'darwin'; + expect(service.get()).toBeDefined(); + expect(windowsSpy).not.toHaveBeenCalled(); + expect(darwinSpy).toHaveBeenCalled(); + expect(linuxSpy).not.toHaveBeenCalled(); + }); + + }) + });