mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 17:46:56 +03:00
24f60a7aa7
* fix: broken rtk-query-monitor demo not working #1126 Description: downgrades framer-motion in order to remove the runtime error "_framerMotion.motion.custom is not a function" See: https://stackoverflow.com/questions/66703410/next-js-framermotion-motion-custom-is-not-a-function * feat(rtk-query): add Data tab #1126 * fix: bump min popup width to 700px #1126 Description: improve UI of rtk-query right side tabs * fix: bump min popup window width again to 760px #1126 * chore: add changeset * feat(rtk-query): improve a11y of rtk-query-monitor tab panel #1126 * chore(rtk-query): add few integration tests to rtk-query-monitor #1126 * Fix merge * Deduplicate msw Co-authored-by: Nathan Bierema <nbierema@gmail.com>
120 lines
3.2 KiB
TypeScript
120 lines
3.2 KiB
TypeScript
import * as React from 'react';
|
|
import { Provider } from 'react-redux';
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
import { ReduxDevTools } from './devtools.mocks';
|
|
import { BaseQueryJestMockFunction, setupStore } from './rtk-query.mocks';
|
|
|
|
function Providers({
|
|
store,
|
|
children,
|
|
}: {
|
|
store: ReturnType<typeof setupStore>['store'];
|
|
children?: React.ComponentProps<typeof Provider>['children'];
|
|
}) {
|
|
const AnyProvider = Provider as any;
|
|
|
|
return (
|
|
<div id="app-root">
|
|
<AnyProvider store={store}>
|
|
{children}
|
|
<ReduxDevTools />
|
|
</AnyProvider>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
describe('rtk-query-monitor standalone integration', () => {
|
|
// Hushes symbol.observable warning
|
|
// @see https://github.com/reduxjs/redux-devtools/issues/1002
|
|
jest.spyOn(console, 'warn');
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
(console.warn as jest.Mock<void>).mockImplementation(() => {});
|
|
|
|
const dataPanelDomId = '#rtk-query-monitor-tab-panel-0';
|
|
|
|
const childrenTextContent = 'Renders children';
|
|
const fetchBaseQueryMock: BaseQueryJestMockFunction<Record<string, unknown>> =
|
|
jest.fn((...fetchArgs) =>
|
|
Promise.resolve({
|
|
data: {
|
|
name: fetchArgs[0],
|
|
},
|
|
})
|
|
);
|
|
const { store, pokemonApi } = setupStore(fetchBaseQueryMock, ReduxDevTools);
|
|
|
|
beforeAll(() => {
|
|
// let's populate api
|
|
(store.dispatch as any)(
|
|
pokemonApi.endpoints.getPokemonByName.initiate('bulbasaur')
|
|
);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
fetchBaseQueryMock.mockClear();
|
|
});
|
|
|
|
afterAll(() => {
|
|
(console.warn as jest.Mock<void>).mockRestore();
|
|
});
|
|
|
|
it('renders on a standalone app without crashing', () => {
|
|
const { container } = render(
|
|
<Providers store={store}>
|
|
<div data-testid="children">{childrenTextContent}</div>
|
|
</Providers>
|
|
);
|
|
|
|
expect(screen.getByTestId('children').textContent).toBe(
|
|
childrenTextContent
|
|
);
|
|
|
|
expect(
|
|
screen
|
|
.getByRole('tab', { name: /actions/i })
|
|
?.textContent?.toLowerCase()
|
|
.trim()
|
|
).toBe('actions');
|
|
expect(
|
|
screen
|
|
.getByRole('tab', { name: /data/i })
|
|
?.textContent?.toLowerCase()
|
|
.trim()
|
|
).toBe('data');
|
|
expect(
|
|
screen
|
|
.getByRole('tab', { name: /api/i })
|
|
?.textContent?.toLowerCase()
|
|
.trim()
|
|
).toBe('api');
|
|
expect(
|
|
container.querySelector(
|
|
'form[id="rtk-query-monitor-query-selection-form"]'
|
|
)
|
|
).toBeDefined();
|
|
});
|
|
|
|
it('displays query data tab content', async () => {
|
|
// `Promise.resolve()` hushes `@typescript-eslint/await-thenable`
|
|
await Promise.resolve(pokemonApi.util.getRunningOperationPromises());
|
|
|
|
const { container } = render(
|
|
<Providers store={store}>
|
|
<div data-testid="children">{childrenTextContent}</div>
|
|
</Providers>
|
|
);
|
|
|
|
// We need to select the query & the correct tab
|
|
fireEvent.click(screen.getByRole('tab', { name: /data/i }));
|
|
fireEvent.click(screen.getByText(/bulbasaur/i));
|
|
|
|
await waitFor(() =>
|
|
expect(container.querySelector(dataPanelDomId)).not.toBeNull()
|
|
);
|
|
|
|
expect(container.querySelector(dataPanelDomId)?.textContent).toMatch(
|
|
/name\W+pokemon\/bulbasaur/i
|
|
);
|
|
});
|
|
});
|