-
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.
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.
- Loading branch information
Showing
5 changed files
with
130 additions
and
26 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,38 @@ | ||
import { shallow, mount } from 'enzyme'; | ||
|
||
const SHALLOW_WRAPPER_CONSTRUCTOR = 'ShallowWrapper'; | ||
|
||
function isShallowWrapper(wrapper) { | ||
return wrapper.constructor.name === undefined | ||
? Boolean(`${wrapper.constructor}`.match(/^function ShallowWrapper\(/u)) | ||
: wrapper.constructor.name === SHALLOW_WRAPPER_CONSTRUCTOR; | ||
} | ||
|
||
function toMatchElement( | ||
actualEnzymeWrapper, | ||
reactInstance, | ||
options = { ignoreProps: true }, | ||
) { | ||
let expectedWrapper; | ||
if (isShallowWrapper(actualEnzymeWrapper)) { | ||
expectedWrapper = shallow(reactInstance); | ||
} else { | ||
expectedWrapper = mount(reactInstance); | ||
} | ||
|
||
const actual = actualEnzymeWrapper.debug({ verbose: true, ...options }); | ||
const expected = expectedWrapper.debug({ verbose: true, ...options }); | ||
const pass = actual === expected; | ||
|
||
return { | ||
pass, | ||
message: 'Expected actual value to match the expected value.', | ||
negatedMessage: 'Did not expect actual value to match the expected value.', | ||
contextualInformation: { | ||
actual: `Actual:\n ${actual}`, | ||
expected: `Expected:\n ${expected}`, | ||
}, | ||
}; | ||
} | ||
|
||
expect.extend({ toMatchElement }); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// This file is for Jest-specific setup only and runs before our Jest tests. | ||
import '@testing-library/jest-dom'; | ||
import './matchers'; |
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,60 @@ | ||
import React from 'react'; | ||
import { shallowWithContext } from '../../../../test/lib/render-helpers'; | ||
import RecipientGroup from './recipient-group'; | ||
import ContactList from '.'; | ||
|
||
describe('Contact List', () => { | ||
describe('given searchForContacts', () => { | ||
it('sorts contacts by name within each letter group', () => { | ||
const contacts = { | ||
Al: { name: 'Al', address: '0x0' }, | ||
aa: { name: 'aa', address: '0x1' }, | ||
Az: { name: 'Az', address: '0x2' }, | ||
Bl: { name: 'Bl', address: '0x3' }, | ||
ba: { name: 'ba', address: '0x4' }, | ||
Bz: { name: 'Bz', address: '0x5' }, | ||
Ccc: { name: 'Ccc', address: '0x6' }, | ||
}; | ||
const searchForContacts = () => { | ||
return Object.values(contacts); | ||
}; | ||
const selectRecipient = () => null; | ||
const selectedAddress = null; | ||
|
||
const wrapper = shallowWithContext( | ||
<ContactList | ||
searchForContacts={searchForContacts} | ||
selectRecipient={selectRecipient} | ||
selectedAddress={selectedAddress} | ||
/>, | ||
); | ||
|
||
expect(wrapper).toMatchElement( | ||
<div className="send__select-recipient-wrapper__list"> | ||
<RecipientGroup | ||
key="A-contact-group" | ||
label="A" | ||
items={[contacts.aa, contacts.Al, contacts.Az]} | ||
onSelect={selectRecipient} | ||
selectedAddress={selectedAddress} | ||
/> | ||
<RecipientGroup | ||
key="B-contact-group" | ||
label="B" | ||
items={[contacts.ba, contacts.Bl, contacts.Bz]} | ||
onSelect={selectRecipient} | ||
selectedAddress={selectedAddress} | ||
/> | ||
<RecipientGroup | ||
key="C-contact-group" | ||
label="C" | ||
items={[contacts.Ccc]} | ||
onSelect={selectRecipient} | ||
selectedAddress={selectedAddress} | ||
/> | ||
</div>, | ||
{ ignoreProps: false }, | ||
); | ||
}); | ||
}); | ||
}); |