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

refactor: reorganize folder structure of React 18 tests for v9 #34051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 0 additions & 24 deletions apps/react-18-tests-v9/src/App.tsx

This file was deleted.

80 changes: 0 additions & 80 deletions apps/react-18-tests-v9/src/Portal.cy.tsx

This file was deleted.

Empty file.
31 changes: 31 additions & 0 deletions apps/react-18-tests-v9/src/components/Dialog/Dialog.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { mount as mountBase } from '@cypress/react';
import { Dialog, DialogSurface, DialogTrigger, DialogBody, Button } from '@fluentui/react-components';

import { Provider } from '../Provider/Provider';

const mount = (element: JSX.Element) => {
mountBase(<Provider>{element}</Provider>);
};

describe('Dialog', () => {
it('should render a Dialog', () => {
mount(
<Dialog>
<DialogTrigger>
<Button>Open dialog</Button>
</DialogTrigger>

<DialogSurface>
<DialogBody>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam exercitationem cumque repellendus eaque
est dolor eius expedita nulla ullam? Tenetur reprehenderit aut voluptatum impedit voluptates in natus iure
cumque eaque?
</DialogBody>
</DialogSurface>
</Dialog>,
);

cy.get('button').click().get('.fui-DialogSurface').should('exist');
});
});
32 changes: 32 additions & 0 deletions apps/react-18-tests-v9/src/components/Menu/Menu.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import { mount as mountBase } from '@cypress/react';
import { Menu, MenuTrigger, MenuPopover, MenuList, MenuItem } from '@fluentui/react-components';

import { Provider } from '../Provider/Provider';

const mount = (element: JSX.Element) => {
mountBase(<Provider>{element}</Provider>);
};

describe('Menu', () => {
it('should render a Menu', () => {
mount(
<Menu>
<MenuTrigger>
<button>Click Me</button>
</MenuTrigger>

<MenuPopover>
<MenuList>
<MenuItem>Item</MenuItem>
<MenuItem>Item</MenuItem>
<MenuItem>Item</MenuItem>
<MenuItem>Item</MenuItem>
</MenuList>
</MenuPopover>
</Menu>,
);

cy.get('button').click().get('.fui-MenuList').should('exist');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { mount as mountBase } from '@cypress/react';
import {
makeStyles,
Button,
Expand All @@ -15,10 +16,9 @@ import {
OverflowItemProps,
useIsOverflowItemVisible,
useOverflowMenu,
FluentProvider,
teamsLightTheme,
} from '@fluentui/react-components';
import { mount as mountBase } from '@cypress/react';

import { Provider } from '../Provider/Provider';

// eslint-disable-next-line @griffel/styles-file
const useStyles = makeStyles({
Expand Down Expand Up @@ -90,11 +90,7 @@ const OverflowMenu: React.FC<{ itemIds: string[] }> = ({ itemIds }) => {
};

const mount = (element: JSX.Element) => {
mountBase(
<React.StrictMode>
<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>
</React.StrictMode>,
);
mountBase(<Provider>{element}</Provider>);
};

describe('Overflow', () => {
Expand Down
17 changes: 17 additions & 0 deletions apps/react-18-tests-v9/src/components/Popover/Popover.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { mount as mountBase } from '@cypress/react';

import { CustomPopover as Popover } from './Popover';
import { Provider } from '../Provider/Provider';

const mount = (element: JSX.Element) => {
mountBase(<Provider>{element}</Provider>);
};

describe('Popover with React 18', () => {
it('should render a Popover', () => {
mount(<Popover />);

cy.get('button').click().get('.fui-PopoverSurface').should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { resetIdsForTests } from '@fluentui/react-utilities';
import { render } from '@testing-library/react';
import * as React from 'react';

import { App } from './App';
import { CustomPopover as Popover } from './Popover';

describe('App with React 18', () => {
describe('Popover component with React 18', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

Expand All @@ -20,7 +20,7 @@ describe('App with React 18', () => {
it('should apply matching className in strict mode', () => {
const { getByText } = render(
<React.StrictMode>
<App />
<Popover />
</React.StrictMode>,
);
const element = getByText('Click Me');
Expand Down
16 changes: 16 additions & 0 deletions apps/react-18-tests-v9/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { Button, Popover, PopoverTrigger, PopoverSurface } from '@fluentui/react-components';
import { Provider } from '../Provider/Provider';

export const CustomPopover = () => {
return (
<Provider>
<Popover>
<PopoverTrigger>
<Button>Click Me</Button>
</PopoverTrigger>
<PopoverSurface>This is a popover</PopoverSurface>
</Popover>
</Provider>
);
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as React from 'react';
import { mount } from '@cypress/react';
Copy link
Contributor

@mainframev mainframev Mar 22, 2025

Choose a reason for hiding this comment

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

Are we actually testing with a version of Cypress that supports React 18? If not, it seems like the cypress mount might not be using createRoot from the React 18 react-dom/client API.

Currently, we have cypress/[email protected] in the root and we're still using [email protected], which, as I see also inside using cypress/react that does not support 18.

From migration docs of cypress 14:
image

Copy link
Contributor Author

@marcosmoura marcosmoura Mar 23, 2025

Choose a reason for hiding this comment

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

This doesn't add any support for React 18 yet. This just reorganize the files and folders so we can add the tests correctly later.

This dependency change will be applied in a follow-up PR.

Copy link
Contributor

@mainframev mainframev Mar 23, 2025

Choose a reason for hiding this comment

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

Gotcha, thanks ;) I know it's a bit unrelated to the PR purpose, but I was not sure if it's known, as package already supposed to be setup for testing against React 18.

import { Button } from '@fluentui/react-components';

import { App } from './App';
import { Provider } from './Provider';

const providerSelector = '.fui-FluentProvider';

describe('App with React 18', () => {
describe('Provider with React 18', () => {
describe('FluentProvider', () => {
it('should apply matching className in strict mode', () => {
mount(
<React.StrictMode>
<App />
</React.StrictMode>,
<Provider>
<Button>Click Me</Button>
</Provider>,
);

cy.get(providerSelector)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { render } from '@testing-library/react';
import * as React from 'react';

import { Button } from '@fluentui/react-components';
import { resetIdsForTests } from '@fluentui/react-utilities';

import { Provider } from './Provider';

describe('Provider with React 18', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(noop);
});

afterEach(() => {
resetIdsForTests();
});

describe('FluentProvider', () => {
it('should apply matching className in strict mode', () => {
const { getByText } = render(
<Provider>
<Button>Click Me</Button>
</Provider>,
);
const element = getByText('Click Me');
const elementProviderClassName = element.className.split(' ')[1];
const matchingStyleTag = document.getElementById(elementProviderClassName);

expect(matchingStyleTag).toBeDefined();
});
});
});
10 changes: 10 additions & 0 deletions apps/react-18-tests-v9/src/components/Provider/Provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';
import { webLightTheme, FluentProvider } from '@fluentui/react-components';

export const Provider = ({ children }: React.PropsWithChildren) => {
return (
<React.StrictMode>
<FluentProvider theme={webLightTheme}>{children}</FluentProvider>
</React.StrictMode>
);
};
11 changes: 1 addition & 10 deletions apps/react-18-tests-v9/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

const root = createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
export {};