123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI
- * (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- import HideNavBarItemLabelsAction from "cawebpack/actions/HideNavBarItemLabelsAction";
- const addDOMClass = jest.fn(() => {});
- const createAppViewDOM = (navBarLength: number): object => {
- return {
- getElementsByClassName: jest.fn(() => {
- return {
- length: navBarLength,
- 0: {
- classList: {
- add: addDOMClass
- }
- }
- };
- })
- };
- };
- const createMockContext = (appViewDOM: object, homeFlag: boolean): any => {
- return {
- glassContext: {
- appController: {
- currentAppView: {
- $el: [appViewDOM],
- hasHomeFlag: (): boolean => {
- return homeFlag;
- }
- }
- }
- }
- };
- };
- describe("Hide Navbar Labels Action", () => {
- let actionHandler: HideNavBarItemLabelsAction;
- beforeEach(() => {
- actionHandler = new HideNavBarItemLabelsAction();
- const spyFunc = jest.fn(() => createAppViewDOM(1));
- Object.defineProperty(document, "querySelector", {
- value: spyFunc,
- configurable: true
- });
- });
- afterEach(() => {
- jest.clearAllMocks();
- });
- it("canExecute returns true if homeFlag false and navBar exists", () => {
- const appViewDOM = createAppViewDOM(1);
- const mockContext = createMockContext(appViewDOM, false);
- const result = actionHandler.canExecute(mockContext);
- expect(result).toBe(true);
- });
- it("canExecute returns false if homeFlag true and navBar exists", () => {
- const appViewDOM = createAppViewDOM(1);
- const mockContext = createMockContext(appViewDOM, true);
- mockContext.glassContext.appController.currentAppView.hasHomeFlag = (): boolean => {
- return true;
- };
- const result = actionHandler.canExecute(mockContext);
- expect(result).toBe(false);
- });
- it("canExecute returns false if homeFlag false and no navBar", () => {
- const spyFunc = jest.fn(() => createAppViewDOM(0));
- Object.defineProperty(document, "querySelector", {
- value: spyFunc,
- configurable: true
- });
- const appViewDOM = createAppViewDOM(0);
- const mockContext = createMockContext(appViewDOM, false);
- const result = actionHandler.canExecute(mockContext);
- expect(result).toBe(false);
- });
- it("canExecute returns false if homeFlag true and no navBar", () => {
- const spyFunc = jest.fn(() => createAppViewDOM(0));
- Object.defineProperty(document, "querySelector", {
- value: spyFunc,
- configurable: true
- });
- const appViewDOM = createAppViewDOM(0);
- const mockContext = createMockContext(appViewDOM, true);
- const result = actionHandler.canExecute(mockContext);
- expect(result).toBe(false);
- });
- it("it can add class narrow to navbar in doAction", () => {
- actionHandler.doAction();
- expect(addDOMClass).toHaveBeenCalledWith("narrow");
- });
- });
|