diff --git a/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.spec.ts b/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.spec.ts index b7e237998..be3686d59 100644 --- a/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.spec.ts +++ b/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.spec.ts @@ -23,21 +23,6 @@ describe("CorCookieTabsDirective", () => { directive.cookieName = "quay.credentialsTab"; }); - describe("constructor", () => { - - it("subscribes to active tab changes", () => { - expect((panelMock.Object.activeTab.subscribe)).toHaveBeenCalled(); - }); - - it("calls cookie service to put new permanent cookie on active tab changes", () => { - const tabId: string = "description"; - (panelMock.Object.activeTab.subscribe).calls.argsFor(0)[0](tabId); - - expect((cookieServiceMock.Object.putPermanent).calls.argsFor(0)[0]).toEqual(directive.cookieName); - expect((cookieServiceMock.Object.putPermanent).calls.argsFor(0)[1]).toEqual(tabId); - }); - }); - describe("ngAfterContentInit", () => { const tabId: string = "description"; @@ -57,5 +42,20 @@ describe("CorCookieTabsDirective", () => { expect((panelMock.Object.activeTab.next).calls.argsFor(0)[0]).toEqual(tabId); }); + + it("subscribes to active tab changes", () => { + directive.ngAfterContentInit(); + + expect((panelMock.Object.activeTab.subscribe)).toHaveBeenCalled(); + }); + + it("calls cookie service to put new permanent cookie on active tab changes", () => { + directive.ngAfterContentInit(); + const tabId: string = "description"; + (panelMock.Object.activeTab.subscribe).calls.argsFor(0)[0](tabId); + + expect((cookieServiceMock.Object.putPermanent).calls.argsFor(0)[0]).toEqual(directive.cookieName); + expect((cookieServiceMock.Object.putPermanent).calls.argsFor(0)[1]).toEqual(tabId); + }); }); }); diff --git a/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.ts b/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.ts index 2cd429d48..d6f7e3302 100644 --- a/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.ts +++ b/static/js/directives/ui/cor-tabs/cor-cookie-tabs/cor-cookie-tabs.directive.ts @@ -14,14 +14,16 @@ export class CorCookieTabsDirective implements AfterContentInit { constructor(@Host() @Inject(CorTabPanelComponent) private panel: CorTabPanelComponent, @Inject('CookieService') private cookieService: any) { - this.panel.activeTab.subscribe((tab: string) => { - this.cookieService.putPermanent(this.cookieName, tab); - }); + } public ngAfterContentInit(): void { // Set initial tab const tabId: string = this.cookieService.get(this.cookieName); this.panel.activeTab.next(tabId); + + this.panel.activeTab.subscribe((tab: string) => { + this.cookieService.putPermanent(this.cookieName, tab); + }); } }