1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/ui/pages/settings/settings-tab/settings-tab.test.js
Thomas Huang 119219b5d2
Continue converting tests from enzyme to @testing-library/react (#16458)
* Add transaction activity log component

* Remove duplicate tx activity log snapshot.

* Convert Advanced Tab to tlr.

* Lint fix

* Convert Settings Tab test to tlr.

* Convert Send Amount Row test to tlr.

* Convert Send Row Error Message test to tlr.

* Add Mock Send State json file.

* Lint fix

* Use proper testid for jazz icon for settings e2e

* Update Send Amount Row snapshot
2022-11-29 07:42:59 -08:00

96 lines
2.9 KiB
JavaScript

import React from 'react';
import { fireEvent } from '@testing-library/react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import mockState from '../../../../test/data/mock-state.json';
import SettingsTab from '.';
import 'jest-canvas-mock';
const mockSetCurrentCurrency = jest.fn();
const mockUpdateCurrentLocale = jest.fn();
const mockSetUseNativeCurrencyAsPrimaryCurrencyPreference = jest.fn();
const mockSetUseBlockie = jest.fn();
const mockSetHideZeroBalanceTokens = jest.fn();
jest.mock('../../../store/actions.js', () => ({
setCurrentCurrency: () => mockSetCurrentCurrency,
updateCurrentLocale: () => mockUpdateCurrentLocale,
setUseNativeCurrencyAsPrimaryCurrencyPreference: () =>
mockSetUseNativeCurrencyAsPrimaryCurrencyPreference,
setUseBlockie: () => mockSetUseBlockie,
setHideZeroBalanceTokens: () => mockSetHideZeroBalanceTokens,
}));
describe('Settings Tab', () => {
const mockStore = configureMockStore([thunk])(mockState);
afterEach(() => {
mockSetCurrentCurrency.mockReset();
mockUpdateCurrentLocale.mockReset();
mockSetUseNativeCurrencyAsPrimaryCurrencyPreference.mockReset();
});
it('selects currency', async () => {
const { queryByTestId } = renderWithProvider(<SettingsTab />, mockStore);
fireEvent.change(queryByTestId('currency-select'), {
target: { value: 'eur' },
});
expect(mockSetCurrentCurrency).toHaveBeenCalled();
});
it('selects locale', async () => {
const { queryByTestId } = renderWithProvider(<SettingsTab />, mockStore);
fireEvent.change(queryByTestId('locale-select'), {
target: { value: 'ja' },
});
expect(mockUpdateCurrentLocale).toHaveBeenCalled();
});
it('sets fiat primary currency', async () => {
const { queryByTestId } = renderWithProvider(<SettingsTab />, mockStore);
const fiatCurrencyToggle = queryByTestId('toggle-fiat-currency');
fireEvent.click(fiatCurrencyToggle);
expect(
mockSetUseNativeCurrencyAsPrimaryCurrencyPreference,
).toHaveBeenCalled();
});
it('clicks jazzicon', () => {
const { queryByTestId } = renderWithProvider(<SettingsTab />, mockStore);
const jazziconToggle = queryByTestId('jazz_icon');
fireEvent.click(jazziconToggle);
expect(mockSetUseBlockie).toHaveBeenCalled();
});
it('clicks blockies icon', () => {
const { queryByTestId } = renderWithProvider(<SettingsTab />, mockStore);
const blockieToggle = queryByTestId('blockie_icon');
fireEvent.click(blockieToggle);
expect(mockSetUseBlockie).toHaveBeenCalled();
});
it('toggles hiding zero balance', () => {
const { getByRole } = renderWithProvider(<SettingsTab />, mockStore);
const hideZerBalanceTokens = getByRole('checkbox');
fireEvent.click(hideZerBalanceTokens);
expect(mockSetHideZeroBalanceTokens).toHaveBeenCalled();
});
});