fix: anon cannot request data removal

This commit is contained in:
Pavel Mineev
2022-08-22 11:42:15 -07:00
committed by Paul Mineev
parent d6b2960a4a
commit dc048ef047
4 changed files with 18 additions and 3 deletions
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { waitFor, fireEvent } from '@testing-library/preact';
import { waitFor, fireEvent, screen } from '@testing-library/preact';
import { render } from 'tests/utils';
import * as api from 'common/api';
@@ -190,4 +190,15 @@ describe('<Profile />', () => {
fireEvent.click(await findByRole('button', { name: /load more/i }));
expect(queryByTestId('preloader')).not.toBeInTheDocument();
});
it('should not render removal button for anonymous user', async () => {
jest
.spyOn(api, 'getUserComments')
.mockImplementation(async () => ({ comments: new Array(10).fill(commentStub), count: 15 }));
jest.spyOn(pq, 'parseQuery').mockImplementation(() => ({ ...userParamsStub, name: 'anonymous_1' }));
render(<Profile />);
expect(screen.queryByText(/request my data removal/i)).not.toBeInTheDocument();
});
});
@@ -8,6 +8,7 @@ import { parseQuery } from 'utils/parse-query';
import { requestDeletion } from 'utils/email';
import { setStyles } from 'utils/set-dom-props';
import { Avatar } from 'components/avatar';
import { isUserAnonymous } from 'utils/isUserAnonymous';
import { postMessageToParent } from 'utils/post-message';
import { Comment } from 'components/comment';
import { Preloader } from 'components/preloader';
@@ -18,7 +19,7 @@ import { CrossIcon } from 'components/icons/cross';
import { IconButton } from 'components/icon-button/icon-button';
import { Button } from 'components/auth/components/button';
import { messages as authMessages } from 'components/auth/auth.messsages';
import type { Comment as CommentType, Theme } from 'common/types';
import type { Comment as CommentType, Theme, User } from 'common/types';
import styles from './profile.module.css';
import { Counter } from './components/counter';
@@ -219,7 +220,7 @@ export function Profile() {
{comments === null && isCommentsLoading && <Preloader className={styles.preloader} />}
{comments !== null && commentsJSX}
</section>
{isCurrent ? (
{isCurrent && !isUserAnonymous(user as unknown as User) ? (
<footer className={clsx('profile-footer', styles.footer)}>
<Button kind="hollow" size="sm" onClick={handleClickRequestRemoveData}>
<FormattedMessage id="profile.request-to-delete-data" defaultMessage="Request my data removal" />
+1
View File
@@ -51,6 +51,7 @@
"@formatjs/cli": "^5.0.2",
"@mavrin/stylelint-declaration-use-css-custom-properties": "^2.0.0",
"@prefresh/babel-plugin": "^0.4.3",
"@prefresh/core": "^1.3.4",
"@prefresh/webpack": "^3.3.4",
"@size-limit/file": "^7.0.8",
"@swc/core": "1.2.205",
+2
View File
@@ -24,6 +24,7 @@ importers:
'@github/text-expander-element': ^2.2.2
'@mavrin/stylelint-declaration-use-css-custom-properties': ^2.0.0
'@prefresh/babel-plugin': ^0.4.3
'@prefresh/core': ^1.3.4
'@prefresh/webpack': ^3.3.4
'@size-limit/file': ^7.0.8
'@swc/core': 1.2.205
@@ -137,6 +138,7 @@ importers:
'@formatjs/cli': 5.0.2
'@mavrin/stylelint-declaration-use-css-custom-properties': 2.0.0_stylelint@14.9.1
'@prefresh/babel-plugin': 0.4.3
'@prefresh/core': 1.3.4_preact@10.6.2
'@prefresh/webpack': 3.3.4_aygq4fhb36ivjwsmiykvhlqsje
'@size-limit/file': 7.0.8_size-limit@7.0.8
'@swc/core': 1.2.205