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

upgrade React to 17.0.2 #2806

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"node": ">=8.0.0",
"yarn": "^1.0.0"
},
"resolutions": {
"@types/react": "^17.0.40"
},
krzotki marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"@aws-sdk/client-lambda": "^3.210.0",
"@codesandbox/sandpack-react": "^1.17.0",
Expand Down
7 changes: 7 additions & 0 deletions src/components/accordion/Accordion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ describe('<Accordion>', () => {

expect(item.getAttribute('aria-expanded')).toEqual('false');
expect(accordion.queryByRole('region')).toBeNull();

// This one does not trigger onFocus method in React 17
accordion.getByRole('button').focus();

// This one does not set document.activeElement
// https://github.com/jsdom/jsdom/issues/2586
fireEvent.focus(accordion.getByRole('button'));
krzotki marked this conversation as resolved.
Show resolved Hide resolved
krzotki marked this conversation as resolved.
Show resolved Hide resolved

expect(item).toEqual(document.activeElement);
userEvent.keyboard('{enter}');
expect(item.getAttribute('aria-expanded')).toEqual('true');
Expand Down
88 changes: 43 additions & 45 deletions src/components/popover/Popover.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,21 @@ export function RenderPopover(props: {
</Popover>
);
}

describe('<Popover />', () => {
it('does not display popover by default', () => {
render(<RenderPopover />);

expect(screen.queryByText(POPOVER_TEXT)).not.toBeInTheDocument();
});

it('displays popover when trigger is hovered', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);

const button = screen.getByTestId('button1');

expect(button).toBeInTheDocument();

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();
});

it('does not display popover when opening with hover is disabled and trigger is hovered', async () => {
Expand All @@ -78,148 +76,148 @@ describe('<Popover />', () => {
});

it('does not keep popover open when click opening is disabled and trigger is clicked, then unhovered', async () => {
const popover = render(<RenderPopover useClick={false} />);
render(<RenderPopover useClick={false} />);
const button = screen.getByTestId('button1');

userEvent.hover(button);
userEvent.click(button);
expect(screen.queryByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.unhover(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover when trigger is no longer hovered', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);

const button = screen.getByTestId('button1');

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.unhover(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('does not hide popover when hover leaves if trigger was clicked', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

userEvent.hover(button);
fireEvent.click(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.unhover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(screen.getByText(POPOVER_TEXT)).toBeInTheDocument();
});

it('displays popover when trigger is focused', () => {
const popover = render(<RenderPopover />);
it('displays popover when trigger is focused', async () => {
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();
});

it('hides popover when trigger loses focus', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

fireEvent.blur(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover if hover leaves, even when trigger is focused', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.unhover(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover if focus leaves, even when trigger is hovered', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

fireEvent.blur(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover when Esc key is hit, when popover is triggered by focus', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

fireEvent.keyDown(document.activeElement, {key: 'Escape'});
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover when Esc key is hit, when popover is triggered by hover', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

fireEvent.keyDown(document.activeElement, {key: 'Escape'});
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('hides popover when Esc key is hit, when popover is both focused and hovered', async () => {
const popover = render(<RenderPopover />);
render(<RenderPopover />);
const button = screen.getByTestId('button1');

fireEvent.focus(button);
userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

fireEvent.keyDown(document.activeElement, {key: 'Escape'});
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('displays popover initally when set as default open', async () => {
const popover = render(<RenderPopover defaultOpen />);
it('displays popover initially when set as default open', async () => {
render(<RenderPopover defaultOpen />);

expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();
});

it('can hide default open popover by clicking somewhere in the document', async () => {
const {queryByText} = render(<RenderPopover defaultOpen />);
render(<RenderPopover defaultOpen />);

userEvent.click(document.body);
await waitForElementToBeRemoved(() => queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));
});

it('popover shows up and hides properly when set as default open', async () => {
const popover = render(<RenderPopover defaultOpen />);
render(<RenderPopover defaultOpen />);

const button = screen.getByTestId('button1');

expect(button).toBeInTheDocument();
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();

userEvent.unhover(button);
await waitForElementToBeRemoved(() => popover.queryByText(POPOVER_TEXT));
await waitForElementToBeRemoved(() => screen.queryByText(POPOVER_TEXT));

userEvent.hover(button);
expect(popover.getByText(POPOVER_TEXT)).toBeInTheDocument();
expect(await screen.findByText(POPOVER_TEXT)).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions src/components/rating/Rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Rating extends React.Component<RatingPropsType> {
(arg0: React.MouseEvent<HTMLSpanElement>) => unknown
> = [];

// It's a typo, should be componentWillReceiveProps (UNSAFE_componentWillReceiveProps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fix this? what is the solution here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution would be to use UNSAFE_componentWillReceiveProps but this will change behaviour of the component as the previous componentWillReciveProps was never called.
Other solution would be to remove it completely

componentWillReciveProps(nextProps: RatingPropsType) {
if (this.props.metricSize !== nextProps.metricSize) {
this.createStarsOnChangeFunctions(nextProps.metricSize);
Expand Down
Loading
Loading