Skip to content

Commit e3a6119

Browse files
authored
[ci] Workflow for Grid UI component tests (#15778)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent 92db47f commit e3a6119

File tree

9 files changed

+1841
-89
lines changed

9 files changed

+1841
-89
lines changed

.github/workflows/ci-grid-ui.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI - Grid UI
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'javascript/grid-ui/**'
7+
push:
8+
branches:
9+
- trunk
10+
paths:
11+
- 'javascript/grid-ui/**'
12+
workflow_dispatch:
13+
workflow_call:
14+
15+
jobs:
16+
grid-ui-tests:
17+
runs-on: ubuntu-latest
18+
name: Grid UI Component Tests
19+
steps:
20+
- name: Checkout source tree
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 50
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '18'
29+
cache: 'npm'
30+
cache-dependency-path: 'javascript/grid-ui/package.json'
31+
32+
- name: Install dependencies
33+
working-directory: javascript/grid-ui
34+
run: npm install
35+
36+
- name: Run component tests
37+
working-directory: javascript/grid-ui
38+
run: npm test

javascript/grid-ui/jest.config.cjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. 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+
module.exports = {
19+
preset: 'ts-jest',
20+
testEnvironment: 'jsdom',
21+
testMatch: ['<rootDir>/src/tests/**/*.test.tsx'],
22+
transform: {
23+
'^.+\\.(ts|tsx)$': 'ts-jest',
24+
'^.+\\.(js|jsx)$': 'ts-jest'
25+
},
26+
moduleNameMapper: {
27+
'\\.(css|less|scss|sass)$': '<rootDir>/src/tests/__mocks__/styleMock.js',
28+
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/src/tests/__mocks__/styleMock.js'
29+
},
30+
transformIgnorePatterns: [
31+
'node_modules/(?!(pretty-ms|parse-ms)/)'
32+
],
33+
setupFilesAfterEnv: [
34+
'<rootDir>/src/setupTests.tsx',
35+
'<rootDir>/src/tests/setup-jest.js'
36+
],
37+
// Suppress act() warnings from Material-UI components
38+
testEnvironmentOptions: {
39+
suppressConsole: true
40+
}
41+
};

javascript/grid-ui/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"source-map-explorer": "2.5.3"
2828
},
2929
"scripts": {
30-
"build": "bazel build //javascript/grid-ui:bundle"
30+
"build": "bazel build //javascript/grid-ui:bundle",
31+
"test": "jest --config jest.config.cjs"
3132
},
3233
"homepage": "./ui",
3334
"browser": {
@@ -47,11 +48,13 @@
4748
]
4849
},
4950
"devDependencies": {
50-
"@babel/preset-react": "7.26.3",
5151
"@testing-library/jest-dom": "6.6.3",
5252
"@testing-library/react": "14.3.1",
5353
"@testing-library/user-event": "14.5.2",
5454
"esbuild": "0.24.2",
55+
"jest": "^29.7.0",
56+
"jest-environment-jsdom": "^29.7.0",
57+
"ts-jest": "^29.3.4",
5558
"ts-standard": "12.0.2",
5659
"typescript": "5.7.2"
5760
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. 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+
module.exports = 'chrome.svg';

javascript/grid-ui/src/tests/components/QueuedSessions.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import * as React from 'react'
1919
import QueuedSessions from '../../components/QueuedSessions/QueuedSessions'
20-
import { render, screen } from '@testing-library/react'
20+
import { screen } from '@testing-library/react'
21+
import { render } from '../utils/render-utils'
2122

2223
const sessionQueueRequests: string[] = [
2324
'{"acceptInsecureCerts":true,"browserName":"chrome","goog:chromeOptions":{"args":["--start-maximized"],"extensions":[]}}'

javascript/grid-ui/src/tests/components/RunningSessions.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import * as React from 'react'
1919
import RunningSessions from '../../components/RunningSessions/RunningSessions'
2020
import SessionInfo from '../../models/session-info'
21-
import { render, screen, within } from '@testing-library/react'
21+
import { act, screen, within } from '@testing-library/react'
22+
import { render } from '../utils/render-utils'
2223
import userEvent from '@testing-library/user-event'
2324
import { createSessionData } from '../../models/session-data'
2425

@@ -131,7 +132,13 @@ it('search field works for multiple results', async () => {
131132
it('search field works for lazy search', async () => {
132133
const { getByPlaceholderText, getByText, queryByText } = render(<RunningSessions sessions={sessions} origin={origin} />)
133134
const user = userEvent.setup()
134-
await user.type(getByPlaceholderText('Search…'), 'browserName')
135+
136+
await act(async () => {
137+
await user.type(getByPlaceholderText('Search…'), 'browserName')
138+
})
139+
140+
await new Promise(resolve => setTimeout(resolve, 0))
141+
135142
expect(getByPlaceholderText('Search…')).toHaveValue('browserName')
136143
expect(queryByText(sessions[0].id)).toBeInTheDocument()
137144
expect(getByText(sessions[1].id)).toBeInTheDocument()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. 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+
const originalError = console.error;
19+
console.error = (...args) => {
20+
if (/Warning.*not wrapped in act/.test(args[0])) {
21+
return;
22+
}
23+
originalError.call(console, ...args);
24+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. 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+
import React from 'react'
19+
import { render } from '@testing-library/react'
20+
import { MemoryRouter } from 'react-router-dom'
21+
22+
const renderWithRouter = (ui, { route = '/' } = {}) => {
23+
return render(
24+
<MemoryRouter initialEntries={[route]}>
25+
{ui}
26+
</MemoryRouter>
27+
)
28+
}
29+
30+
export { renderWithRouter as render }

0 commit comments

Comments
 (0)