diff --git a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.test.tsx b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.test.tsx index dc1ad36f01c5e..7d7122e7387ce 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.test.tsx +++ b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.test.tsx @@ -588,6 +588,41 @@ describe('start', () => { expect(updatedIsCollapsed).toBe(!isCollapsed); }); }); + + describe('getIsFeedbackBtnVisible$', () => { + it('should return false by default', async () => { + const { chrome, service } = await start(); + const isCollapsed = await firstValueFrom(chrome.sideNav.getIsFeedbackBtnVisible$()); + service.stop(); + expect(isCollapsed).toBe(false); + }); + + it('should return "false" when the sidenav is collapsed', async () => { + const { chrome, service } = await start(); + + const isFeedbackBtnVisible$ = chrome.sideNav.getIsFeedbackBtnVisible$(); + chrome.sideNav.setIsFeedbackBtnVisible(true); // Mark it as visible + chrome.sideNav.setIsCollapsed(true); // But the sidenav is collapsed + + const isFeedbackBtnVisible = await firstValueFrom(isFeedbackBtnVisible$); + service.stop(); + expect(isFeedbackBtnVisible).toBe(false); + }); + }); + + describe('setIsFeedbackBtnVisible', () => { + it('should update the isFeedbackBtnVisible$ observable', async () => { + const { chrome, service } = await start(); + const isFeedbackBtnVisible$ = chrome.sideNav.getIsFeedbackBtnVisible$(); + const isFeedbackBtnVisible = await firstValueFrom(isFeedbackBtnVisible$); + + chrome.sideNav.setIsFeedbackBtnVisible(!isFeedbackBtnVisible); + + const updatedIsFeedbackBtnVisible = await firstValueFrom(isFeedbackBtnVisible$); + service.stop(); + expect(updatedIsFeedbackBtnVisible).toBe(!isFeedbackBtnVisible); + }); + }); }); }); diff --git a/packages/core/chrome/core-chrome-browser-mocks/src/chrome_service.mock.ts b/packages/core/chrome/core-chrome-browser-mocks/src/chrome_service.mock.ts index ff39293738ff0..144002ee94547 100644 --- a/packages/core/chrome/core-chrome-browser-mocks/src/chrome_service.mock.ts +++ b/packages/core/chrome/core-chrome-browser-mocks/src/chrome_service.mock.ts @@ -56,6 +56,8 @@ const createStartContractMock = () => { setIsCollapsed: jest.fn(), getPanelSelectedNode$: jest.fn(), setPanelSelectedNode: jest.fn(), + getIsFeedbackBtnVisible$: jest.fn(), + setIsFeedbackBtnVisible: jest.fn(), }, getBreadcrumbsAppendExtension$: jest.fn(), setBreadcrumbsAppendExtension: jest.fn(), diff --git a/src/plugins/navigation/public/plugin.test.ts b/src/plugins/navigation/public/plugin.test.ts index a88b51abba665..d05cf756f7178 100644 --- a/src/plugins/navigation/public/plugin.test.ts +++ b/src/plugins/navigation/public/plugin.test.ts @@ -179,6 +179,60 @@ describe('Navigation Plugin', () => { }); }); + describe('set feedback button visibility', () => { + it('should set the feedback button visibility to "true" when space solution is a known solution', async () => { + const { plugin, coreStart, unifiedSearch, cloud, spaces } = setup(); + + for (const solution of ['es', 'oblt', 'security']) { + spaces.getActiveSpace$ = jest + .fn() + .mockReturnValue(of({ solution } as Pick)); + plugin.start(coreStart, { unifiedSearch, cloud, spaces }); + await new Promise((resolve) => setTimeout(resolve)); + expect(coreStart.chrome.sideNav.setIsFeedbackBtnVisible).toHaveBeenCalledWith(true); + coreStart.chrome.sideNav.setIsFeedbackBtnVisible.mockReset(); + } + }); + + it('should set the feedback button visibility to "false" for deployment in trial', async () => { + const { plugin, coreStart, unifiedSearch, cloud: cloudStart, spaces } = setup(); + const coreSetup = coreMock.createSetup(); + const cloudSetup = cloudMock.createSetup(); + cloudSetup.trialEndDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30); // 30 days from now + plugin.setup(coreSetup, { cloud: cloudSetup }); + + for (const solution of ['es', 'oblt', 'security']) { + spaces.getActiveSpace$ = jest + .fn() + .mockReturnValue(of({ solution } as Pick)); + plugin.start(coreStart, { unifiedSearch, cloud: cloudStart, spaces }); + await new Promise((resolve) => setTimeout(resolve)); + expect(coreStart.chrome.sideNav.setIsFeedbackBtnVisible).toHaveBeenCalledWith(false); + coreStart.chrome.sideNav.setIsFeedbackBtnVisible.mockReset(); + } + }); + + it('should not set the feedback button visibility for classic or unknown solution', async () => { + const { plugin, coreStart, unifiedSearch, cloud, spaces } = setup(); + + for (const solution of ['classic', 'unknown', undefined]) { + spaces.getActiveSpace$ = jest.fn().mockReturnValue(of({ solution })); + plugin.start(coreStart, { unifiedSearch, cloud, spaces }); + await new Promise((resolve) => setTimeout(resolve)); + expect(coreStart.chrome.sideNav.setIsFeedbackBtnVisible).not.toHaveBeenCalled(); + coreStart.chrome.sideNav.setIsFeedbackBtnVisible.mockReset(); + } + }); + + it('should not set the feedback button visibility when on serverless', async () => { + const { plugin, coreStart, unifiedSearch, cloud } = setup({ buildFlavor: 'serverless' }); + + plugin.start(coreStart, { unifiedSearch, cloud }); + await new Promise((resolve) => setTimeout(resolve)); + expect(coreStart.chrome.sideNav.setIsFeedbackBtnVisible).not.toHaveBeenCalled(); + }); + }); + describe('isSolutionNavEnabled$', () => { it('should be off if spaces plugin not available', async () => { const { plugin, coreStart, unifiedSearch } = setup();