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

fix: create webhooks on an empty list page #19989

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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}
Copy link
Member

Choose a reason for hiding this comment

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

is this check necessary? the disabled flag should stop the callback right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but Typescript fights back

Copy link
Member

Choose a reason for hiding this comment

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

Does it? I've just tried locally and can't see an issue at the moment 🤔 can you share what you see?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-04-03 at 10 17 34

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, again

>
{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'));
});
});