import { PlanEVController } from './PlanEV'; import { Mock, IMock, It, Times } from 'typemoq'; import { UserDataState } from '../../common/state/UserDataState'; import { QuoteService } from '../../common/services/QuoteService'; import { Quote, QuoteWithMeters } from '../../common/entities/Quote'; import { AnalyticsService } from '../../common/services/AnalyticsService'; import { LayoutState } from "../../common/state/LayoutState"; import { ModalService } from '../../common/services/ModalService'; import { quote } from '../../common/entities/Quote.fixture'; import { expect } from 'chai'; describe('PlanEV controller', () => { let userDataState: UserDataState, layoutState: LayoutState, $window: IMock, quoteService: IMock, $state: IMock, modalService: IMock, analyticsService: IMock; beforeEach(() => { userDataState = {} as UserDataState; $state = Mock.ofType(); $window = Mock.ofType(); layoutState = new LayoutState(); quoteService = Mock.ofType(); analyticsService = Mock.ofType(); modalService = Mock.ofType(); }); function newController() { return new PlanEVController($state.object, $window.object, layoutState, userDataState, quoteService.object, analyticsService.object, modalService.object); } it('should navigate to get quote ev page if quote doesn\'t exist', () => { const ctrl = newController(); quoteService.setup(x => x.getQuote()).returns(() => Promise.reject("error")); return ctrl.$onInit().then(() => $state.verify(x => x.go(It.isValue("^.get-quote")), Times.once()) ); }); it('navigate to switch page if switch to plan is called', () => { const ctrl = newController(); ctrl.bundle = quote.bundles.find(bundle => bundle.name === 'EV'); ctrl.switchToPlan(); $state.verify(x => x.go(It.isValue("^.switch")), Times.once()) }); it('should get boltons from quote', () => { const ctrl = newController(); const bundle = quote.bundles.find(bundle => bundle.name === 'EV'); const result = ctrl.getBoltonsFromQuote(quote, bundle); expect(result.length).to.equal(2); }); });