Merge pull request #2681 from alecmerdler/fix-cor-cookie-tabs
Fix CorCookieTabs Panel Undefined
This commit is contained in:
commit
c9cc2d9fdd
2 changed files with 20 additions and 18 deletions
|
@ -23,21 +23,6 @@ describe("CorCookieTabsDirective", () => {
|
||||||
directive.cookieName = "quay.credentialsTab";
|
directive.cookieName = "quay.credentialsTab";
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("constructor", () => {
|
|
||||||
|
|
||||||
it("subscribes to active tab changes", () => {
|
|
||||||
expect((<Spy>panelMock.Object.activeTab.subscribe)).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls cookie service to put new permanent cookie on active tab changes", () => {
|
|
||||||
const tabId: string = "description";
|
|
||||||
(<Spy>panelMock.Object.activeTab.subscribe).calls.argsFor(0)[0](tabId);
|
|
||||||
|
|
||||||
expect((<Spy>cookieServiceMock.Object.putPermanent).calls.argsFor(0)[0]).toEqual(directive.cookieName);
|
|
||||||
expect((<Spy>cookieServiceMock.Object.putPermanent).calls.argsFor(0)[1]).toEqual(tabId);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("ngAfterContentInit", () => {
|
describe("ngAfterContentInit", () => {
|
||||||
const tabId: string = "description";
|
const tabId: string = "description";
|
||||||
|
|
||||||
|
@ -57,5 +42,20 @@ describe("CorCookieTabsDirective", () => {
|
||||||
|
|
||||||
expect((<Spy>panelMock.Object.activeTab.next).calls.argsFor(0)[0]).toEqual(tabId);
|
expect((<Spy>panelMock.Object.activeTab.next).calls.argsFor(0)[0]).toEqual(tabId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("subscribes to active tab changes", () => {
|
||||||
|
directive.ngAfterContentInit();
|
||||||
|
|
||||||
|
expect((<Spy>panelMock.Object.activeTab.subscribe)).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls cookie service to put new permanent cookie on active tab changes", () => {
|
||||||
|
directive.ngAfterContentInit();
|
||||||
|
const tabId: string = "description";
|
||||||
|
(<Spy>panelMock.Object.activeTab.subscribe).calls.argsFor(0)[0](tabId);
|
||||||
|
|
||||||
|
expect((<Spy>cookieServiceMock.Object.putPermanent).calls.argsFor(0)[0]).toEqual(directive.cookieName);
|
||||||
|
expect((<Spy>cookieServiceMock.Object.putPermanent).calls.argsFor(0)[1]).toEqual(tabId);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,14 +14,16 @@ export class CorCookieTabsDirective implements AfterContentInit {
|
||||||
|
|
||||||
constructor(@Host() @Inject(CorTabPanelComponent) private panel: CorTabPanelComponent,
|
constructor(@Host() @Inject(CorTabPanelComponent) private panel: CorTabPanelComponent,
|
||||||
@Inject('CookieService') private cookieService: any) {
|
@Inject('CookieService') private cookieService: any) {
|
||||||
this.panel.activeTab.subscribe((tab: string) => {
|
|
||||||
this.cookieService.putPermanent(this.cookieName, tab);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ngAfterContentInit(): void {
|
public ngAfterContentInit(): void {
|
||||||
// Set initial tab
|
// Set initial tab
|
||||||
const tabId: string = this.cookieService.get(this.cookieName);
|
const tabId: string = this.cookieService.get(this.cookieName);
|
||||||
this.panel.activeTab.next(tabId);
|
this.panel.activeTab.next(tabId);
|
||||||
|
|
||||||
|
this.panel.activeTab.subscribe((tab: string) => {
|
||||||
|
this.cookieService.putPermanent(this.cookieName, tab);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue