-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
95 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters