import { QuayRequireDirective } from './quay-require.directive'; import { Mock } from 'ts-mocks'; import Spy = jasmine.Spy; describe("QuayRequireDirective", () => { var directive: QuayRequireDirective; var featuresMock: Mock; var $elementMock: Mock; var $scopeMock: Mock; var $transcludeMock: Mock; var ngIfDirectiveMock: Mock; beforeEach(() => { featuresMock = new Mock(); $elementMock = new Mock(); $scopeMock = new Mock(); $transcludeMock = new Mock(); ngIfDirectiveMock = new Mock(); directive = new QuayRequireDirective(featuresMock.Object, $elementMock.Object, $scopeMock.Object, $transcludeMock.Object, [ngIfDirectiveMock.Object]); directive.requiredFeatures = ['BILLING', 'SOME_OTHER_FEATURE']; }); describe("ngAfterContentInit", () => { var linkMock: Mock; beforeEach(() => { linkMock = new Mock(); linkMock.setup(mock => (mock).apply); ngIfDirectiveMock.setup(mock => mock.link).is(linkMock.Object); }); it("calls ngIfDirective link method with own element's arguments to achieve ngIf functionality", () => { featuresMock.setup(mock => mock.matchesFeatures).is((features) => false); directive.ngAfterContentInit(); expect(((linkMock.Object).apply).calls.argsFor(0)[0]).toEqual(ngIfDirectiveMock.Object); expect(((linkMock.Object).apply).calls.argsFor(0)[1][0]).toEqual($elementMock.Object); expect(((linkMock.Object).apply).calls.argsFor(0)[1][1]).toEqual($scopeMock.Object); expect(Object.keys(((linkMock.Object).apply).calls.argsFor(0)[1][2])).toEqual(['ngIf']); expect(((linkMock.Object).apply).calls.argsFor(0)[1][3]).toEqual(null); expect(((linkMock.Object).apply).calls.argsFor(0)[1][4]).toEqual($transcludeMock.Object); }); it("calls feature service to check if given features are present in application", () => { featuresMock.setup(mock => mock.matchesFeatures).is((features) => false); directive.ngAfterContentInit(); expect(((linkMock.Object).apply).calls.argsFor(0)[1][2]['ngIf']()).toBe(false); expect(featuresMock.Object.matchesFeatures).toHaveBeenCalled(); expect((featuresMock.Object.matchesFeatures).calls.argsFor(0)[0]).toEqual(directive.requiredFeatures); }); }); });