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 1 commit
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 @@ -44,6 +44,7 @@ import { useTypedSelector } from '../../../../core/store/hooks';

import { useWebhooks } from './hooks/useWebhooks';


/* -------------------------------------------------------------------------------------------------
* ListPage
* -----------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -383,7 +384,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 @@ -8,6 +8,7 @@ import { rest } from 'msw';

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


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

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({
push: mockedPush
}),
useLocation: jest.fn().mockReturnValue({
pathname: '/admin/settings/webhooks',
})
}));
const mockedPush = jest.fn();
joshuaellis marked this conversation as resolved.
Show resolved Hide resolved


describe('Webhooks | ListPage', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -148,4 +161,28 @@ 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 { getByText, getByRole } = render(<ListPage />);

await waitFor(() => {
expect(getByText('No webhooks found')).toBeInTheDocument();
});
joshuaellis marked this conversation as resolved.
Show resolved Hide resolved

fireEvent.click(getByRole('button', {name: 'Create new webhook'}));
Copy link
Member

Choose a reason for hiding this comment

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

you should prefer user over fireEvent where possible imo :)




expect(mockedPush).toHaveBeenCalledWith('/admin/settings/webhooks/create')
});
});