import {ComponentTest} from '../../infrastructure/ComponentHelper'; import {Directive as DetailDir, Controller as DetailCtrl, FlightDetailParams} from './flight-detail'; import DetailMod from '../flight-detail.mod'; import {Mod as CoreMod} from '../../core/core.mod'; import {IFlightInformationModel} from '../services/flightInformationService'; import {IFlightDetail} from '../../core/service/flightService'; class FlightDetailTest extends ComponentTest { constructor() { super(DetailDir.$componentName, 'app/flight-detail/detail/flight-detail.tpl.html') } } class TestInstance { public test: FlightDetailTest; public api: any; public $httpBackend: ng.IHttpBackendService; public $state: ng.ui.IStateService; public $stateParams: ng.ui.IStateParamsService; public $rootScope: ng.IRootScopeService; constructor() { angular.mock.inject(($httpBackend, $state, $stateParams, $rootScope, api) => { this.$httpBackend = $httpBackend; this.$state = $state; this.$stateParams = $stateParams; this.$rootScope = $rootScope; this.api = api; }); } public getSelectedFlight(): IFlightDetail { return { Id: '1', Type: 'A', Operator: 'SK', Number: '0214', AircraftType: '333', Registration: 'PK-GPE', Location: 'MAN', Scheduled: '09:00', Estimated: '09:00', Actual: '09:00', Terminal: 'T1', Stand: 'A1', FlightConcat: 'SK0214' }; } public setupForListGet(): IFlightInformationModel { let model: IFlightInformationModel = { Flight: undefined, Groups: [{ "Name": "Detail", "Display": "Details", "Icon": "ion-navicon" }], Fields: undefined, Editors: undefined, IsOutsideOfWindow: false }; this.$httpBackend.expectGET(`${this.api.detail}?flightId=${this.getSelectedFlight().Id}&requestId=ste1234567`).respond(201, model); return model; } } describe('Flight Details:', () => { let instance: TestInstance; beforeEach(() => { new DetailMod(angular); new CoreMod(angular); angular.mock.module('ui.router'); angular.mock.module('ionic'); angular.mock.module('chroma.configuration') angular.mock.module(DetailMod.$componentName); angular.mock.module(CoreMod.$componentName); instance = new TestInstance(); instance.test = new FlightDetailTest(); }); describe('Framework: ChromaDateFilter', () => { let $filter: any; beforeEach(() => { angular.mock.inject((_$filter_) => { $filter = _$filter_; }); }); it('ChromaDateFilter: If input is empty, return empty', () => { let result = $filter('chromaDateFilter')('', false); expect(result).toBe(''); }); it('ChromaDateFilter: If input is default DateTime, return empty', () => { let result = $filter('chromaDateFilter')('/Date(-62135596800000)/', false); expect(result).toBe(''); }); it('ChromaDateFilter: return HH:mm if not a Date request', () => { let result = $filter('chromaDateFilter')('/Date(1447243800000)/', false); expect(result).toBe('12:10'); }); it('ChromaDateFilter: return [DD] HH:mm if a Date request', () => { let result = $filter('chromaDateFilter')("/Date(1447243800000)/", true); expect(result).toBe('[11] 12:10'); }); }); describe('Scenario: Viewing flights by window', () => { //Given that I have selected a window // And select a flight that I want to View //Then I should see the flights information //Grouped by category it('Groups should be displayed', function () { let model: IFlightInformationModel, ctrl: DetailCtrl, params: FlightDetailParams, baseStateName: string, expectedStateName: string; params = instance.$stateParams; params.flight = instance.getSelectedFlight(); params.requestId = 'ste1234567'; baseStateName = 'chroma.flight-detail.'; spyOn(instance.$state, "go").and.callThrough(); model = instance.setupForListGet(); ctrl = instance.test.compile() expectedStateName = baseStateName + model.Groups[0].Name; expect(instance.$state.go).toHaveBeenCalledWith(expectedStateName); }) it('View title updated on navigation', function () { let model: IFlightInformationModel, ctrl: DetailCtrl, params: FlightDetailParams, newGroup: string = "NewGroup123"; params = instance.$stateParams; params.flight = instance.getSelectedFlight(); params.requestId = 'ste1234567'; model = instance.setupForListGet(); ctrl = instance.test.compile() instance.$rootScope.$emit('flightGroupChanged', { Display: newGroup }) expect(ctrl.viewTitle).toBe(newGroup); }) }) })