aodb/app/flight-detail/editors/freetext/freetext.spec.ts

151 lines
4.4 KiB
TypeScript
Raw Normal View History

2016-12-22 00:00:06 +00:00
import {ComponentTest} from '../../../infrastructure/ComponentHelper';
import DetailMod from '../../flight-detail.mod';
import {Mod as CoreMod} from '../../../core/core.mod';
import {Directive, Controller} from './freetext'
import * as InformationService from "../../services/flightInformationService";
class FreeTextEditorTest extends ComponentTest {
public compileString: string = `<chroma:Freetext-Editor definition="definition" field="field"instance="instance"model="model"> </chroma:Freetext-Editor>`;
constructor() {
super(Directive.$componentName, 'app/flight-detail/editors/freetext/freetext.tpl.html');
}
public getTestingScope(): any {
return {
field: {
Value: 'testValue',
Name: 'Crew',
Editor: 'freetext',
Group: 'Details',
Mapping: 'SCCREW'
},
definition: {
Url: 'testURL'
},
model: {
Flight: {
Id: '0001'
}
},
instance: {
close() {
}
}
};
}
public setupForRequest(scope: any, responseObj: any, beforeUpdate: any = undefined): Controller {
let ctrl = this.compile<Controller>(scope, this.compileString);
this.$httpBackend.expectPOST(ctrl.updateUrl).respond(201, responseObj);
if (beforeUpdate) {
beforeUpdate(ctrl);
}
ctrl.update();
this.$httpBackend.flush();
return ctrl;
}
}
describe('Freetext Editor:', () => {
let instance: FreeTextEditorTest,
detailMod: DetailMod,
coreMod: CoreMod;
beforeEach(() => {
detailMod = new DetailMod(angular);
coreMod = 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 FreeTextEditorTest();
});
describe('Framework:', () => {
it('Compiles with required properties', () => {
let ctrl: Controller,
scope: any;
scope = instance.getTestingScope();
ctrl = instance.compile<Controller>(scope, instance.compileString);
expect(ctrl).toBeDefined();
expect(ctrl.field).toBeDefined();
expect(ctrl.definition).toBeDefined();
expect(ctrl.model).toBeDefined();
expect(ctrl.instance).toBeDefined();
});
it('Popup closes if previous action complete', () => {
let ctrl: Controller, scope: any;
scope = instance.getTestingScope();
ctrl = instance.setupForRequest(scope, { Success: false });
spyOn(ctrl.instance, 'close').and.callThrough();
ctrl.update();
expect(ctrl.instance.close).toHaveBeenCalled();
});
});
describe('Behaviour', () => {
it('Flight updated even broadcast on update regardless on status', () => {
let ctrl: Controller, scope: any,
flightUpdateEvent: string = 'chroma:flight-updated';
scope = instance.getTestingScope();
spyOn(instance.$rootScope, '$emit').and.callThrough();
instance.setupForRequest(scope, { Success: true });
expect(instance.$rootScope.$emit).toHaveBeenCalledWith(flightUpdateEvent);
});
it('Status becomes S if successful Update', () => {
let ctrl: Controller, scope: any;
scope = instance.getTestingScope();
ctrl = instance.setupForRequest(scope, { Success: true });
expect(ctrl.status).toBe('S');
});
it('Status becomes S if successful Delete', () => {
let ctrl: Controller, scope: any;
scope = instance.getTestingScope();
ctrl = instance.setupForRequest(scope, {}, (controller: Controller) => {
controller.value = '';
});
expect(ctrl.status).toBe('S');
});
it('Status becomes E if on failed update or delete', () => {
let ctrl: Controller, scope: any;
scope = instance.getTestingScope();
ctrl = instance.setupForRequest(scope, { Success: false });
expect(ctrl.status).toBe('E');
});
});
});