Skip to content

Commit 177acff

Browse files
committed
Fix unit tests
1 parent ab0ffb1 commit 177acff

54 files changed

Lines changed: 290 additions & 178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@thunderid/eslint-plugin": "workspace:^",
5959
"@thunderid/prettier-config": "workspace:^",
6060
"@thunderid/test-utils": "workspace:^",
61+
"@vitest/browser-playwright": "catalog:",
6162
"@types/node": "catalog:",
6263
"@types/react": "catalog:",
6364
"eslint": "catalog:",

frontend/packages/components/src/Helmet/Helmet.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default function Helmet({children}: HelmetProps): null {
7676
}
7777

7878
const el = document.createElement(type as string);
79+
el.setAttribute('data-helmet', 'true');
7980
applyAttributes(el, props);
8081

8182
if (type === 'style' || type === 'script' || type === 'noscript') {

frontend/packages/components/src/Helmet/__tests__/Helmet.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('Helmet', () => {
6161
</Helmet>,
6262
);
6363
await waitFor(() => {
64-
const link = document.querySelector('link[rel="icon"]');
64+
const link = document.querySelector('link[data-helmet][rel="icon"]');
6565
expect(link).toBeTruthy();
6666
expect(link?.getAttribute('href')).toBe('/favicon.ico');
6767
});
@@ -109,7 +109,7 @@ describe('Helmet', () => {
109109
</Helmet>,
110110
);
111111
await waitFor(() => {
112-
const style = document.querySelector('style');
112+
const style = document.querySelector('style[data-helmet]');
113113
expect(style?.textContent).toBe('body { margin: 0; }');
114114
});
115115
});

frontend/packages/components/src/lab/components/EmojiPicker/__tests__/EmojiPicker.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ import userEvent from '@testing-library/user-event';
2121
import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
2222
import EmojiPicker from '../EmojiPicker';
2323

24+
vi.mock('react-i18next', () => ({
25+
useTranslation: () => ({
26+
t: (key: string, fallback?: string | Record<string, unknown>, options?: Record<string, unknown>) => {
27+
const str = typeof fallback === 'string' ? fallback : key;
28+
const vars = typeof fallback === 'object' ? fallback : options;
29+
if (vars && typeof vars === 'object') {
30+
return str.replace(/\{\{(\w+)\}\}/g, (_, k: string) => {
31+
const val = vars[k];
32+
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' ? String(val) : '';
33+
});
34+
}
35+
return str;
36+
},
37+
}),
38+
}));
39+
2440
// The module-level _supportedCategories cache needs to be reset between tests
2541
// so that the canvas mock only runs once per test. Since jsdom's canvas 2D
2642
// context is null, getSupportedCategories() falls through to returning all
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import {cleanup} from '@testing-library/react';
20+
import {afterEach} from 'vitest';
21+
22+
afterEach(() => {
23+
cleanup();
24+
});

frontend/packages/components/vitest.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import {resolve} from 'path';
20+
import {playwright} from '@vitest/browser-playwright';
2021
import {defineConfig} from 'vitest/config';
2122

2223
export default defineConfig({
@@ -40,7 +41,8 @@ export default defineConfig({
4041
enabled: true,
4142
headless: true,
4243
instances: [{browser: 'chromium'}],
43-
provider: 'playwright',
44+
provider: playwright(),
4445
},
46+
setupFiles: ['./src/test-setup.ts'],
4547
},
4648
});

frontend/packages/configure-agent-types/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@thunderid/prettier-config": "workspace:^",
5858
"@thunderid/test-utils": "workspace:^",
5959
"@thunderid/types": "workspace:^",
60+
"@vitest/browser-playwright": "catalog:",
6061
"@types/node": "catalog:",
6162
"@types/react": "catalog:",
6263
"eslint": "catalog:",

frontend/packages/configure-agent-types/src/pages/__tests__/ViewAgentTypePage.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ vi.mock('react-router', async () => {
5353
};
5454
});
5555

56-
vi.mock('../../api/useGetAgentType', () => ({
56+
vi.mock('@/api/useGetAgentType', () => ({
5757
default: (id?: string): unknown => mockUseGetAgentType(id) as unknown,
5858
}));
5959

60-
vi.mock('../../api/useUpdateAgentType', () => ({
60+
vi.mock('@/api/useUpdateAgentType', () => ({
6161
default: (): unknown => mockUseUpdateAgentType() as unknown,
6262
}));
6363

64-
vi.mock('../../components/edit-agent-type/schema-settings/EditSchemaSettings', () => ({
64+
vi.mock('@/components/edit-agent-type/schema-settings/EditSchemaSettings', () => ({
6565
default: ({onPropertiesChange}: {onPropertiesChange: (props: unknown[]) => void}) => (
6666
<div data-testid="edit-schema-settings">
6767
<button

frontend/packages/configure-agent-types/vitest.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import {resolve} from 'path';
20+
import {playwright} from '@vitest/browser-playwright';
2021
import {defineConfig} from 'vitest/config';
2122

2223
export default defineConfig({
@@ -40,7 +41,8 @@ export default defineConfig({
4041
enabled: true,
4142
headless: true,
4243
instances: [{browser: 'chromium'}],
43-
provider: 'playwright',
44+
provider: playwright(),
4445
},
46+
setupFiles: ['@thunderid/test-utils/setup'],
4547
},
4648
});

frontend/packages/configure-organization-units/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@thunderid/prettier-config": "workspace:^",
5858
"@thunderid/test-utils": "workspace:^",
5959
"@thunderid/types": "workspace:^",
60+
"@vitest/browser-playwright": "catalog:",
6061
"@types/node": "catalog:",
6162
"@types/react": "catalog:",
6263
"eslint": "catalog:",

0 commit comments

Comments
 (0)