Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-ISSUE Use ReactDOM 18 functions #2569

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/assisted-ui/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import { App } from './components/App';

const rootElement = document.getElementById('root');
if (rootElement) {
rootElement.classList.add('pf-v5-u-h-100vh');
ReactDOM.render(
const root = ReactDOM.createRoot(rootElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
rootElement,
);
}
12 changes: 8 additions & 4 deletions libs/ui-lib/lib/_test-helpers/mock-container.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { unmountComponentAtNode } from 'react-dom';
import ReactDOM from 'react-dom/client';

let element: HTMLDivElement | null = null;
let root: ReactDOM.Root;

function getMockContainer() {
return element;
if (element) {
root = ReactDOM.createRoot(element);
return root;
}
}

/**
Expand All @@ -29,8 +33,8 @@ function initMockContainer(
*/
function tryResetMockContainer() {
let didResetMockContainer = false;
if (element) {
unmountComponentAtNode(element);
if (element && root) {
root.unmount();
element.remove();
element = null;
didResetMockContainer = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ export const LabelField: React.FC<LabelFieldProps> = ({
}}
addKeys={[13, 32, 188]}
renderTag={({ tag, key, onRemove, getTagDisplayValue }) => (
<LabelValue
key={key as number}
onClose={() => onRemove(key as number)}
value={getTagDisplayValue(tag)}
/>
<LabelValue key={key} onClose={() => onRemove(key)} value={getTagDisplayValue(tag)} />
)}
addOnBlur
inputProps={{
Expand Down
65 changes: 36 additions & 29 deletions libs/ui-lib/lib/ocm/hooks/_use-feature-detection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Account, Organization } from '@openshift-assisted/types/accounts-m
import { describe, it, vi, expect } from 'vitest';
import * as React from 'react';
import { Provider } from 'react-redux';
import { render } from 'react-dom';
import { act } from 'react-dom/test-utils';
import { featureFlagsActions } from '../store/slices/feature-flags/slice';
import { storeDay1 } from '../store/store-day1';
Expand Down Expand Up @@ -40,16 +39,19 @@ describe('use-feature-detection.ts', () => {
],
});

await act(() =>
Promise.resolve(
render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
getMockContainer(),
const mockContainer = getMockContainer();

if (mockContainer) {
await act(() =>
Promise.resolve(
mockContainer.render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
),
),
),
);
);
}

expect(isFeatureEnabled('ASSISTED_INSTALLER_PLATFORM_OCI')(storeDay1.getState())).toBe(true);
});
Expand All @@ -70,16 +72,19 @@ describe('use-feature-detection.ts', () => {
],
});

await act(() =>
Promise.resolve(
render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
getMockContainer(),
const mockContainer = getMockContainer();

if (mockContainer) {
await act(() =>
Promise.resolve(
mockContainer.render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
),
),
),
);
);
}

expect(isFeatureEnabled('ASSISTED_INSTALLER_PLATFORM_OCI')(storeDay1.getState())).toBe(
featuresOverride.ASSISTED_INSTALLER_PLATFORM_OCI,
Expand All @@ -93,17 +98,19 @@ describe('use-feature-detection.ts', () => {
return null;
};

await act(() =>
Promise.resolve(
render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
getMockContainer(),
),
),
);
const mockContainer = getMockContainer();

if (mockContainer) {
await act(() =>
Promise.resolve(
mockContainer.render(
<Provider store={storeDay1}>
<DummyComponent />
</Provider>,
),
),
);
}
/* Here we don't mock the call to the user organization API, therefore the
* capabilities in the currentUser slice should remain undefined, since the list
* of featuresOverride should get filtered out of features not prefixed with
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@types/node": "^18.14.6",
"@types/react": "<17.0.30",
"@types/react-autosuggest": "^10.1.5",
"@types/react-dom": "<17.0.30",
"@types/react-dom": "^18.3.0",
"@types/react-measure": "^2.0.8",
"@types/react-redux": "^7.1.7",
"@types/react-router-dom": "^5.3.0",
Expand Down
Loading
Loading