mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-31 21:38:19 +03:00
Simplified DeleteShortUrlModal so that it only requires writing 'delete'
This commit is contained in:
parent
b79dced185
commit
0bf859d485
2 changed files with 9 additions and 9 deletions
|
@ -15,6 +15,8 @@ interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps {
|
|||
resetDeleteShortUrl: () => void;
|
||||
}
|
||||
|
||||
const DELETION_PATTERN = 'delete';
|
||||
|
||||
export const DeleteShortUrlModal = ({
|
||||
shortUrl,
|
||||
toggle,
|
||||
|
@ -41,12 +43,12 @@ export const DeleteShortUrlModal = ({
|
|||
<ModalBody>
|
||||
<p><b className="text-danger">Caution!</b> You are about to delete a short URL.</p>
|
||||
<p>This action cannot be undone. Once you have deleted it, all the visits stats will be lost.</p>
|
||||
<p>Write <b>{shortUrl.shortCode}</b> to confirm deletion.</p>
|
||||
<p>Write <b>{DELETION_PATTERN}</b> to confirm deletion.</p>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
placeholder={`Insert the short code (${shortUrl.shortCode})`}
|
||||
placeholder={`Insert ${DELETION_PATTERN}`}
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
/>
|
||||
|
@ -62,7 +64,7 @@ export const DeleteShortUrlModal = ({
|
|||
<button
|
||||
type="submit"
|
||||
className="btn btn-danger"
|
||||
disabled={inputValue !== shortUrl.shortCode || loading}
|
||||
disabled={inputValue !== DELETION_PATTERN || loading}
|
||||
>
|
||||
{loading ? 'Deleting...' : 'Delete'}
|
||||
</button>
|
||||
|
|
|
@ -62,30 +62,28 @@ describe('<DeleteShortUrlModal />', () => {
|
|||
});
|
||||
|
||||
it('enables submit button when proper short code is provided', async () => {
|
||||
const shortCode = 'abc123';
|
||||
const { user } = setUp({
|
||||
loading: false,
|
||||
error: false,
|
||||
shortCode,
|
||||
shortCode: 'abc123',
|
||||
});
|
||||
const getDeleteBtn = () => screen.getByRole('button', { name: 'Delete' });
|
||||
|
||||
expect(getDeleteBtn()).toHaveAttribute('disabled');
|
||||
await user.type(screen.getByPlaceholderText(/^Insert the short code/), shortCode);
|
||||
await user.type(screen.getByPlaceholderText('Insert delete'), 'delete');
|
||||
expect(getDeleteBtn()).not.toHaveAttribute('disabled');
|
||||
});
|
||||
|
||||
it('tries to delete short URL when form is submit', async () => {
|
||||
const shortCode = 'abc123';
|
||||
const { user } = setUp({
|
||||
loading: false,
|
||||
error: false,
|
||||
deleted: true,
|
||||
shortCode,
|
||||
shortCode: 'abc123',
|
||||
});
|
||||
|
||||
expect(deleteShortUrl).not.toHaveBeenCalled();
|
||||
await user.type(screen.getByPlaceholderText(/^Insert the short code/), shortCode);
|
||||
await user.type(screen.getByPlaceholderText('Insert delete'), 'delete');
|
||||
await user.click(screen.getByRole('button', { name: 'Delete' }));
|
||||
expect(deleteShortUrl).toHaveBeenCalledTimes(1);
|
||||
await waitFor(() => expect(shortUrlDeleted).toHaveBeenCalledTimes(1));
|
||||
|
|
Loading…
Reference in a new issue