mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 04:17:21 +00:00
Reset cache for all tests and remove describe
This commit is contained in:
parent
54ad17928e
commit
78b86c96c8
@ -19,9 +19,10 @@ import { createMemoryHistory } from 'history';
|
|||||||
import MarketPlacePage from '../index';
|
import MarketPlacePage from '../index';
|
||||||
import server from './server';
|
import server from './server';
|
||||||
|
|
||||||
|
// Increase the jest timeout to accommodate long running tests
|
||||||
|
jest.setTimeout(30000);
|
||||||
const toggleNotification = jest.fn();
|
const toggleNotification = jest.fn();
|
||||||
jest.mock('../../../hooks/useNavigatorOnLine', () => jest.fn(() => true));
|
jest.mock('../../../hooks/useNavigatorOnLine', () => jest.fn(() => true));
|
||||||
jest.setTimeout(30000);
|
|
||||||
jest.mock('@strapi/helper-plugin', () => ({
|
jest.mock('@strapi/helper-plugin', () => ({
|
||||||
...jest.requireActual('@strapi/helper-plugin'),
|
...jest.requireActual('@strapi/helper-plugin'),
|
||||||
useNotification: jest.fn(() => {
|
useNotification: jest.fn(() => {
|
||||||
@ -63,6 +64,8 @@ describe('Plugins tab', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
// Clear the cache to isolate each test
|
||||||
|
client.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => server.close());
|
afterAll(() => server.close());
|
||||||
@ -82,11 +85,12 @@ describe('Plugins tab', () => {
|
|||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await waitForReload();
|
||||||
|
|
||||||
renderedContainer = container;
|
renderedContainer = container;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders and matches the plugin tab snapshot', async () => {
|
it('renders and matches the plugin tab snapshot', async () => {
|
||||||
await waitForReload();
|
|
||||||
// Check snapshot
|
// Check snapshot
|
||||||
expect(renderedContainer.firstChild).toMatchSnapshot();
|
expect(renderedContainer.firstChild).toMatchSnapshot();
|
||||||
|
|
||||||
@ -127,9 +131,6 @@ describe('Plugins tab', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('shows the installed text for installed plugins', () => {
|
it('shows the installed text for installed plugins', () => {
|
||||||
const pluginsTab = screen.getByRole('tab', { name: /plugins/i });
|
|
||||||
userEvent.click(pluginsTab);
|
|
||||||
|
|
||||||
// Plugin that's already installed
|
// Plugin that's already installed
|
||||||
const alreadyInstalledCard = screen
|
const alreadyInstalledCard = screen
|
||||||
.getAllByTestId('npm-package-card')
|
.getAllByTestId('npm-package-card')
|
||||||
@ -197,203 +198,187 @@ describe('Plugins tab', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('filter requests', () => {
|
it('filters a collection option', async () => {
|
||||||
beforeAll(() => {
|
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
||||||
// Clear cache before all the tests run
|
userEvent.click(filtersButton);
|
||||||
client.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
||||||
await waitForReload();
|
userEvent.click(collectionsButton);
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
||||||
// Clear the cache again after each test
|
userEvent.click(option);
|
||||||
client.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('filters a collection option', async () => {
|
await waitForReload();
|
||||||
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
|
||||||
userEvent.click(filtersButton);
|
|
||||||
|
|
||||||
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
const optionTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
||||||
userEvent.click(collectionsButton);
|
expect(optionTag).toBeVisible();
|
||||||
|
|
||||||
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
const collectionCards = screen.getAllByTestId('npm-package-card');
|
||||||
userEvent.click(option);
|
expect(collectionCards.length).toEqual(2);
|
||||||
|
|
||||||
await waitForReload();
|
const collectionPlugin = screen.getByText('Gatsby Preview');
|
||||||
|
const notCollectionPlugin = screen.queryByText('Comments');
|
||||||
|
expect(collectionPlugin).toBeVisible();
|
||||||
|
expect(notCollectionPlugin).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
const optionTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
it('filters a category option', async () => {
|
||||||
expect(optionTag).toBeVisible();
|
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
||||||
|
userEvent.click(filtersButton);
|
||||||
|
|
||||||
const collectionCards = screen.getAllByTestId('npm-package-card');
|
const categoriesButton = screen.getByRole('button', { name: 'No categories selected' });
|
||||||
expect(collectionCards.length).toEqual(2);
|
userEvent.click(categoriesButton);
|
||||||
|
|
||||||
const collectionPlugin = screen.getByText('Gatsby Preview');
|
const option = screen.getByRole('option', { name: `Custom fields (4)` });
|
||||||
const notCollectionPlugin = screen.queryByText('Comments');
|
userEvent.click(option);
|
||||||
expect(collectionPlugin).toBeVisible();
|
|
||||||
expect(notCollectionPlugin).toEqual(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('filters a category option', async () => {
|
await waitForReload();
|
||||||
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
|
||||||
userEvent.click(filtersButton);
|
|
||||||
|
|
||||||
const categoriesButton = screen.getByRole('button', { name: 'No categories selected' });
|
const optionTag = screen.getByRole('button', { name: 'Custom fields' });
|
||||||
userEvent.click(categoriesButton);
|
expect(optionTag).toBeVisible();
|
||||||
|
|
||||||
const option = screen.getByRole('option', { name: `Custom fields (4)` });
|
const categoryCards = screen.getAllByTestId('npm-package-card');
|
||||||
userEvent.click(option);
|
expect(categoryCards.length).toEqual(2);
|
||||||
|
|
||||||
await waitForReload();
|
const categoryPlugin = screen.getByText('CKEditor 5 custom field');
|
||||||
|
const notCategoryPlugin = screen.queryByText('Comments');
|
||||||
|
expect(categoryPlugin).toBeVisible();
|
||||||
|
expect(notCategoryPlugin).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
const optionTag = screen.getByRole('button', { name: 'Custom fields' });
|
// filters collections and categories together
|
||||||
expect(optionTag).toBeVisible();
|
it('filters a category and a collection option', async () => {
|
||||||
|
// When a user clicks the filters button
|
||||||
|
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
||||||
|
// They should see a select button for collections with no options selected
|
||||||
|
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
||||||
|
// When they click the select button
|
||||||
|
userEvent.click(collectionsButton);
|
||||||
|
// They should see a Made by Strapi option
|
||||||
|
const collectionOption = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
||||||
|
// When they click the option
|
||||||
|
userEvent.click(collectionOption);
|
||||||
|
// The page should reload
|
||||||
|
await waitForReload();
|
||||||
|
// When they click the filters button again
|
||||||
|
userEvent.click(screen.getByRole('button', { name: 'Filters' }));
|
||||||
|
// They should see the collections button indicating 1 option selected
|
||||||
|
userEvent.click(screen.getByRole('button', { name: '1 collection selected Made by Strapi' }));
|
||||||
|
// They should the categories button with no options selected
|
||||||
|
const categoriesButton = screen.getByRole('button', { name: 'No categories selected' });
|
||||||
|
userEvent.click(categoriesButton);
|
||||||
|
const categoryOption = screen.getByRole('option', { name: `Custom fields (4)` });
|
||||||
|
userEvent.click(categoryOption);
|
||||||
|
// The page should reload
|
||||||
|
await waitForReload();
|
||||||
|
// When the page reloads they should see a tag for the selected option
|
||||||
|
const madeByStrapiTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
||||||
|
const customFieldsTag = screen.getByRole('button', { name: 'Custom fields' });
|
||||||
|
expect(madeByStrapiTag).toBeVisible();
|
||||||
|
expect(customFieldsTag).toBeVisible();
|
||||||
|
// They should see the correct number of results
|
||||||
|
const filterCards = screen.getAllByTestId('npm-package-card');
|
||||||
|
expect(filterCards.length).toEqual(4);
|
||||||
|
// They should see the collection option results
|
||||||
|
const collectionPlugin = screen.getByText('Gatsby Preview');
|
||||||
|
const notCollectionPlugin = screen.queryByText('Comments');
|
||||||
|
expect(collectionPlugin).toBeVisible();
|
||||||
|
expect(notCollectionPlugin).toEqual(null);
|
||||||
|
// They should see the category option results
|
||||||
|
const categoryPlugin = screen.getByText('CKEditor 5 custom field');
|
||||||
|
const notCategoryPlugin = screen.queryByText('Config Sync');
|
||||||
|
expect(categoryPlugin).toBeVisible();
|
||||||
|
expect(notCategoryPlugin).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
const categoryCards = screen.getAllByTestId('npm-package-card');
|
it('filters multiple collection options', async () => {
|
||||||
expect(categoryCards.length).toEqual(2);
|
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
||||||
|
userEvent.click(screen.getByRole('button', { name: 'No collections selected' }));
|
||||||
|
userEvent.click(screen.getByRole('option', { name: `Made by Strapi (13)` }));
|
||||||
|
|
||||||
const categoryPlugin = screen.getByText('CKEditor 5 custom field');
|
await waitForReload();
|
||||||
const notCategoryPlugin = screen.queryByText('Comments');
|
|
||||||
expect(categoryPlugin).toBeVisible();
|
|
||||||
expect(notCategoryPlugin).toEqual(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// filters collections and categories together
|
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
||||||
it('filters a category and a collection option', async () => {
|
userEvent.click(screen.getByRole('button', { name: `1 collection selected Made by Strapi` }));
|
||||||
// When a user clicks the filters button
|
userEvent.click(screen.getByRole('option', { name: `Verified (29)` }));
|
||||||
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
|
||||||
// They should see a select button for collections with no options selected
|
|
||||||
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
|
||||||
// When they click the select button
|
|
||||||
userEvent.click(collectionsButton);
|
|
||||||
// They should see a Made by Strapi option
|
|
||||||
const collectionOption = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
|
||||||
// When they click the option
|
|
||||||
userEvent.click(collectionOption);
|
|
||||||
// The page should reload
|
|
||||||
await waitForReload();
|
|
||||||
// When they click the filters button again
|
|
||||||
userEvent.click(screen.getByRole('button', { name: 'Filters' }));
|
|
||||||
// They should see the collections button indicating 1 option selected
|
|
||||||
userEvent.click(screen.getByRole('button', { name: '1 collection selected Made by Strapi' }));
|
|
||||||
// They should the categories button with no options selected
|
|
||||||
const categoriesButton = screen.getByRole('button', { name: 'No categories selected' });
|
|
||||||
userEvent.click(categoriesButton);
|
|
||||||
const categoryOption = screen.getByRole('option', { name: `Custom fields (4)` });
|
|
||||||
userEvent.click(categoryOption);
|
|
||||||
// The page should reload
|
|
||||||
await waitForReload();
|
|
||||||
// When the page reloads they should see a tag for the selected option
|
|
||||||
const madeByStrapiTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
|
||||||
const customFieldsTag = screen.getByRole('button', { name: 'Custom fields' });
|
|
||||||
expect(madeByStrapiTag).toBeVisible();
|
|
||||||
expect(customFieldsTag).toBeVisible();
|
|
||||||
// They should see the correct number of results
|
|
||||||
const filterCards = screen.getAllByTestId('npm-package-card');
|
|
||||||
expect(filterCards.length).toEqual(4);
|
|
||||||
// They should see the collection option results
|
|
||||||
const collectionPlugin = screen.getByText('Gatsby Preview');
|
|
||||||
const notCollectionPlugin = screen.queryByText('Comments');
|
|
||||||
expect(collectionPlugin).toBeVisible();
|
|
||||||
expect(notCollectionPlugin).toEqual(null);
|
|
||||||
// They should see the category option results
|
|
||||||
const categoryPlugin = screen.getByText('CKEditor 5 custom field');
|
|
||||||
const notCategoryPlugin = screen.queryByText('Config Sync');
|
|
||||||
expect(categoryPlugin).toBeVisible();
|
|
||||||
expect(notCategoryPlugin).toEqual(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('filters multiple collection options', async () => {
|
await waitForReload();
|
||||||
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
|
||||||
userEvent.click(screen.getByRole('button', { name: 'No collections selected' }));
|
|
||||||
userEvent.click(screen.getByRole('option', { name: `Made by Strapi (13)` }));
|
|
||||||
|
|
||||||
await waitForReload();
|
const madeByStrapiTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
||||||
|
const verifiedTag = screen.getByRole('button', { name: 'Verified' });
|
||||||
|
expect(madeByStrapiTag).toBeVisible();
|
||||||
|
expect(verifiedTag).toBeVisible();
|
||||||
|
expect(screen.getAllByTestId('npm-package-card').length).toEqual(3);
|
||||||
|
expect(screen.getByText('Gatsby Preview')).toBeVisible();
|
||||||
|
expect(screen.getByText('Config Sync')).toBeVisible();
|
||||||
|
expect(screen.queryByText('Comments')).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
it('filters multiple category options', async () => {
|
||||||
userEvent.click(screen.getByRole('button', { name: `1 collection selected Made by Strapi` }));
|
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
||||||
userEvent.click(screen.getByRole('option', { name: `Verified (29)` }));
|
userEvent.click(screen.getByRole('button', { name: 'No categories selected' }));
|
||||||
|
userEvent.click(screen.getByRole('option', { name: `Custom fields (4)` }));
|
||||||
|
|
||||||
await waitForReload();
|
await waitForReload();
|
||||||
|
|
||||||
const madeByStrapiTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
||||||
const verifiedTag = screen.getByRole('button', { name: 'Verified' });
|
userEvent.click(screen.getByRole('button', { name: `1 category selected Custom fields` }));
|
||||||
expect(madeByStrapiTag).toBeVisible();
|
userEvent.click(screen.getByRole('option', { name: `Monitoring (1)` }));
|
||||||
expect(verifiedTag).toBeVisible();
|
|
||||||
expect(screen.getAllByTestId('npm-package-card').length).toEqual(3);
|
|
||||||
expect(screen.getByText('Gatsby Preview')).toBeVisible();
|
|
||||||
expect(screen.getByText('Config Sync')).toBeVisible();
|
|
||||||
expect(screen.queryByText('Comments')).toEqual(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('filters multiple category options', async () => {
|
await waitForReload();
|
||||||
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
|
||||||
userEvent.click(screen.getByRole('button', { name: 'No categories selected' }));
|
|
||||||
userEvent.click(screen.getByRole('option', { name: `Custom fields (4)` }));
|
|
||||||
|
|
||||||
await waitForReload();
|
const customFieldsTag = screen.getByRole('button', { name: 'Custom fields' });
|
||||||
|
const monitoringTag = screen.getByRole('button', { name: 'Monitoring' });
|
||||||
|
expect(customFieldsTag).toBeVisible();
|
||||||
|
expect(monitoringTag).toBeVisible();
|
||||||
|
expect(screen.getAllByTestId('npm-package-card').length).toEqual(3);
|
||||||
|
expect(screen.getByText('CKEditor 5 custom field')).toBeVisible();
|
||||||
|
expect(screen.getByText('Sentry')).toBeVisible();
|
||||||
|
expect(screen.queryByText('Comments')).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
userEvent.click(screen.getByRole('button', { name: /filters/i }));
|
it('removes a filter option tag', async () => {
|
||||||
userEvent.click(screen.getByRole('button', { name: `1 category selected Custom fields` }));
|
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
||||||
userEvent.click(screen.getByRole('option', { name: `Monitoring (1)` }));
|
userEvent.click(filtersButton);
|
||||||
|
|
||||||
await waitForReload();
|
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
||||||
|
userEvent.click(collectionsButton);
|
||||||
|
|
||||||
const customFieldsTag = screen.getByRole('button', { name: 'Custom fields' });
|
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
||||||
const monitoringTag = screen.getByRole('button', { name: 'Monitoring' });
|
userEvent.click(option);
|
||||||
expect(customFieldsTag).toBeVisible();
|
|
||||||
expect(monitoringTag).toBeVisible();
|
|
||||||
expect(screen.getAllByTestId('npm-package-card').length).toEqual(3);
|
|
||||||
expect(screen.getByText('CKEditor 5 custom field')).toBeVisible();
|
|
||||||
expect(screen.getByText('Sentry')).toBeVisible();
|
|
||||||
expect(screen.queryByText('Comments')).toEqual(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes a filter option tag', async () => {
|
await waitForReload();
|
||||||
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
|
||||||
userEvent.click(filtersButton);
|
|
||||||
|
|
||||||
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
const optionTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
||||||
userEvent.click(collectionsButton);
|
expect(optionTag).toBeVisible();
|
||||||
|
|
||||||
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
userEvent.click(optionTag);
|
||||||
userEvent.click(option);
|
|
||||||
|
|
||||||
await waitForReload();
|
expect(optionTag).not.toBeVisible();
|
||||||
|
expect(history.location.search).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
const optionTag = screen.getByRole('button', { name: 'Made by Strapi' });
|
it('only filters in the plugins tab', async () => {
|
||||||
expect(optionTag).toBeVisible();
|
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
||||||
|
userEvent.click(filtersButton);
|
||||||
|
|
||||||
userEvent.click(optionTag);
|
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
||||||
|
userEvent.click(collectionsButton);
|
||||||
|
|
||||||
expect(optionTag).not.toBeVisible();
|
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
||||||
expect(history.location.search).toBe('');
|
userEvent.click(option);
|
||||||
});
|
|
||||||
|
|
||||||
it('only filters in the plugins tab', async () => {
|
await waitForReload();
|
||||||
const filtersButton = screen.getByRole('button', { name: /filters/i });
|
|
||||||
userEvent.click(filtersButton);
|
|
||||||
|
|
||||||
const collectionsButton = screen.getByRole('button', { name: 'No collections selected' });
|
const collectionCards = screen.getAllByTestId('npm-package-card');
|
||||||
userEvent.click(collectionsButton);
|
expect(collectionCards.length).toBe(2);
|
||||||
|
|
||||||
const option = screen.getByRole('option', { name: `Made by Strapi (13)` });
|
userEvent.click(screen.getByRole('tab', { name: /providers/i }));
|
||||||
userEvent.click(option);
|
|
||||||
|
|
||||||
await waitForReload();
|
const providerCards = screen.getAllByTestId('npm-package-card');
|
||||||
|
expect(providerCards.length).toBe(9);
|
||||||
|
|
||||||
const collectionCards = screen.getAllByTestId('npm-package-card');
|
userEvent.click(screen.getByRole('tab', { name: /plugins/i }));
|
||||||
expect(collectionCards.length).toBe(2);
|
expect(collectionCards.length).toBe(2);
|
||||||
|
|
||||||
userEvent.click(screen.getByRole('tab', { name: /providers/i }));
|
|
||||||
|
|
||||||
const providerCards = screen.getAllByTestId('npm-package-card');
|
|
||||||
expect(providerCards.length).toBe(9);
|
|
||||||
|
|
||||||
userEvent.click(screen.getByRole('tab', { name: /plugins/i }));
|
|
||||||
expect(collectionCards.length).toBe(2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user