Skip to content

Commit df3aa76

Browse files
committed
Add Prettier and format code
1 parent b663608 commit df3aa76

File tree

8 files changed

+39
-11
lines changed

8 files changed

+39
-11
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 4,
3+
"printWidth": 80
4+
}

generate-react-cli.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
},
1414
"usesCssModule": true,
1515
"cssPreprocessor": "css"
16-
}
16+
}

src/components/CostDisplay/CostDisplay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const CostDisplay = (
88
) => (
99
<div className={styles.CostDisplay} data-testid="CostDisplay">
1010
{/*display cost display with specified styles*/}
11-
Cost:{" "}
11+
Cost:{' '}
1212
<span id="cost-value">
1313
<NumericDisplay value={cost} />
1414
</span>

src/components/NumericDisplay/NumericDisplay.lazy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { lazy, Suspense } from 'react';
22

33
const LazyNumericDisplay = lazy(() => import('./NumericDisplay'));
44

5-
const NumericDisplay = props => (
5+
const NumericDisplay = (props) => (
66
<Suspense fallback={null}>
77
<LazyNumericDisplay {...props} />
88
</Suspense>

src/components/NumericDisplay/NumericDisplay.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import NumericDisplay from './NumericDisplay';
33

44
export default {
5-
title: "NumericDisplay",
5+
title: 'NumericDisplay',
66
};
77

88
export const Default = () => <NumericDisplay />;

src/components/NumericDisplay/NumericDisplay.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import '@testing-library/jest-dom';
4-
import NumericDisplay from './NumericDisplay';
4+
import NumericDisplay, { formatNumber } from './NumericDisplay';
55

66
describe('<NumericDisplay />', () => {
77
test('it should mount', () => {
@@ -11,4 +11,28 @@ describe('<NumericDisplay />', () => {
1111

1212
expect(numericDisplay).toBeInTheDocument();
1313
});
14+
test('it should format number with default values', () => {
15+
const defaultNumericValue = formatNumber();
16+
expect(defaultNumericValue).toBe('0');
17+
});
18+
test('it should render with large number', () => {
19+
const largeNumericValue = formatNumber(9876);
20+
const bigNumericValue = formatNumber(19283);
21+
const veryLargeNumericValue = formatNumber(7654321);
22+
expect(largeNumericValue).toBe('9.88K');
23+
expect(bigNumericValue).toBe('19.28K');
24+
expect(veryLargeNumericValue).toBe('7.65M');
25+
});
26+
test('it should render with large number without short format', () => {
27+
const largeNumericValue = formatNumber(9876.543, false);
28+
const smallNumericValue = formatNumber(654.321, false);
29+
expect(largeNumericValue).toBe('9877');
30+
expect(smallNumericValue).toBe('654');
31+
});
32+
test('it should render with non-integer number', () => {
33+
const smallDecimalNumericValue = formatNumber(3.456);
34+
const bigDecimalNumericValue = formatNumber(987.65);
35+
expect(smallDecimalNumericValue).toBe('3');
36+
expect(bigDecimalNumericValue).toBe('988');
37+
});
1438
});

src/index.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
body {
22
/*body styles*/
33
margin: 0;
4-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
5-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
6-
sans-serif; /*default computer system font*/
4+
font-family:
5+
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
6+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; /*default computer system font*/
77
-webkit-font-smoothing: antialiased;
88
-moz-osx-font-smoothing: grayscale;
99
}
1010

1111
code {
12-
font-family: 'Source Code Pro', Menlo, Monaco, Consolas, 'Courier New',
13-
monospace; /*set font for code block to monospaced font*/
12+
font-family:
13+
'Source Code Pro', Menlo, Monaco, Consolas, 'Courier New', monospace; /*set font for code block to monospaced font*/
1414
}
1515

1616
table,

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const root = ReactDOM.createRoot(document.getElementById('root'));
88
root.render(
99
<React.StrictMode>
1010
<App />
11-
</React.StrictMode>
11+
</React.StrictMode>,
1212
);
1313

1414
// If you want to start measuring performance in your app, pass a function

0 commit comments

Comments
 (0)