Skip to content

Commit 6aab996

Browse files
renanvalentinLucas Araujo
authored andcommitted
[DDW-839] Discreet mode - automated tests (#2756)
* [DDW-839] Discreet mode integration tests * [DDW-839] Remove aria-query from yarnlock * [DDW-839] Remove istanbul from yarnlock * [DDW-839] Tests for public api * [DDW-839] Run lockfile:fix * [DDW-839] Update changelog
1 parent 20342c7 commit 6aab996

File tree

8 files changed

+385
-47
lines changed

8 files changed

+385
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
### Features
2727

28-
- Implemented "discreet mode" ([PR 2723](https://github.com/input-output-hk/daedalus/pull/2723), [PR 2724](https://github.com/input-output-hk/daedalus/pull/2724), [PR 2725](https://github.com/input-output-hk/daedalus/pull/2725), [PR 2742](https://github.com/input-output-hk/daedalus/pull/2742), [PR 2740](https://github.com/input-output-hk/daedalus/pull/2740))
28+
- Implemented "discreet mode" ([PR 2723](https://github.com/input-output-hk/daedalus/pull/2723), [PR 2724](https://github.com/input-output-hk/daedalus/pull/2724), [PR 2725](https://github.com/input-output-hk/daedalus/pull/2725), [PR 2742](https://github.com/input-output-hk/daedalus/pull/2742), [PR 2740](https://github.com/input-output-hk/daedalus/pull/2740), [PR 2756](https://github.com/input-output-hk/daedalus/pull/2756))
2929
- Implemented "Catalyst Fund7" voting registration changes ([PR 2732](https://github.com/input-output-hk/daedalus/pull/2732))
3030
- Added "Over-saturation" warning in the delegation wizard ([PR 2733](https://github.com/input-output-hk/daedalus/pull/2733), [PR 2738](https://github.com/input-output-hk/daedalus/pull/2738))
3131
- Added Catalyst footer links ([PR 2721](https://github.com/input-output-hk/daedalus/pull/2721))

jest.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ module.exports = {
175175
// timers: "real",
176176

177177
// A map from regular expressions to paths to transformers
178-
// transform: undefined,
178+
transform: {
179+
'\\.[jt]sx?$': 'babel-jest',
180+
'^.+\\.svg$': 'jest-svg-transformer',
181+
'.+\\.(css|styl|less|sass|scss)$': 'jest-css-modules-transform',
182+
},
179183

180184
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
181185
// transformIgnorePatterns: [

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
"@storybook/addons": "5.3.14",
8888
"@storybook/core": "5.3.14",
8989
"@storybook/react": "5.3.14",
90+
"@testing-library/jest-dom": "^5.15.1",
91+
"@testing-library/react": "^12.1.2",
9092
"asar": "2.1.0",
9193
"autodll-webpack-plugin": "0.4.2",
9294
"axios": "0.21.1",
@@ -130,9 +132,11 @@
130132
"hash.js": "1.1.7",
131133
"html-loader": "0.5.5",
132134
"husky": "4.3.0",
135+
"identity-obj-proxy": "3.0.0",
133136
"jest": "26.6.3",
137+
"jest-css-modules-transform": "^4.3.0",
134138
"jest-environment-jsdom": "26.6.2",
135-
"identity-obj-proxy": "3.0.0",
139+
"jest-svg-transformer": "^1.0.0",
136140
"markdown-loader": "5.1.0",
137141
"mini-css-extract-plugin": "0.9.0",
138142
"minimist": "1.2.5",
@@ -279,7 +283,6 @@
279283
"**/**/node-fetch": "2.6.1",
280284
"**/**/mobx-react-lite": "2.2.2",
281285
"**/**/ini": "1.3.8",
282-
"**/**/usb": "1.7.2",
283-
"**/**/istanbul-lib-report": "2.0.8"
286+
"**/**/usb": "1.7.2"
284287
}
285288
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @flow
2+
import React from 'react';
3+
4+
export default function ReactInlineSVG() {
5+
return <svg />;
6+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// @flow
2+
import React, { Component } from 'react';
3+
import type { Node } from 'react';
4+
import { IntlProvider } from 'react-intl';
5+
import BigNumber from 'bignumber.js';
6+
import { observer } from 'mobx-react';
7+
import { render, fireEvent, screen, cleanup } from '@testing-library/react';
8+
import '@testing-library/jest-dom';
9+
10+
import { BrowserLocalStorageBridge } from '../local-storage';
11+
import { DiscreetModeFeatureProvider } from './context';
12+
import {
13+
DiscreetWalletAmount,
14+
DiscreetModeToggle,
15+
DiscreetTokenWalletAmount,
16+
DiscreetValue,
17+
withDiscreetMode,
18+
} from './ui';
19+
import { DiscreetMode } from './feature';
20+
21+
describe('Discreet Mode feature', () => {
22+
afterEach(cleanup);
23+
24+
function TestDecorator({
25+
children,
26+
testId,
27+
}: {
28+
children: Node,
29+
testId: string,
30+
}) {
31+
return (
32+
<IntlProvider locale="en-US">
33+
<BrowserLocalStorageBridge>
34+
<DiscreetModeFeatureProvider>
35+
<>
36+
<DiscreetModeToggle />
37+
38+
<div data-testid={testId}>{children}</div>
39+
</>
40+
</DiscreetModeFeatureProvider>
41+
</BrowserLocalStorageBridge>
42+
</IntlProvider>
43+
);
44+
}
45+
46+
const discreetWalletAmountCases = [
47+
// testId, [amount, currency, withCurrency, long], [expected]
48+
['custom ticker', [new BigNumber(1), 'TEST', true, true], '1.000000 TEST'],
49+
['ada as ticker', [new BigNumber(1), undefined, true, false], '1 ADA'],
50+
['no currency', [new BigNumber(1), 'TEST', false, false], '1'],
51+
];
52+
53+
test.each(discreetWalletAmountCases)(
54+
'<DiscreetWalletAmount /> should replace wallet amount with %s by sensitive data symbol',
55+
async (testId, [amount, currency, withCurrency, long], expected) => {
56+
expect.assertions(2);
57+
58+
render(
59+
<TestDecorator testId={testId}>
60+
<DiscreetWalletAmount
61+
amount={amount}
62+
currency={currency}
63+
withCurrency={withCurrency}
64+
long={long}
65+
/>
66+
</TestDecorator>
67+
);
68+
69+
expect(screen.getByTestId(testId)).toHaveTextContent(expected);
70+
71+
fireEvent.click(
72+
screen.getByRole('button', { name: /discreetModeToggle/i })
73+
);
74+
75+
expect(screen.getByTestId(testId)).toHaveTextContent('***');
76+
}
77+
);
78+
79+
const discreetTokenWalletAmountCases = [
80+
// testId, [amount, metada, decimals], [expected]
81+
['without ticker', [new BigNumber(1), null, 0], '1'],
82+
['with ticker', [new BigNumber(1), { ticker: 'TEST' }, 5], '0.00001 TEST'],
83+
];
84+
85+
test.each(discreetTokenWalletAmountCases)(
86+
'<DiscreetTokenWalletAmount /> should replace token wallet amount with %s by sensitive data symbol',
87+
(testId, [amount, metadata, decimals], expected) => {
88+
expect.assertions(2);
89+
90+
render(
91+
<TestDecorator testId={testId}>
92+
<DiscreetTokenWalletAmount
93+
amount={amount}
94+
metadata={metadata}
95+
decimals={decimals}
96+
/>
97+
</TestDecorator>
98+
);
99+
100+
expect(screen.getByTestId(testId)).toHaveTextContent(expected);
101+
102+
fireEvent.click(
103+
screen.getByRole('button', { name: /discreetModeToggle/i })
104+
);
105+
106+
expect(screen.getByTestId(testId)).toHaveTextContent('***');
107+
}
108+
);
109+
110+
test('<DiscreetValue /> should replace value by sensitive data symbol', () => {
111+
expect.assertions(2);
112+
113+
const value = 'test';
114+
const testId = 'discreet-value';
115+
116+
render(
117+
<TestDecorator testId={testId}>
118+
<DiscreetValue>{value}</DiscreetValue>
119+
</TestDecorator>
120+
);
121+
122+
expect(screen.getByTestId(testId)).toHaveTextContent(value);
123+
124+
fireEvent.click(
125+
screen.getByRole('button', { name: /discreetModeToggle/i })
126+
);
127+
128+
expect(screen.getByTestId(testId)).toHaveTextContent('***');
129+
});
130+
131+
test('<withDiscreetMode /> high order component should replace value by sensitive data symbol', () => {
132+
expect.assertions(2);
133+
134+
const value = 'test';
135+
const testId = 'discreet-value';
136+
const HighOrderComponentApi = withDiscreetMode(
137+
observer(
138+
class View extends Component<{ discreetModeFeature: DiscreetMode }> {
139+
render() {
140+
return this.props.discreetModeFeature.discreetValue({
141+
value,
142+
});
143+
}
144+
}
145+
)
146+
);
147+
148+
render(
149+
<TestDecorator testId={testId}>
150+
<HighOrderComponentApi />
151+
</TestDecorator>
152+
);
153+
154+
expect(screen.getByTestId(testId)).toHaveTextContent(value);
155+
156+
fireEvent.click(
157+
screen.getByRole('button', { name: /discreetModeToggle/i })
158+
);
159+
160+
expect(screen.getByTestId(testId)).toHaveTextContent('***');
161+
});
162+
});

source/renderer/app/features/discreet-mode/ui/discreet-toggle/DiscreetModeToggle.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export const DiscreetModeToggleComponent = ({
1919
onToggle: () => void,
2020
}) => {
2121
return (
22-
<button className={classNames(styles.root, className)} onClick={onToggle}>
22+
<button
23+
className={classNames(styles.root, className)}
24+
onClick={onToggle}
25+
aria-label="discreetModeToggle"
26+
>
2327
<SVGInline
2428
svg={isDiscreetMode ? hideIcon : revealIcon}
2529
className={classNames(styles.icon, isDiscreetMode && styles.hideIcon)}

utils/lockfile-checker/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ lodash.map(json.object, (entry, key) => {
1616
}
1717
});
1818

19-
const dependencyNamesToRemove = ['@types/react-syntax-highlighter', '@types/npmlog', '@types/reactcss', '@types/uglify-js', '@types/parse-json', '@types/html-minifier-terser', '@types/minimist', 'blake2b-wasm@https://github.com/BitGo/blake2b-wasm', 'blake2b@https://github.com/BitGo/blake2b'];
19+
const dependencyNamesToRemove = ['@types/react-syntax-highlighter', '@types/npmlog', '@types/reactcss', '@types/uglify-js', '@types/parse-json', '@types/html-minifier-terser', '@types/minimist', 'blake2b-wasm@https://github.com/BitGo/blake2b-wasm', 'blake2b@https://github.com/BitGo/blake2b', '@types/aria-query', '@types/istanbul-lib-report'];
2020
const dependenciesToRemove = Object.keys(json.object).filter(key => dependencyNamesToRemove.find(name => key.includes(name)));
2121
const affectedDependencies = Object.keys(json.object).filter(key => {
2222
const { dependencies } = json.object[key];

0 commit comments

Comments
 (0)