import { PropertyQuestionsController } from './PropertyQuestions'; import { PropertyQuestionsService } from '../common/services/PropertyQuestionsService'; import { AnalyticsService } from '../common/services/AnalyticsService'; import { UserDataState } from '../common/state/UserDataState'; import { LayoutState } from '../common/state/LayoutState'; import { Mock, IMock, It, Times } from 'typemoq'; import { expect } from 'chai'; describe('Property questions controller', () => { let userDataState: UserDataState, layoutState: LayoutState, propertyQuestionsService: IMock, $state: IMock, $window: IMock, analyticsService: IMock; beforeEach(() => { userDataState = {} as UserDataState; layoutState = {} as LayoutState; propertyQuestionsService = Mock.ofType(); $state = Mock.ofType(); $window = Mock.ofType(); analyticsService = Mock.ofType(); }); function newController() { return new PropertyQuestionsController(propertyQuestionsService.object, $state.object, analyticsService.object, userDataState, layoutState, $window.object); } it('should redirect to the get quote page if the fuel is not set', () => { const ctrl = newController(); $state.verify(x => x.go(It.isValue("^.get-quote")), Times.once()); }); it('should redirect to the plan page if the questions have all been answered', () => { userDataState.fuel = 'Dual'; propertyQuestionsService.setup(x => x.getFirstUnansweredQuestion()).returns(() => 'Eligible'); const ctrl = newController(); $state.verify(x => x.go(It.isValue("^.plan-payg")), Times.once()); }); it('should set the question to the first unanswered question', () => { userDataState.fuel = 'Dual'; propertyQuestionsService.setup(x => x.getFirstUnansweredQuestion()).returns(() => ({ id: 'InFlat', yes: 'Eligible', no: 'PropertyNotEligible' })); const ctrl = newController(); expect(ctrl.question.id).to.equal('InFlat'); }); it('should redirect to the plan page once the last question has been answered', () => { userDataState.fuel = 'Dual'; propertyQuestionsService.setup(x => x.getFirstUnansweredQuestion()).returns(() => ({ id: 'InFlat', yes: 'Eligible', no: 'PropertyNotEligible' })); propertyQuestionsService.setup(x => x.setAnswer(It.isAny(), It.isAny())).returns(() => 'Eligible'); const ctrl = newController(); ctrl.setAnswer('No'); $state.verify(x => x.go(It.isValue("^.plan-payg")), Times.once()); }); });