-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
28 additions
and
43 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
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,42 +1,35 @@ | ||
import type { ReactNode } from 'react'; | ||
import { describe, expect, it } from 'vitest'; | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { Avatar } from '../../identity/components/Avatar'; | ||
import { Name } from '../../identity/components/Name'; | ||
import { findComponent } from './findComponent'; | ||
|
||
const ToThe = () => <div>Name Component</div>; | ||
const Moon = () => <div>Age Component</div>; | ||
|
||
describe('findComponent', () => { | ||
it('should find the Name component in the array', () => { | ||
const childrenArray: ReactNode[] = [ | ||
<div key="1">Random div</div>, | ||
<ToThe key="2" />, | ||
<Moon key="3" />, | ||
<Name key="2" address="0x123456789" />, | ||
<Avatar key="3" address="0x123456789" />, | ||
]; | ||
|
||
const foundNameComponent = childrenArray.find(findComponent(ToThe)); | ||
const foundNameComponent = childrenArray.find(findComponent(Name)); | ||
expect(foundNameComponent).toBeDefined(); | ||
expect(foundNameComponent?.type).toBe(ToThe); | ||
expect(foundNameComponent?.type).toBe(Name); | ||
}); | ||
|
||
it('should find the Age component in the array', () => { | ||
it('should find the Avatar component in the array', () => { | ||
const childrenArray: ReactNode[] = [ | ||
<div key="1">Random div</div>, | ||
<ToThe key="2" />, | ||
<Moon key="3" />, | ||
<Name key="2" address="0x123456789" />, | ||
<Avatar key="3" address="0x123456789" />, | ||
]; | ||
|
||
const foundAgeComponent = childrenArray.find(findComponent(Moon)); | ||
const foundAgeComponent = childrenArray.find(findComponent(Avatar)); | ||
expect(foundAgeComponent).toBeDefined(); | ||
expect(foundAgeComponent?.type).toBe(Moon); | ||
expect(foundAgeComponent?.type).toBe(Avatar); | ||
}); | ||
|
||
it('should return undefined if the component is not in the array', () => { | ||
const childrenArray: ReactNode[] = [<div key="1">Random div</div>]; | ||
|
||
const foundNameComponent = childrenArray.find(findComponent(ToThe)); | ||
const foundNameComponent = childrenArray.find(findComponent(Name)); | ||
expect(foundNameComponent).toBeUndefined(); | ||
}); | ||
}); |
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
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