Skip to content

Commit

Permalink
update and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkajtoch committed Jan 14, 2025
1 parent 4b10ba9 commit 603260a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ThemeService } from '@kbn/core-theme-browser-internal';

const mockTheme: CoreTheme = {
darkMode: false,
name: 'amsterdam',
name: 'borealis',
};

const createThemeMock = (): CoreTheme => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
});

const getClientGetMockImplementation =
({ darkMode, name }: { darkMode?: boolean; name?: string } = {}) =>
({ darkMode, name }: { darkMode?: boolean | string; name?: string } = {}) =>
(key: string) => {
switch (key) {
case 'theme:darkMode':
return Promise.resolve(darkMode ?? false);
case 'theme:name':
return Promise.resolve(name ?? 'amsterdam');
return Promise.resolve(name ?? 'borealis');
}
return Promise.resolve();
};
Expand All @@ -67,7 +67,7 @@ describe('bootstrapRenderer', () => {
packageInfo = createPackageInfo();
userSettingsService = userSettingsServiceMock.createSetupContract();

getThemeTagMock.mockReturnValue('v8light');
getThemeTagMock.mockReturnValue('borealislight');
getPluginsBundlePathsMock.mockReturnValue(new Map());
renderTemplateMock.mockReturnValue('__rendered__');
getJsDependencyPathsMock.mockReturnValue([]);
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand All @@ -141,7 +141,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -167,7 +167,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand All @@ -192,7 +192,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -217,7 +217,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand Down Expand Up @@ -290,13 +290,17 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});

it('calls getThemeTag with the correct parameters when darkMode is `system`', async () => {
uiSettingsClient.get.mockResolvedValue('system');
uiSettingsClient.get.mockImplementation(
getClientGetMockImplementation({
darkMode: 'system',
})
);

const request = httpServerMock.createKibanaRequest();

Expand All @@ -307,7 +311,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'system',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -321,15 +325,15 @@ describe('bootstrapRenderer', () => {
});
});

it('does not call uiSettingsClient.get', async () => {
it('does not call uiSettingsClient.get with `theme:darkMode`', async () => {
const request = httpServerMock.createKibanaRequest();

await renderer({
request,
uiSettingsClient,
});

expect(uiSettingsClient.get).not.toHaveBeenCalled();
expect(uiSettingsClient.get).not.toHaveBeenCalledWith('theme:darkMode');
});

it('calls getThemeTag with the default parameters', async () => {
Expand Down Expand Up @@ -367,7 +371,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand Down

0 comments on commit 603260a

Please sign in to comment.