Skip to content

Commit 1012115

Browse files
committed
tests: update unit tests and stories
1 parent b19c6c5 commit 1012115

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

app/src/__stories__/SettingsPage.stories.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { useStore } from 'store';
23
import { Layout } from 'components/layout';
34
import SettingsPage from 'components/settings/SettingsPage';
45

@@ -12,6 +13,18 @@ export const Default = () => {
1213
return <SettingsPage />;
1314
};
1415

16+
export const BitcoinUnit = () => {
17+
const { uiStore } = useStore();
18+
uiStore.selectedSetting = 'unit';
19+
return <SettingsPage />;
20+
};
21+
22+
export const BalanceMode = () => {
23+
const { uiStore } = useStore();
24+
uiStore.selectedSetting = 'balance';
25+
return <SettingsPage />;
26+
};
27+
1528
export const InsideLayout = () => {
1629
return (
1730
<Layout>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import { fireEvent } from '@testing-library/react';
3+
import { renderWithProviders } from 'util/tests';
4+
import Checkbox from 'components/common/Checkbox';
5+
6+
describe('Checkbox component', () => {
7+
const handleChange = jest.fn();
8+
9+
const render = (checked?: boolean, disabled?: boolean) => {
10+
const cmp = (
11+
<Checkbox checked={checked} disabled={disabled} onChange={handleChange} />
12+
);
13+
return renderWithProviders(cmp);
14+
};
15+
16+
it('should display checked', () => {
17+
const { getByText } = render(true);
18+
expect(getByText('check.svg')).toBeInTheDocument();
19+
});
20+
21+
it('should display unchecked', () => {
22+
const { queryByText } = render(false);
23+
expect(queryByText('check.svg')).not.toBeInTheDocument();
24+
});
25+
26+
it('should trigger onChange event', () => {
27+
const { getByText } = render(true);
28+
fireEvent.click(getByText('check.svg'));
29+
expect(handleChange).toBeCalledWith(false);
30+
});
31+
});

app/src/__tests__/store/buildSwapStore.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import { grpc } from '@improbable-eng/grpc-web';
33
import { waitFor } from '@testing-library/react';
44
import * as config from 'config';
55
import { injectIntoGrpcUnary } from 'util/tests';
6-
import { BuildSwapStore, createStore } from 'store';
6+
import { BuildSwapStore, createStore, Store } from 'store';
77
import { SWAP_ABORT_DELAY } from 'store/stores/buildSwapStore';
88

99
const grpcMock = grpc as jest.Mocked<typeof grpc>;
1010

1111
describe('BuildSwapStore', () => {
12+
let rootStore: Store;
1213
let store: BuildSwapStore;
1314

1415
beforeEach(async () => {
15-
const rootStore = createStore();
16+
rootStore = createStore();
1617
await rootStore.init();
1718
store = rootStore.buildSwapStore;
1819
});
@@ -25,6 +26,14 @@ describe('BuildSwapStore', () => {
2526
expect(store.selectedChanIds).toHaveLength(0);
2627
});
2728

29+
it('should infer the swap direction based on the selected channels', () => {
30+
const channels = rootStore.channelStore.sortedChannels;
31+
store.toggleSelectedChannel(channels[0].chanId);
32+
expect(store.inferredDirection).toEqual(SwapDirection.OUT);
33+
store.toggleSelectedChannel(channels[channels.length - 1].chanId);
34+
expect(store.inferredDirection).toEqual(SwapDirection.IN);
35+
});
36+
2837
it('should fetch loop terms', async () => {
2938
expect(store.terms.in).toEqual({ min: 0, max: 0 });
3039
expect(store.terms.out).toEqual({ min: 0, max: 0 });

0 commit comments

Comments
 (0)