mirror of
https://gitlab.silvrtree.co.uk/martind2000/aodb.git
synced 2025-02-10 11:49:16 +00:00
139 lines
4.6 KiB
TypeScript
139 lines
4.6 KiB
TypeScript
import {Directive, Controller, TransactionListParams} from './transaction-list'
|
|
import {ComponentTest} from '../../infrastructure/ComponentHelper';
|
|
import {Mod as CoreModule} from '../../core/core.mod';
|
|
import FlightDetailModule from '../../flight-detail/flight-detail.mod';
|
|
import {ITransactionDetail} from '../services/transactionService';
|
|
import {IFlightDetail} from '../../core/service/flightService';
|
|
|
|
|
|
class TransactionListTest extends ComponentTest {
|
|
public api: any;
|
|
public $stateParams: TransactionListParams;
|
|
public $state: ng.ui.IStateService;
|
|
public transactions: Array<ITransactionDetail>;
|
|
public ctrl: Controller;
|
|
public testModel: IFlightDetail;
|
|
public compileString: string = '<chroma:Transaction-List model=\'model\'></chroma:Transaction-List>';
|
|
|
|
constructor(){
|
|
super(Directive.$componentName, 'app/flight-detail/transactions/transaction-list.tpl.html');
|
|
}
|
|
|
|
public setup(): void {
|
|
this.testModel = {
|
|
Id: "123",
|
|
Location: undefined,
|
|
Operator: undefined,
|
|
Number: undefined,
|
|
AircraftType: undefined,
|
|
Registration: undefined,
|
|
Stand: undefined,
|
|
Terminal: undefined,
|
|
Actual: undefined,
|
|
Scheduled: undefined,
|
|
Estimated: undefined,
|
|
Type: 'D'
|
|
}
|
|
}
|
|
|
|
public buildTransactionList(count: number): void {
|
|
this.transactions = [];
|
|
|
|
for(let i=0; i < count; i++){
|
|
let iStr = i.toString();
|
|
this.transactions.push({
|
|
Id: iStr,
|
|
Code: iStr + iStr + iStr,
|
|
Name: 'Transaction' + i,
|
|
Duration: '250',
|
|
PONumber: 'ZZZZ' + i.toString(),
|
|
StartTime: '09:00',
|
|
EndTime: '12:4' + iStr,
|
|
Quantity: i * i,
|
|
Confirmed: true,
|
|
Cancelled:false
|
|
});
|
|
}
|
|
}
|
|
|
|
public setupForSuccessfulGet(): void {
|
|
this.$stateParams.flightId = '123';
|
|
console.log(this.transactions)
|
|
this.buildTransactionList(4);
|
|
console.log(this.transactions);
|
|
let expectedUrl = this.api.transactions + "?flightId=" + this.$stateParams.flightId;
|
|
|
|
this.$httpBackend.expectGET(expectedUrl)
|
|
.respond(201, {
|
|
Transactions: this.transactions
|
|
});
|
|
|
|
this.ctrl = this.compile<Controller>({model: this.testModel}, this.compileString);
|
|
console.log(this.ctrl);
|
|
}
|
|
}
|
|
|
|
describe('Transaction List View Tests', () => {
|
|
let instance: TransactionListTest,
|
|
core: CoreModule,
|
|
flightDetail: FlightDetailModule;
|
|
|
|
beforeEach(() => {
|
|
if(!instance) {
|
|
core = new CoreModule(angular);
|
|
flightDetail = new FlightDetailModule(angular);
|
|
|
|
angular.mock.module('ui.router');
|
|
angular.mock.module('ionic');
|
|
angular.mock.module('chroma.configuration');
|
|
angular.mock.module(CoreModule.$componentName);
|
|
angular.mock.module(FlightDetailModule.$componentName);
|
|
|
|
angular.mock.inject((api, $state, $stateParams) => {
|
|
instance = new TransactionListTest();
|
|
instance.setup();
|
|
instance.api = api;
|
|
instance.$state = $state;
|
|
instance.$stateParams = $stateParams;
|
|
});
|
|
}
|
|
});
|
|
|
|
it('Directive is compiled', () => {
|
|
instance.flushOnInit = false;
|
|
|
|
instance.setup();
|
|
|
|
instance.ctrl = instance.compile<Controller>({model: this.testModel}, instance.compileString);
|
|
console.log(instance.ctrl);
|
|
expect(instance.ctrl).toBeDefined();
|
|
});
|
|
|
|
it('Flight has 4 transactions and 4 transactions are displayed', () => {
|
|
console.log(instance);
|
|
instance.setupForSuccessfulGet();
|
|
|
|
console.log(instance.ctrl);
|
|
|
|
expect(instance.ctrl).toBeDefined();
|
|
expect(instance.ctrl.transactions).toBeDefined();
|
|
expect(instance.ctrl.transactions.length).toEqual(4);
|
|
expect(instance.ctrl.transactions).toEqual(instance.transactions);
|
|
});
|
|
|
|
it('Transaction Detail shown when transaction pressed', () => {
|
|
instance.setupForSuccessfulGet();
|
|
|
|
let firstTran = instance.ctrl.transactions[0];
|
|
|
|
spyOn(instance.$state, "go");
|
|
|
|
instance.ctrl.showTransactionDetail(firstTran);
|
|
|
|
expect(instance.$state.go).toHaveBeenCalledWith('chroma.flight-detail.transaction-detail', {
|
|
transaction: firstTran
|
|
});
|
|
});
|
|
});
|
|
|