A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/components/app/flask/snap-settings-card/snap-settings-card.test.js

77 lines
2.8 KiB

Adding SnapSettingsCard ui component (#12655) * parent d89e5336a61e3b4a8838025311c37ba7c003f60e author georgewrmarshall <george.marshall@consensys.net> 1636692862 -0800 committer hmalik88 <hassan.malik@consensys.net> 1637342043 -0500 Initial SnapSettingsCard component Updates to styles but having specificity issues so increased specificity Updates to styles but having specificity issues so increased specificity added overflow fix and added tests lockfile update prettier fix added stylelint ignore yarn.lock fixed * merge conflict fix * package/yarn fix * fixed package.json * updated lockfile... * removed comment * removed unnecessary key/val for chip status indicator color * bumped lattice to 0.4.0 in package json, fixed yarn lock * removed dupe entry in yarn lock * ran yarn setup to update lock file * updated chip label prop * parent d89e5336a61e3b4a8838025311c37ba7c003f60e author georgewrmarshall <george.marshall@consensys.net> 1636692862 -0800 committer hmalik88 <hassan.malik@consensys.net> 1637342043 -0500 Initial SnapSettingsCard component Updates to styles but having specificity issues so increased specificity Updates to styles but having specificity issues so increased specificity added overflow fix and added tests lockfile update prettier fix added stylelint ignore yarn.lock fixed * merge conflict fix * package/yarn fix * fixed package.json * updated lockfile... * removed comment * bumped lattice to 0.4.0 in package json, fixed yarn lock * removed dupe entry in yarn lock * ran yarn setup to update lock file * Using IconWithFallback instead of SiteIcon, fixing icon prop, and adding status story and docs page * Updating to follow storybook folder convention * Updates to styles * Adding localization * added todo comment Co-authored-by: hmalik88 <hassan.malik@consensys.net>
3 years ago
import * as React from 'react';
import { render, fireEvent } from '@testing-library/react';
import SnapSettingsCard from '.';
describe('SnapSettingsCard', () => {
const args = {
name: 'Snap name',
description:
'This snap provides developers everywhere access to an entirely new data storage paradigm, even letting your programs store data autonomously.',
dateAdded: new Date().toDateString(),
version: '10.5.1234',
url: 'https://metamask.io',
status: 'stopped',
icon: './AST.png',
};
it('should render the SnapsSettingCard without crashing', () => {
const { getByText } = render(<SnapSettingsCard {...args} />);
expect(getByText('Snap name')).toBeDefined();
});
it('should render the pill as installing when given a status of installing', () => {
args.status = 'installing';
const { getByText } = render(<SnapSettingsCard {...args} />);
expect(getByText('installing')).toBeDefined();
});
it('should render the pill as running when given a status of running', () => {
args.status = 'running';
const { getByText } = render(<SnapSettingsCard {...args} />);
expect(getByText('running')).toBeDefined();
});
it('should render the pill as installing when given a status of stopped', () => {
args.status = 'stopped';
const { getByText } = render(<SnapSettingsCard {...args} />);
expect(getByText('stopped')).toBeDefined();
});
it('should render the pill as crashed when given a status of crashed', () => {
args.status = 'crashed';
const { getByText } = render(<SnapSettingsCard {...args} />);
expect(getByText('crashed')).toBeDefined();
});
it('should call onToggle prop when toggle button is clicked', () => {
const onToggle = jest.fn();
args.onToggle = onToggle;
const { container } = render(<SnapSettingsCard {...args} />);
const toggleBtn = container.querySelector('.toggle-button').firstChild;
fireEvent.click(toggleBtn);
expect(onToggle).toHaveBeenCalled();
});
it('should call onClick prop when See Details button is clicked', () => {
const onClick = jest.fn();
args.onClick = onClick;
const { container } = render(<SnapSettingsCard {...args} />);
const seeDetailsBtn = container.querySelector(
'.snap-settings-card__button',
);
fireEvent.click(seeDetailsBtn);
expect(onClick).toHaveBeenCalled();
});
it('should render an icon image', () => {
const { getByAltText } = render(<SnapSettingsCard {...args} />);
const image = getByAltText(args.name);
expect(image).toBeDefined();
expect(image).toHaveAttribute('src', args.icon);
});
it('should render the icon fallback using the first letter of the name', () => {
const { getByText } = render(<SnapSettingsCard {...args} icon="" />);
expect(getByText('S')).toBeDefined();
});
});