-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(tests): another portion of tests (#959)
- Loading branch information
1 parent
65de702
commit c7e00bb
Showing
19 changed files
with
1,298 additions
and
11 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
11 changes: 11 additions & 0 deletions
11
...ader/components/AccountButton/components/DisconnectButton/tests/DisconnectButton.spec.tsx
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,11 @@ | ||
import { render } from 'jest/testUtils'; | ||
|
||
import { DisconnectButton } from 'astro_2.0/components/AppHeader/components/AccountButton/components/DisconnectButton'; | ||
|
||
describe('DisconnectButton', () => { | ||
it('Should render component', () => { | ||
const { getByText } = render(<DisconnectButton logout={() => 0} />); | ||
|
||
expect(getByText('Disconnect')).toBeTruthy(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
...Header/components/AccountButton/components/MyAccountButton/tests/MyAccountButton.spec.tsx
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,18 @@ | ||
import { render } from 'jest/testUtils'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
|
||
import { MyAccountButton } from 'astro_2.0/components/AppHeader/components/AccountButton/components/MyAccountButton'; | ||
|
||
describe('MyAccountButton', () => { | ||
it('Should handle click properly ', () => { | ||
const closeDropdown = jest.fn(); | ||
|
||
const { getByRole } = render( | ||
<MyAccountButton closeDropdown={closeDropdown} /> | ||
); | ||
|
||
fireEvent.click(getByRole('button')); | ||
|
||
expect(closeDropdown).toBeCalled(); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
....0/components/AppHeader/components/AccountButton/components/WalletButton/WalletButton.tsx
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
21 changes: 21 additions & 0 deletions
21
...ts/AppHeader/components/AccountButton/components/WalletButton/tests/WalletButton.spec.tsx
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,21 @@ | ||
import { render } from 'jest/testUtils'; | ||
|
||
import { WalletButton } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletButton'; | ||
|
||
describe('WalletButton', () => { | ||
it('Should render component', () => { | ||
const name = 'Wallet Name'; | ||
|
||
const { getByText } = render( | ||
<WalletButton | ||
url="" | ||
type="" | ||
name={name} | ||
walletType={0} | ||
onClick={() => 0} | ||
/> | ||
); | ||
|
||
expect(getByText(name)).toBeTruthy(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...er/components/AccountButton/components/WalletDescription/tests/WalletDescription.spec.tsx
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,19 @@ | ||
import { render } from 'jest/testUtils'; | ||
|
||
import { WalletDescription } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletDescription'; | ||
|
||
describe('WalletDescription', () => { | ||
it('Should render component', () => { | ||
const name = 'Wallet name'; | ||
const type = 'Wallet type'; | ||
const url = 'Wallet url'; | ||
|
||
const { getByText } = render( | ||
<WalletDescription name={name} type={type} url={url} /> | ||
); | ||
|
||
expect(getByText(name)).toBeTruthy(); | ||
expect(getByText(type, { exact: false })).toBeTruthy(); | ||
expect(getByText(url)).toBeTruthy(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...onents/AppHeader/components/AccountButton/components/WalletIcon/tests/WalletIcon.spec.tsx
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,37 @@ | ||
import { render } from 'jest/testUtils'; | ||
|
||
import { WalletIcon } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletIcon'; | ||
|
||
jest.mock('astro_2.0/components/NearIcon', () => { | ||
return { | ||
NearIcon: () => <div>NearIcon</div>, | ||
}; | ||
}); | ||
|
||
jest.mock('astro_2.0/components/SenderIcon', () => { | ||
return { | ||
SenderIcon: () => <div>SenderIcon</div>, | ||
}; | ||
}); | ||
|
||
describe('WalletIcon', () => { | ||
it('Should render Near icon', () => { | ||
const { getByText } = render(<WalletIcon walletType={0} isSelected />); | ||
|
||
expect(getByText('NearIcon')).toBeTruthy(); | ||
}); | ||
|
||
it('Should render Sender icon', () => { | ||
const { getByText } = render( | ||
<WalletIcon walletType={1} isSelected={false} /> | ||
); | ||
|
||
expect(getByText('SenderIcon')).toBeTruthy(); | ||
}); | ||
|
||
it('Should render Near icon by default', () => { | ||
const { getByText } = render(<WalletIcon walletType={3} isSelected />); | ||
|
||
expect(getByText('NearIcon')).toBeTruthy(); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...ponents/AccountButton/components/WalletSelectionModal/tests/WalletSelectionModal.spec.tsx
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,36 @@ | ||
import { render } from 'jest/testUtils'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
|
||
import { WalletSelectionModal } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletSelectionModal'; | ||
|
||
jest.mock('components/modal', () => { | ||
return { | ||
Modal: ({ children }: { children: unknown }) => children, | ||
}; | ||
}); | ||
|
||
describe('WalletSelectionModal', () => { | ||
it('Should sign in Near wallet', () => { | ||
const signIn = jest.fn(); | ||
|
||
const { getAllByRole } = render( | ||
<WalletSelectionModal isOpen onClose={() => 0} signIn={signIn} /> | ||
); | ||
|
||
fireEvent.click(getAllByRole('button')[0]); | ||
|
||
expect(signIn).toBeCalledWith(0); | ||
}); | ||
|
||
it('Should sign in Sender wallet', () => { | ||
const signIn = jest.fn(); | ||
|
||
const { getAllByRole } = render( | ||
<WalletSelectionModal isOpen onClose={() => 0} signIn={signIn} /> | ||
); | ||
|
||
fireEvent.click(getAllByRole('button')[2]); | ||
|
||
expect(signIn).toBeCalledWith(1); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
.../components/AccountButton/components/WalletWithAccounts/tests/WalletWithAccounts.spec.tsx
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,39 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
|
||
import { render } from 'jest/testUtils'; | ||
|
||
import { useAuthContext } from 'context/AuthContext'; | ||
|
||
import { WalletWithAccounts } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletWithAccounts'; | ||
|
||
jest.mock('context/AuthContext', () => { | ||
return { | ||
useAuthContext: jest.fn(() => ({})), | ||
}; | ||
}); | ||
|
||
describe('WalletWithAccounts', () => { | ||
it('Should render component', () => { | ||
// @ts-ignore | ||
useAuthContext.mockImplementation(() => ({ | ||
accountId: '1', | ||
})); | ||
|
||
const { getByText } = render( | ||
<WalletWithAccounts | ||
wallet={{ | ||
id: 0, | ||
name: 'NEAR', | ||
type: 'NEAR', | ||
url: 'url', | ||
}} | ||
isSelected | ||
accounts={['2', '1', '3']} | ||
switchAccountHandler={() => () => 0} | ||
switchWalletHandler={() => () => 0} | ||
/> | ||
); | ||
|
||
expect(getByText('NEAR')).toBeTruthy(); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
..._2.0/components/AppHeader/components/AccountButton/components/WalletsList/WalletsList.tsx
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
25 changes: 25 additions & 0 deletions
25
...ents/AppHeader/components/AccountButton/components/WalletsList/tests/WalletsList.spec.tsx
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,25 @@ | ||
import { render } from 'jest/testUtils'; | ||
|
||
import { WalletMeta } from 'services/sputnik/SputnikNearService/services/types'; | ||
import { WalletsList } from 'astro_2.0/components/AppHeader/components/AccountButton/components/WalletsList'; | ||
|
||
describe('WalletsList', () => { | ||
it('Should render component', () => { | ||
const wallets = ([ | ||
{ id: 'NEAR' }, | ||
{ id: 'SENDER' }, | ||
] as unknown) as WalletMeta[]; | ||
|
||
render( | ||
<WalletsList | ||
logoutHandler={() => Promise.resolve()} | ||
availableNearAccounts={[]} | ||
availableWallets={wallets} | ||
selectedWallet={0} | ||
switchAccountHandler={() => () => 0} | ||
switchWalletHandler={() => () => 0} | ||
closeDropdownHandler={() => 0} | ||
/> | ||
); | ||
}); | ||
}); |
Oops, something went wrong.