Skip to content

Commit d0bad7e

Browse files
committed
2.0.0
* Adding more tests * Tweaking pika build * Bumping deps * Adding .vscode settings/config
1 parent 23f700c commit d0bad7e

File tree

12 files changed

+192
-29
lines changed

12 files changed

+192
-29
lines changed

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Jest All",
8+
"program": "${workspaceFolder}/node_modules/.bin/jest",
9+
"args": ["--runInBand"],
10+
"console": "integratedTerminal",
11+
"internalConsoleOptions": "neverOpen",
12+
"disableOptimisticBPs": true,
13+
"windows": {
14+
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
15+
}
16+
},
17+
{
18+
"type": "node",
19+
"request": "launch",
20+
"name": "Jest Current File",
21+
"program": "${workspaceFolder}/node_modules/.bin/jest",
22+
"args": ["${relativeFile}", "--config", "jest.config.js", "--collectCoverage=false"],
23+
"console": "integratedTerminal",
24+
"internalConsoleOptions": "neverOpen",
25+
"disableOptimisticBPs": true,
26+
"windows": {
27+
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
28+
}
29+
}
30+
]
31+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"typescript.updateImportsOnFileMove.enabled": "always",
3+
"eslint.validate": [
4+
"javascript",
5+
"javascriptreact",
6+
"typescript",
7+
"typescriptreact"
8+
]
9+
}

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"lint": "eslint \"src/**/*.{ts,tsx}\"",
2222
"test": "jest --silent",
2323
"clean": "rimraf pkg/**",
24-
"build": "npm-run-all --parallel ts-check lint clean && pika build",
24+
"build": "npm-run-all --parallel ts-check lint clean test && pika build",
2525
"ts-check": "tsc --noEmit",
26-
"version": "npm-run-all test build"
26+
"version": "npm-run-all lint test build"
2727
},
2828
"repository": {
2929
"type": "git",
@@ -56,6 +56,7 @@
5656
"pika-plugin-legacy-browser",
5757
{
5858
"name": "PrettyCheckboxReact",
59+
"format": "umd",
5960
"minify": true,
6061
"external": [
6162
"react"
@@ -87,7 +88,7 @@
8788
"@testing-library/react": "^9.4.0",
8889
"@testing-library/react-hooks": "^3.2.1",
8990
"@types/classnames": "^2.2.9",
90-
"@types/jest": "^25.1.1",
91+
"@types/jest": "^25.1.2",
9192
"@types/nanoid": "^2.1.0",
9293
"@types/react": "^16.9.19",
9394
"coveralls": "^3.0.9",
@@ -105,8 +106,8 @@
105106
"react-dom": "^16.12.0",
106107
"react-test-renderer": "^16.12.0",
107108
"react-ts-docgen": "^1.0.1",
108-
"rimraf": "^3.0.1",
109-
"ts-jest": "^25.1.0",
109+
"rimraf": "^3.0.2",
110+
"ts-jest": "^25.2.0",
110111
"typescript": "^3.7.5"
111112
},
112113
"dependencies": {

src/components/Radio.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ export const useRadioState = ({ state: initialState = false }: { state?: RadioSt
1818
setState,
1919
onChange: React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
2020
const value = e.currentTarget.value;
21-
22-
setState(prev => {
23-
// (isBoolean(prev) ? !prev : value)
24-
if (isBoolean(prev)) {
25-
return !prev;
26-
}
27-
28-
return value;
29-
});
21+
setState(prev => (isBoolean(prev) ? !prev : value));
3022
}, []),
3123
...useUUID(),
3224
};

src/components/__tests__/Checkbox.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,19 @@ describe('Checkbox tests', () => {
88
render(<Checkbox state={false} onChange={jest.fn()} />).container;
99
}).not.toThrow();
1010
});
11+
12+
it('should allow users to supply custom values', () => {
13+
const { container } = render(
14+
<Checkbox state={false} onChange={jest.fn()} value="apples" />
15+
);
16+
17+
// @ts-ignore
18+
expect(container.querySelector('input').getAttribute('value')).toEqual('apples');
19+
});
20+
21+
it('should match the snapshot', () => {
22+
expect(
23+
render(<Checkbox state={false} onChange={jest.fn()} value="apples" />).container
24+
).toMatchSnapshot();
25+
});
1126
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Checkbox tests should match the snapshot 1`] = `
4+
<div>
5+
<div
6+
aria-checked="false"
7+
class="pretty p-default"
8+
role="checkbox"
9+
tabindex="0"
10+
>
11+
<input
12+
tabindex="-1"
13+
type="checkbox"
14+
value="apples"
15+
/>
16+
<div
17+
class="state"
18+
>
19+
<label />
20+
</div>
21+
</div>
22+
</div>
23+
`;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { renderHook, act } from '@testing-library/react-hooks';
2+
import { useCheckboxState } from '../Checkbox';
3+
4+
describe('useCheckboxState tests', () => {
5+
it('should update when change is called', () => {
6+
const { result } = renderHook(() => useCheckboxState());
7+
8+
expect(result.current).toMatchObject({
9+
state: expect.any(Boolean),
10+
setState: expect.any(Function),
11+
onChange: expect.any(Function),
12+
});
13+
14+
act(() => {
15+
result.current.onChange({ currentTarget: { value: '' } } as any);
16+
});
17+
18+
expect(result.current.state).toBe(true);
19+
20+
act(() => {
21+
result.current.onChange({ currentTarget: { value: '' } } as any);
22+
});
23+
24+
expect(result.current.state).toBe(false);
25+
});
26+
27+
it('should handle arrays of items', () => {
28+
const { result } = renderHook(() => useCheckboxState({ state: [] }));
29+
30+
act(() => {
31+
result.current.onChange({ currentTarget: { value: 'oranges' } } as any);
32+
});
33+
34+
expect(result.current.state).toBeInstanceOf(Array);
35+
expect(result.current.state).toEqual(['oranges']);
36+
37+
act(() => {
38+
result.current.onChange({ currentTarget: { value: 'apples' } } as any);
39+
});
40+
41+
expect(result.current.state).toEqual(['oranges', 'apples']);
42+
43+
act(() => {
44+
result.current.onChange({ currentTarget: { value: 'oranges' } } as any);
45+
});
46+
47+
expect(result.current.state).toEqual(['apples']);
48+
});
49+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { renderHook, act } from '@testing-library/react-hooks';
2+
import { useRadioState } from '../Radio';
3+
4+
describe('useRadioState tests', () => {
5+
it('should work with boolean values', () => {
6+
const { result } = renderHook(() => useRadioState());
7+
8+
expect(result.current).toMatchObject({
9+
state: expect.any(Boolean),
10+
setState: expect.any(Function),
11+
onChange: expect.any(Function),
12+
});
13+
14+
act(() => {
15+
result.current.onChange({ currentTarget: {} } as any);
16+
});
17+
18+
expect(result.current.state).toBeUndefined();
19+
20+
act(() => {
21+
result.current.onChange({ currentTarget: {} } as any);
22+
});
23+
24+
expect(result.current.state).toBe(true);
25+
});
26+
});

src/factory/Pretty.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const Pretty = React.forwardRef<HTMLDivElement, PrettyProps>((props: Pret
5050
'aria-checked': state === 'indeterminate' ? 'mixed' : !!state,
5151
tabIndex: 0,
5252
onKeyPress: React.useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
53+
/* istanbul ignore next */
5354
e.preventDefault();
5455
}, []),
5556
onKeyUp: React.useCallback(

0 commit comments

Comments
 (0)