mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
feat(frontend): deactivate delete note button if user is not owner
This button and its functionality only works if the user is the owner, so it doesn't make sense to make it possible to press it otherwise… Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
e7e81cf670
commit
759c906506
3 changed files with 69 additions and 3 deletions
|
@ -1,5 +1,47 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`DeletionModal disables deletion when user is not owner 1`] = `
|
||||||
|
<div
|
||||||
|
class="modal-dialog text-dark "
|
||||||
|
data-testid="commonModal"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="modal-content"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="modal-header"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="modal-title h4"
|
||||||
|
>
|
||||||
|
<span />
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
aria-label="Close"
|
||||||
|
class="btn-close"
|
||||||
|
type="button"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="text-dark modal-body"
|
||||||
|
>
|
||||||
|
testText
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="modal-footer"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="btn btn-danger"
|
||||||
|
disabled=""
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
testDeletionButton
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`DeletionModal renders correctly with deletionButtonI18nKey 1`] = `
|
exports[`DeletionModal renders correctly with deletionButtonI18nKey 1`] = `
|
||||||
<div
|
<div
|
||||||
class="modal-dialog text-dark "
|
class="modal-dialog text-dark "
|
||||||
|
|
|
@ -1,15 +1,37 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import { mockNoteOwnership } from '../../../test-utils/note-ownership'
|
||||||
import { mockI18n } from '../../markdown-renderer/test-utils/mock-i18n'
|
import { mockI18n } from '../../markdown-renderer/test-utils/mock-i18n'
|
||||||
import { DeletionModal } from './deletion-modal'
|
import { DeletionModal } from './deletion-modal'
|
||||||
import { render, screen } from '@testing-library/react'
|
import { render, screen } from '@testing-library/react'
|
||||||
|
|
||||||
describe('DeletionModal', () => {
|
describe('DeletionModal', () => {
|
||||||
it('renders correctly with deletionButtonI18nKey', async () => {
|
beforeEach(async () => {
|
||||||
await mockI18n()
|
await mockI18n()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetAllMocks()
|
||||||
|
jest.resetModules()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders correctly with deletionButtonI18nKey', async () => {
|
||||||
|
mockNoteOwnership('test', 'test')
|
||||||
|
const onConfirm = jest.fn()
|
||||||
|
render(
|
||||||
|
<DeletionModal onConfirm={onConfirm} deletionButtonI18nKey={'testDeletionButton'} show={true}>
|
||||||
|
testText
|
||||||
|
</DeletionModal>
|
||||||
|
)
|
||||||
|
const modal = await screen.findByTestId('commonModal')
|
||||||
|
expect(modal).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('disables deletion when user is not owner', async () => {
|
||||||
|
mockNoteOwnership('test2', 'test')
|
||||||
const onConfirm = jest.fn()
|
const onConfirm = jest.fn()
|
||||||
render(
|
render(
|
||||||
<DeletionModal onConfirm={onConfirm} deletionButtonI18nKey={'testDeletionButton'} show={true}>
|
<DeletionModal onConfirm={onConfirm} deletionButtonI18nKey={'testDeletionButton'} show={true}>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import { useIsOwner } from '../../../hooks/common/use-is-owner'
|
||||||
import { cypressId } from '../../../utils/cypress-attribute'
|
import { cypressId } from '../../../utils/cypress-attribute'
|
||||||
import type { CommonModalProps } from './common-modal'
|
import type { CommonModalProps } from './common-modal'
|
||||||
import { CommonModal } from './common-modal'
|
import { CommonModal } from './common-modal'
|
||||||
|
@ -40,6 +41,7 @@ export const DeletionModal: React.FC<PropsWithChildren<DeletionModalProps>> = ({
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
|
const isOwner = useIsOwner()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommonModal
|
<CommonModal
|
||||||
|
@ -51,7 +53,7 @@ export const DeletionModal: React.FC<PropsWithChildren<DeletionModalProps>> = ({
|
||||||
{...props}>
|
{...props}>
|
||||||
<Modal.Body className='text-dark'>{children}</Modal.Body>
|
<Modal.Body className='text-dark'>{children}</Modal.Body>
|
||||||
<Modal.Footer>
|
<Modal.Footer>
|
||||||
<Button {...cypressId('deletionModal.confirmButton')} variant='danger' onClick={onConfirm}>
|
<Button {...cypressId('deletionModal.confirmButton')} variant='danger' onClick={onConfirm} disabled={!isOwner}>
|
||||||
<Trans i18nKey={deletionButtonI18nKey} />
|
<Trans i18nKey={deletionButtonI18nKey} />
|
||||||
</Button>
|
</Button>
|
||||||
</Modal.Footer>
|
</Modal.Footer>
|
||||||
|
|
Loading…
Reference in a new issue