Skip to content

Commit

Permalink
test(web-terminal): remove TerminalComponent test race condition issue (
Browse files Browse the repository at this point in the history
janus-idp#1071)

* test(web-terminal): remove TerminalComponent test race condition issue

Signed-off-by: Christoph Jerolimov <[email protected]>

* Revert "chore: updates jest timeout (janus-idp#1070)"

This reverts commit ca2b119.

* chore: update plugin dep

---------

Signed-off-by: Christoph Jerolimov <[email protected]>
Co-authored-by: Jaivardhan Kumar <[email protected]>
  • Loading branch information
christoph-jerolimov and invincibleJai authored Jan 17, 2024
1 parent ca2b119 commit 05ee8dc
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"*.{js,jsx,ts,tsx,mjs,cjs}": "turbo run lint:fix --"
},
"jest": {
"testTimeout": 25000
"testTimeout": 15000
},
"release": {
"branches": "main",
Expand Down
1 change: 0 additions & 1 deletion plugins/acr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### Dependencies

* **@janus-idp/shared-react:** upgraded to 2.4.0
* **@janus-idp/cli:** upgraded to 1.5.0

## @janus-idp/backstage-plugin-acr [1.2.17](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/[email protected]...@janus-idp/[email protected]) (2023-12-22)
Expand Down
2 changes: 1 addition & 1 deletion plugins/acr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.45",
"@janus-idp/shared-react": "2.4.0",
"@janus-idp/shared-react": "2.3.0",
"react-use": "^17.4.0"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion plugins/jfrog-artifactory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### Dependencies

* **@janus-idp/shared-react:** upgraded to 2.4.0
* **@janus-idp/cli:** upgraded to 1.5.0

## @janus-idp/backstage-plugin-jfrog-artifactory [1.2.17](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/[email protected]...@janus-idp/[email protected]) (2023-12-22)
Expand Down
2 changes: 1 addition & 1 deletion plugins/jfrog-artifactory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.45",
"@janus-idp/shared-react": "2.4.0",
"@janus-idp/shared-react": "2.3.0",
"react-use": "^17.4.0"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion plugins/nexus-repository-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### Dependencies

* **@janus-idp/shared-react:** upgraded to 2.4.0
* **@janus-idp/cli:** upgraded to 1.5.0

## @janus-idp/backstage-plugin-nexus-repository-manager [1.4.17](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/[email protected]...@janus-idp/[email protected]) (2023-12-22)
Expand Down
2 changes: 1 addition & 1 deletion plugins/nexus-repository-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@backstage/core-components": "^0.13.6",
"@backstage/core-plugin-api": "^1.7.0",
"@backstage/plugin-catalog-react": "^1.8.5",
"@janus-idp/shared-react": "2.4.0",
"@janus-idp/shared-react": "2.3.0",
"@backstage/theme": "^0.4.3",
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.11.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TestApiProvider,
} from '@backstage/test-utils';

import { createTheme, ThemeProvider } from '@material-ui/core';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
Expand Down Expand Up @@ -41,6 +42,24 @@ const mockConfig = new MockConfigApi({
},
});

const theme = createTheme({
transitions: {
duration: {
// Disable <Progress /> visibility fade-in delay
// https://github.com/backstage/backstage/blob/master/packages/core-components/src/components/Progress/Progress.tsx
short: 0,
},
},
});

const Providers: React.FC = ({ children }) => (
<ThemeProvider theme={theme}>
<TestApiProvider apis={[[configApiRef, mockConfig]]}>
<EntityProvider entity={entityMock}>{children}</EntityProvider>
</TestApiProvider>
</ThemeProvider>
);

describe('TerminalComponent', () => {
const server = setupServer();
const VALID_TOKEN = 'valid-token';
Expand Down Expand Up @@ -81,7 +100,6 @@ describe('TerminalComponent', () => {
);
}
return res(
ctx.delay(800),
ctx.status(200),
ctx.json(require('./__fixtures__/createWorkspace.json')),
);
Expand All @@ -90,62 +108,38 @@ describe('TerminalComponent', () => {
}),
);
});

afterEach(() => {
server.resetHandlers();
});

it('should render form for the Web Terminal', async () => {
const rendered = render(
<TestApiProvider apis={[[configApiRef, mockConfig]]}>
<EntityProvider entity={entityMock}>
<TerminalComponent />
</EntityProvider>
</TestApiProvider>,
<Providers>
<TerminalComponent />
</Providers>,
);
expect(rendered.getByText('Web Terminal')).toBeInTheDocument();
});
it('should start loading', async () => {
const rendered = render(
<TestApiProvider apis={[[configApiRef, mockConfig]]}>
<EntityProvider entity={entityMock}>
<TerminalComponent />
</EntityProvider>
</TestApiProvider>,
);
const inputField = rendered
.getByTestId('token-input')
.querySelector('input');
if (!inputField) {
throw new Error('Input field not found');
}
fireEvent.change(inputField, { target: { value: VALID_TOKEN } });
expect(inputField.value).toBe(VALID_TOKEN);
const submit = rendered.getByTestId('submit-token-button');
fireEvent.click(submit);
await waitFor(() =>
expect(rendered.getByTestId('progress')).toBeInTheDocument(),
);
});

it('should render popup on token without valid permissions', async () => {
const rendered = render(
<TestApiProvider apis={[[configApiRef, mockConfig]]}>
<EntityProvider entity={entityMock}>
<TerminalComponent />
</EntityProvider>
</TestApiProvider>,
<Providers>
<TerminalComponent />
</Providers>,
);
const inputField = rendered
.getByTestId('token-input')
.querySelector('input');
if (!inputField) {
throw new Error('Input field not found');
}
fireEvent.change(inputField, {
await fireEvent.change(inputField, {
target: { value: NOT_VALID_PERMISSIONS_TOKEN },
});
expect(inputField.value).toBe(NOT_VALID_PERMISSIONS_TOKEN);
const submit = rendered.getByTestId('submit-token-button');
fireEvent.click(submit);
await fireEvent.click(submit);
await waitFor(() =>
expect(rendered.getByTestId('namespace-picker')).toBeInTheDocument(),
);
Expand All @@ -163,22 +157,23 @@ describe('TerminalComponent', () => {
})),
});
const rendered = render(
<TestApiProvider apis={[[configApiRef, mockConfig]]}>
<EntityProvider entity={entityMock}>
<TerminalComponent />
</EntityProvider>
</TestApiProvider>,
<Providers>
<TerminalComponent />
</Providers>,
);
const inputField = rendered
.getByTestId('token-input')
.querySelector('input');
if (!inputField) {
throw new Error('Input field not found');
}
fireEvent.change(inputField, { target: { value: VALID_TOKEN } });
await fireEvent.change(inputField, { target: { value: VALID_TOKEN } });
expect(inputField.value).toBe(VALID_TOKEN);
const submit = rendered.getByTestId('submit-token-button');
fireEvent.click(submit);
await fireEvent.click(submit);
await waitFor(() =>
expect(rendered.getByTestId('progress')).toBeInTheDocument(),
);
await waitFor(() =>
expect(rendered.getByTestId('terminal')).toBeInTheDocument(),
);
Expand Down
63 changes: 63 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6426,6 +6426,69 @@
"@backstage/config" "^1.1.1"
deep-freeze "^0.0.1"

"@janus-idp/[email protected]":
version "1.4.7"
resolved "https://registry.yarnpkg.com/@janus-idp/cli/-/cli-1.4.7.tgz#2f013d68f768bc3d5b930c9527e032a1dd90c379"
integrity sha512-7lnmkTvcxT/iFXE3or5exgQ3CXd+VR9gJtCAXzjcFfpf8LfTQ4SgS7xRiijaQSZJacg/JSpRoIxuIH0sOHAvvw==
dependencies:
"@backstage/cli-common" "^0.1.13"
"@backstage/cli-node" "^0.1.5"
"@backstage/config" "^1.1.1"
"@backstage/config-loader" "^1.5.1"
"@backstage/errors" "^1.2.3"
"@backstage/eslint-plugin" "^0.1.3"
"@backstage/types" "^1.1.1"
"@manypkg/get-packages" "^1.1.3"
"@openshift/dynamic-plugin-sdk-webpack" "^3.0.0"
"@pmmmwh/react-refresh-webpack-plugin" "^0.5.7"
"@rollup/plugin-commonjs" "^25.0.4"
"@rollup/plugin-json" "^6.0.0"
"@rollup/plugin-node-resolve" "^15.2.1"
"@rollup/plugin-yaml" "^4.0.0"
"@svgr/rollup" "^8.1.0"
"@svgr/webpack" "^6.5.1"
"@yarnpkg/lockfile" "^1.1.0"
"@yarnpkg/parsers" "^3.0.0-rc.4"
bfj "^7.0.2"
chalk "^4.0.0"
chokidar "^3.3.1"
commander "^9.1.0"
css-loader "^6.5.1"
esbuild "^0.19.0"
esbuild-loader "^2.18.0"
eslint "^8.49.0"
eslint-config-prettier "^8.10.0"
eslint-webpack-plugin "^3.2.0"
express "^4.18.2"
fork-ts-checker-webpack-plugin "^7.0.0-alpha.8"
fs-extra "^10.1.0"
handlebars "^4.7.7"
html-webpack-plugin "^5.3.1"
inquirer "^8.2.0"
lodash "^4.17.21"
mini-css-extract-plugin "^2.4.2"
node-libs-browser "^2.2.1"
npm-packlist "^5.0.0"
ora "^5.3.0"
postcss "^8.2.13"
process "^0.11.10"
react-dev-utils "^12.0.0-next.60"
react-refresh "^0.14.0"
recursive-readdir "^2.2.2"
rollup "^2.78.0"
rollup-plugin-dts "^4.0.1"
rollup-plugin-esbuild "^4.7.2"
rollup-plugin-postcss "^4.0.0"
rollup-pluginutils "^2.8.2"
semver "^7.5.4"
style-loader "^3.3.1"
swc-loader "^0.2.3"
typescript-json-schema "^0.62.0"
webpack "^5.89.0"
webpack-dev-server "^4.15.1"
yml-loader "^2.1.0"
yn "^4.0.0"

"@jest/console@^29.7.0":
version "29.7.0"
resolved "https://registry.yarnpkg.com/@jest/console/-/console-29.7.0.tgz#cd4822dbdb84529265c5a2bdb529a3c9cc950ffc"
Expand Down

0 comments on commit 05ee8dc

Please sign in to comment.