Skip to content

Commit

Permalink
addressing review comments - updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiranjanaBinoy committed Sep 20, 2024
1 parent f0083a1 commit ef54c5c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 20 deletions.
6 changes: 1 addition & 5 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"cdn.segment.io",
"cdnjs.cloudflare.com",
"chainid.network",
"client-side-detection.api.cx.metamask.io",
"configuration.dev.metamask-institutional.io",
"configuration.metamask-institutional.io",
"connect.trezor.io",
Expand Down Expand Up @@ -56,11 +57,6 @@
"tokens.api.cx.metamask.io",
"tx-sentinel-ethereum-mainnet.api.cx.metamask.io",
"unresponsive-rpc.test",
"authentication.api.cx.metamask.io",
"oidc.api.cx.metamask.io",
"price.api.cx.metamask.io",
"token.api.cx.metamask.io",
"client-side-detection.api.cx.metamask.io",
"unresponsive-rpc.url",
"www.4byte.directory"
]
22 changes: 10 additions & 12 deletions test/e2e/tests/metrics/delete-metametrics-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import FixtureBuilder from '../../fixture-builder';
import { Driver } from '../../webdriver/driver';
import { TestSuiteArguments } from '../confirmations/transactions/shared';
import { WebElementWithWaitForElementState } from '../../webdriver/types';

const selectors = {
accountOptionsMenuButton: '[data-testid="account-options-menu-button"]',
Expand Down Expand Up @@ -121,10 +122,9 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButton = await driver.findElement(
selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButton as any).waitForElementState(
'disabled',
);
await (
deleteMetaMetricsDataButton as WebElementWithWaitForElementState
).waitForElementState('disabled');
assert.equal(
await deleteMetaMetricsDataButton.isEnabled(),
false,
Expand Down Expand Up @@ -195,10 +195,9 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButton = await driver.findElement(
selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButton as any).waitForElementState(
'disabled',
);
await (
deleteMetaMetricsDataButton as WebElementWithWaitForElementState
).waitForElementState('disabled');
assert.equal(
await deleteMetaMetricsDataButton.isEnabled(),
false,
Expand All @@ -221,10 +220,9 @@ describe('Delete MetaMetrics Data @no-mmi', function (this: Suite) {
const deleteMetaMetricsDataButtonRefreshed = await driver.findElement(
selectors.deleteMetaMetricsDataButton,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (deleteMetaMetricsDataButtonRefreshed as any).waitForElementState(
'disabled',
);
await (
deleteMetaMetricsDataButtonRefreshed as WebElementWithWaitForElementState
).waitForElementState('disabled');
assert.equal(
await deleteMetaMetricsDataButtonRefreshed.isEnabled(),
false,
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/webdriver/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WebElement, WebElementPromise } from 'selenium-webdriver';

export type WebElementWithWaitForElementState = WebElement & {
waitForElementState: (state: unknown, timeout?: unknown) => WebElementPromise;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import * as React from 'react';
import { fireEvent } from '@testing-library/react';
import configureStore from '../../../store/store';
import { renderWithProvider } from '../../../../test/lib/render-helpers';

import * as Actions from '../../../store/actions';
import { DELETE_METAMETRICS_DATA_MODAL_CLOSE } from '../../../store/actionConstants';
import ClearMetaMetricsData from './clear-metametrics-data';

const mockCloseDeleteMetaMetricsDataModal = jest.fn().mockImplementation(() => {
return {
type: DELETE_METAMETRICS_DATA_MODAL_CLOSE,
};
});

jest.mock('../../../store/actions', () => ({
createMetaMetricsDataDeletionTask: jest.fn(),
}));

jest.mock('../../../ducks/app/app.ts', () => {
return {
hideDeleteMetaMetricsDataModal: () => {
return mockCloseDeleteMetaMetricsDataModal();
},
};
});

describe('ClearMetaMetricsData', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should render the data deletion error modal', async () => {
const store = configureStore({});
const { getByText } = renderWithProvider(<ClearMetaMetricsData />, store);
Expand All @@ -16,4 +40,20 @@ describe('ClearMetaMetricsData', () => {
),
).toBeInTheDocument();
});

it('should call createMetaMetricsDataDeletionTask when Clear button is clicked', () => {
const store = configureStore({});
const { getByText } = renderWithProvider(<ClearMetaMetricsData />, store);
expect(getByText('Clear')).toBeEnabled();
fireEvent.click(getByText('Clear'));
expect(Actions.createMetaMetricsDataDeletionTask).toHaveBeenCalledTimes(1);
});

it('should call hideDeleteMetaMetricsDataModal when Cancel button is clicked', () => {
const store = configureStore({});
const { getByText } = renderWithProvider(<ClearMetaMetricsData />, store);
expect(getByText('Cancel')).toBeEnabled();
fireEvent.click(getByText('Cancel'));
expect(mockCloseDeleteMetaMetricsDataModal).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function ClearMetaMetricsData() {
{t('cancel')}
</Button>
<Button
data-testid="clear-metametrics-data"
size={ButtonSize.Lg}
width={BlockSize.Half}
variant={ButtonVariant.Primary}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import * as React from 'react';
import { fireEvent } from '@testing-library/react';
import configureStore from '../../../store/store';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { DATA_DELETION_ERROR_MODAL_CLOSE } from '../../../store/actionConstants';

import DataDeletionErrorModal from './data-deletion-error-modal';

const mockCloseDeleteMetaMetricsErrorModal = jest
.fn()
.mockImplementation(() => {
return {
type: DATA_DELETION_ERROR_MODAL_CLOSE,
};
});

jest.mock('../../../ducks/app/app.ts', () => {
return {
hideDataDeletionErrorModal: () => {
return mockCloseDeleteMetaMetricsErrorModal();
},
};
});

describe('DataDeletionErrorModal', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should render data deletion error modal', async () => {
const store = configureStore({});
const { getByText } = renderWithProvider(<DataDeletionErrorModal />, store);
Expand All @@ -18,4 +40,12 @@ describe('DataDeletionErrorModal', () => {
),
).toBeInTheDocument();
});

it('should call hideDeleteMetaMetricsDataModal when Ok button is clicked', () => {
const store = configureStore({});
const { getByText } = renderWithProvider(<DataDeletionErrorModal />, store);
expect(getByText('Ok')).toBeEnabled();
fireEvent.click(getByText('Ok'));
expect(mockCloseDeleteMetaMetricsErrorModal).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import { DeleteRegulationStatus } from '../../../../../shared/constants/metametr
const DeleteMetaMetricsDataButton = ({
wrapperRef,
}: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
wrapperRef?: PolymorphicRef<any>;
wrapperRef?: PolymorphicRef<React.ElementType>;
}) => {
const t = useI18nContext();
const dispatch = useDispatch();
Expand Down

0 comments on commit ef54c5c

Please sign in to comment.