123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import {Fragment} from 'react';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {textWithMarkupMatcher} from 'sentry-test/utils';
- import GlobalModal from 'sentry/components/globalModal';
- import {DataScrubbing} from 'sentry/views/settings/components/dataScrubbing';
- const relayPiiConfig = JSON.stringify(TestStubs.DataScrubbingRelayPiiConfig());
- describe('Data Scrubbing', function () {
- describe('Organization level', function () {
- const {organization} = initializeOrg();
- const additionalContext = 'These rules can be configured for each project.';
- const endpoint = `organization/${organization.slug}/`;
- it('default render', function () {
- render(
- <DataScrubbing
- additionalContext={additionalContext}
- endpoint={endpoint}
- relayPiiConfig={relayPiiConfig}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- />
- );
- // Header
- expect(screen.getByText('Advanced Data Scrubbing')).toBeInTheDocument();
- // Alert
- expect(
- screen.getByText(
- textWithMarkupMatcher(
- `${additionalContext} The new rules will only apply to upcoming events. For more details, see full documentation on data scrubbing.`
- )
- )
- ).toBeInTheDocument();
- expect(
- screen.getByRole('link', {name: 'full documentation on data scrubbing'})
- ).toHaveAttribute(
- 'href',
- `https://docs.sentry.io/product/data-management-settings/scrubbing/advanced-datascrubbing/`
- );
- // Body
- expect(screen.getAllByRole('button', {name: 'Edit Rule'})).toHaveLength(3);
- // Actions
- expect(screen.getByRole('button', {name: 'Read Docs'})).toHaveAttribute(
- 'href',
- `https://docs.sentry.io/product/data-management-settings/scrubbing/advanced-datascrubbing/`
- );
- expect(screen.getByRole('button', {name: 'Add Rule'})).toBeEnabled();
- });
- it('render empty state', function () {
- render(
- <DataScrubbing
- endpoint={endpoint}
- relayPiiConfig={undefined}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- />
- );
- expect(screen.getByText('You have no data scrubbing rules')).toBeInTheDocument();
- });
- it('render disabled actions', function () {
- render(
- <DataScrubbing
- additionalContext={additionalContext}
- endpoint={endpoint}
- relayPiiConfig={relayPiiConfig}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- disabled
- />
- );
- // Read Docs is the only enabled action
- expect(screen.getByRole('button', {name: 'Read Docs'})).toBeEnabled();
- expect(screen.getByRole('button', {name: 'Add Rule'})).toBeDisabled();
- for (const index in JSON.parse(relayPiiConfig).rules) {
- expect(screen.getAllByRole('button', {name: 'Edit Rule'})[index]).toBeDisabled();
- expect(
- screen.getAllByRole('button', {name: 'Delete Rule'})[index]
- ).toBeDisabled();
- }
- });
- });
- describe('Project level', function () {
- it('default render', function () {
- const {organization, project} = initializeOrg();
- render(
- <DataScrubbing
- endpoint={`/projects/${organization.slug}/foo/`}
- relayPiiConfig={relayPiiConfig}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- project={project}
- />
- );
- // Header
- expect(
- screen.getByText('There are no data scrubbing rules at the organization level')
- ).toBeInTheDocument();
- });
- it('OrganizationRules has content', function () {
- const {organization, project} = initializeOrg({
- ...initializeOrg(),
- organization: {
- ...initializeOrg().organization,
- relayPiiConfig,
- },
- });
- render(
- <DataScrubbing
- endpoint={`/projects/${organization.slug}/foo/`}
- relayPiiConfig={relayPiiConfig}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- project={project}
- />,
- {organization}
- );
- // Organization Rules
- expect(screen.getByText('Organization Rules')).toBeInTheDocument();
- });
- it('Delete rule successfully', async function () {
- const {organization, project} = initializeOrg();
- render(
- <Fragment>
- <GlobalModal />
- <DataScrubbing
- endpoint={`/projects/${organization.slug}/foo/`}
- project={project}
- relayPiiConfig={relayPiiConfig}
- disabled={false}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- />
- </Fragment>
- );
- userEvent.click(screen.getAllByLabelText('Delete Rule')[0]);
- expect(
- await screen.findByText('Are you sure you wish to delete this rule?')
- ).toBeInTheDocument();
- });
- it('Open Add Rule Modal', async function () {
- const {organization, project} = initializeOrg();
- render(
- <Fragment>
- <GlobalModal />
- <DataScrubbing
- endpoint={`/projects/${organization.slug}/foo/`}
- project={project}
- relayPiiConfig={relayPiiConfig}
- disabled={false}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- />
- </Fragment>
- );
- userEvent.click(screen.getByRole('button', {name: 'Add Rule'}));
- expect(
- await screen.findByText('Add an advanced data scrubbing rule')
- ).toBeInTheDocument();
- });
- it('Open Edit Rule Modal', function () {
- const {organization, router, project} = initializeOrg();
- render(
- <Fragment>
- <GlobalModal />
- <DataScrubbing
- endpoint={`/projects/${organization.slug}/foo/`}
- project={project}
- relayPiiConfig={relayPiiConfig}
- disabled={false}
- organization={organization}
- onSubmitSuccess={jest.fn()}
- />
- </Fragment>,
- {router}
- );
- userEvent.click(screen.getAllByRole('button', {name: 'Edit Rule'})[0]);
- // Verify the router to open the modal was called
- expect(router.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: `/settings/${organization.slug}/projects/${project.slug}/security-and-privacy/advanced-data-scrubbing/0/`,
- })
- );
- });
- });
- });
|