Skip to content

Commit

Permalink
Add tests for registerCollapsibleNavHeader warning console output
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <[email protected]>
  • Loading branch information
ruanyl committed Dec 13, 2023
1 parent 4594288 commit e973515
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/public/chrome/chrome_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ afterAll(() => {
});

describe('setup', () => {
afterEach(() => {
jest.restoreAllMocks();
});

it('register custom Nav Header render', async () => {
const customHeaderMock = React.createElement('TestCustomNavHeader');
const renderMock = jest.fn().mockReturnValue(customHeaderMock);
Expand All @@ -122,6 +126,24 @@ describe('setup', () => {
expect(wrapper.prop('collapsibleNavHeaderRender')).toBeDefined();
expect(wrapper.prop('collapsibleNavHeaderRender')()).toEqual(customHeaderMock);
});

it('should output warning message if calling `registerCollapsibleNavHeader` more than once', () => {
const warnMock = jest.fn();
jest.spyOn(console, 'warn').mockImplementation(warnMock);
const customHeaderMock = React.createElement('TestCustomNavHeader');
const renderMock = jest.fn().mockReturnValue(customHeaderMock);
const chrome = new ChromeService({ browserSupportsCsp: true });

const chromeSetup = chrome.setup();
// call 1st time
chromeSetup.registerCollapsibleNavHeader(renderMock);
// call 2nd time
chromeSetup.registerCollapsibleNavHeader(renderMock);
expect(warnMock).toHaveBeenCalledTimes(1);
expect(warnMock).toHaveBeenCalledWith(
'[ChromeService] An existing custom collapsible navigation bar header render has been overridden.'
);
});
});

describe('start', () => {
Expand Down

0 comments on commit e973515

Please sign in to comment.