-
Notifications
You must be signed in to change notification settings - Fork 295
/
SidebarWalletsMenu.spec.tsx
106 lines (95 loc) · 2.96 KB
/
SidebarWalletsMenu.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// @flow
import React from 'react';
import { IntlProvider } from 'react-intl';
import { render, screen, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Provider as MobxProvider } from 'mobx-react';
import translations from '../../../i18n/locales/en-US.json';
import StoryDecorator from '../../../../../../storybook/stories/_support/StoryDecorator';
import {
DiscreetModeFeatureProvider,
BrowserLocalStorageBridge,
} from '../../../features';
import type { SidebarWalletType } from '../../../types/sidebarTypes';
import SidebarWalletsMenu from './SidebarWalletsMenu';
describe('Sidebar Wallets Menu', () => {
afterEach(cleanup);
function TestDecorator({
wallets,
searchValue,
}: {
wallets: Array<SidebarWalletType>,
searchValue: string,
}) {
return (
<StoryDecorator>
<MobxProvider>
<IntlProvider locale="en-US" messages={translations}>
<BrowserLocalStorageBridge>
<DiscreetModeFeatureProvider>
<SidebarWalletsMenu
wallets={wallets}
onAddWallet={jest.fn()}
onWalletItemClick={() => {}}
isActiveWallet={() => false}
isAddWalletButtonActive={false}
isShelleyActivated
visible={false}
searchValue={searchValue}
/>
</DiscreetModeFeatureProvider>
</BrowserLocalStorageBridge>
</IntlProvider>
</MobxProvider>
</StoryDecorator>
);
}
function createWallet() {
let id = 0;
return (title: string): SidebarWalletType => {
id += 1;
return {
id: id.toString(),
title,
amount: 0,
isConnected: false,
isRestoreActive: false,
restoreProgress: 0,
isNotResponding: false,
isLegacy: false,
createdAt: new Date(),
recoveryPhraseVerificationDate: new Date(),
hasNotification: false,
};
};
}
const wallet = createWallet();
const wallets = [
wallet('Loki'),
wallet('Ledger Nano X'),
wallet('Ledger Nano S'),
wallet('Odin'),
wallet('byron'),
wallet('byron new new1'),
];
test.each([
[' ', ['Ledger Nano X', 'Ledger Nano S', 'byron new new1']],
['OKI', ['Loki', 'Odin']],
['byron1111', ['byron', 'byron new new1']],
['brom', ['byron', 'byron new new1']],
['asdf', []],
['legasdf', []],
])(
'<SidebarWalletsMenu /> should filter by %s and display %s',
(searchValue, results) => {
const assertVisibleItems = 1;
const assertSearchResult = results.length;
expect.assertions(assertSearchResult + assertVisibleItems);
render(<TestDecorator wallets={wallets} searchValue={searchValue} />);
results.forEach((r) => expect(screen.queryByTestId(r)).toBeVisible());
expect(screen.queryAllByTestId('walletMenu')).toHaveLength(
assertSearchResult
);
}
);
});