Skip to content

Commit ee2b22b

Browse files
author
Lucas Araujo
committed
[DDW-942] Added tests
1 parent de90025 commit ee2b22b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from 'react';
2+
import BigNumber from 'bignumber.js';
3+
import { render, screen, cleanup } from '@testing-library/react';
4+
import '@testing-library/jest-dom';
5+
import Asset from './Asset';
6+
import { TestDecorator } from '../../../../../tests/_utils/TestDecorator';
7+
8+
const assets = [
9+
{
10+
policyId: 'policyId',
11+
assetName: '54657374636f696e',
12+
quantity: new BigNumber(1),
13+
fingerprint: 'fingerprint',
14+
metadata: {
15+
name: 'Testcoin',
16+
description: 'Test coin',
17+
},
18+
uniqueId: 'uniqueId',
19+
decimals: 1,
20+
recommendedDecimals: null,
21+
},
22+
{
23+
policyId: 'policyId',
24+
assetName: '436f696e74657374',
25+
quantity: new BigNumber(1),
26+
fingerprint: 'fingerprint',
27+
uniqueId: 'uniqueId',
28+
decimals: 1,
29+
recommendedDecimals: null,
30+
},
31+
{
32+
policyId: 'policyId',
33+
assetName: '',
34+
quantity: new BigNumber(1),
35+
fingerprint: 'fingerprint',
36+
uniqueId: 'uniqueId',
37+
decimals: 1,
38+
recommendedDecimals: null,
39+
},
40+
];
41+
42+
describe('Asset', () => {
43+
afterEach(cleanup);
44+
45+
test('Should display asset metadata name', () => {
46+
render(
47+
<TestDecorator>
48+
<Asset asset={assets[0]} />
49+
</TestDecorator>
50+
);
51+
expect(screen.queryByTestId('assetName')).toHaveTextContent('Testcoin');
52+
});
53+
54+
test('Should display asset ASCII name', () => {
55+
render(
56+
<TestDecorator>
57+
<Asset asset={assets[1]} />
58+
</TestDecorator>
59+
);
60+
expect(screen.queryByTestId('assetName')).toHaveTextContent(
61+
'ASCII: Cointest'
62+
);
63+
});
64+
65+
test('Should display empty name', () => {
66+
render(
67+
<TestDecorator>
68+
<Asset asset={assets[2]} />
69+
</TestDecorator>
70+
);
71+
expect(screen.queryByTestId('assetName')).toBeNull();
72+
});
73+
});

source/renderer/app/components/assets/Asset.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ class Asset extends Component<Props, State> {
181181
assetName,
182182
} = asset;
183183
const hasName = !!metadata?.name;
184-
const name = metadata?.name || `ASCII: ${hexToString(assetName)}`;
184+
const name =
185+
metadata?.name || (assetName && `ASCII: ${hexToString(assetName)}`);
185186
const displayName = metadataNameChars
186187
? ellipsis(name, metadataNameChars)
187188
: name;
@@ -208,6 +209,7 @@ class Asset extends Component<Props, State> {
208209
</div>
209210
{displayName && (
210211
<div
212+
data-testid="assetName"
211213
className={classnames(
212214
styles.metadataName,
213215
!hasName && styles.ascii

0 commit comments

Comments
 (0)