Skip to content

Commit

Permalink
Merge pull request #19989 from strapi/fix/create-webhook-button
Browse files Browse the repository at this point in the history
fix: create webhooks on an empty list page
  • Loading branch information
Christian committed Apr 3, 2024
2 parents 1fac05e + e510c18 commit a36def2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const ListPage = () => {
colCount={5}
rowCount={numberOfWebhooks + 1}
footer={
<TFooter onClick={canCreate ? goTo('create') : undefined} icon={<Plus />}>
<TFooter onClick={goTo('create')} icon={<Plus />}>
{formatMessage({
id: 'Settings.webhooks.list.button.add',
defaultMessage: 'Create new webhook',
Expand Down Expand Up @@ -383,7 +383,8 @@ const ListPage = () => {
<Button
variant="secondary"
startIcon={<Plus />}
onClick={() => (canCreate ? goTo('create') : {})}
disabled={!canCreate}
onClick={canCreate ? goTo('create') : undefined}
>
{formatMessage({
id: 'Settings.webhooks.list.button.add',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React from 'react';
import { useRBAC } from '@strapi/helper-plugin';
import { fireEvent, waitForElementToBeRemoved } from '@testing-library/react';
import { mockData } from '@tests/mockData';
import { render, waitFor, server } from '@tests/utils';
import { render, waitFor, server, screen } from '@tests/utils';
import { rest } from 'msw';
import { useLocation } from 'react-router-dom';

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

Expand All @@ -17,6 +18,12 @@ jest.mock('@strapi/helper-plugin', () => ({
useFocusWhenNavigate: jest.fn(),
}));

const LocationDisplay = () => {
const location = useLocation();

return <span data-testId="location">{location.pathname}</span>;
};

describe('Webhooks | ListPage', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -148,4 +155,34 @@ describe('Webhooks | ListPage', () => {
expect(enableSwitches[0]).toHaveAttribute('aria-checked', 'false');
});
});

it('should allow to create a new webhook on empty state screen by clicking on the button', async () => {
server.use(
rest.get('/admin/webhooks', (req, res, ctx) => {
return res(
ctx.json({
data: [],
})
);
})
);

const { getByRole, findByText, user } = render(<ListPage />, {
renderOptions: {
wrapper({ children }) {
return (
<>
{children}
<LocationDisplay />
</>
);
},
},
});

await findByText('No webhooks found');
expect(screen.getByTestId('location')).not.toHaveTextContent('/create');
await user.click(getByRole('button', { name: 'Create new webhook' }));
await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/create'));
});
});

0 comments on commit a36def2

Please sign in to comment.