1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/components/app/contact-list/contact-list.test.js
Elliot Winkler 49e1abc374
Sort contacts alphabetically (#11982)
* Sort contacts alphabetically

Contacts are grouped together by letter, and the groups are listed
alphabetically, but the contacts in each group are not sorted
alphabetically themselves.

Fixes #10318.

* Improve tests to be less brittle

* Remove this matcher

* Revert this file

* Also don't need this change anymore

* Don't need this data attribute either
2021-09-03 12:31:12 -07:00

59 lines
2.0 KiB
JavaScript

import React from 'react';
import { within } from '@testing-library/react';
import configureMockStore from 'redux-mock-store';
import { renderWithProvider } from '../../../../test/jest/rendering';
import ContactList from '.';
describe('Contact List', () => {
const store = configureMockStore([])({ metamask: {} });
describe('given searchForContacts', () => {
const selectRecipient = () => null;
const selectedAddress = null;
it('sorts contacts by name within each letter group', () => {
const { getAllByTestId } = renderWithProvider(
<ContactList
searchForContacts={() => {
return [
{
name: 'Al',
address: '0x0000000000000000000000000000000000000000',
},
{
name: 'aa',
address: '0x0000000000000000000000000000000000000001',
},
{
name: 'Az',
address: '0x0000000000000000000000000000000000000002',
},
{
name: 'bbb',
address: '0x0000000000000000000000000000000000000003',
},
];
}}
selectRecipient={selectRecipient}
selectedAddress={selectedAddress}
/>,
store,
);
const recipientGroups = getAllByTestId('recipient-group');
expect(within(recipientGroups[0]).getByText('A')).toBeInTheDocument();
const recipientsInA = within(recipientGroups[0]).getAllByTestId(
'recipient',
);
expect(recipientsInA[0]).toHaveTextContent('aa0x0000...0001');
expect(recipientsInA[1]).toHaveTextContent('Al0x0000...0000');
expect(recipientsInA[2]).toHaveTextContent('Az0x0000...0002');
expect(within(recipientGroups[1]).getByText('B')).toBeInTheDocument();
const recipientsInB = within(recipientGroups[1]).getAllByTestId(
'recipient',
);
expect(recipientsInB[0]).toHaveTextContent('bbb0x0000...0003');
});
});
});