Skip to content

Commit af160c9

Browse files
committed
more code coverage
1 parent 5fa0e90 commit af160c9

28 files changed

+580
-40
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../test';
7+
import { unexpectedError } from './UnexpectedErrorAlert';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = unexpectedError(callback, { error: new Error('test') });
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { updateServerFailure } from './UpdateServerFailure';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = updateServerFailure(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { bluetoothNotAvailable } from './BluetoothNotAvailable';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = bluetoothNotAvailable(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { missingService } from './MissingService';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = missingService(callback, { hubName: 'name', serviceName: 'service' });
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});

src/ble/alerts/NoGatt.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { noGatt } from './NoGatt';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = noGatt(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});

src/ble/alerts/NoHub.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { noHub } from './NoHub';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = noHub(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
19+
20+
it('should flash firmware when button is clicked', async () => {
21+
const callback = jest.fn();
22+
const toast = noHub(callback, undefined as never);
23+
24+
const [user, message] = testRender(<Toast {...toast} />);
25+
26+
await user.click(message.getByRole('button', { name: /firmware/i }));
27+
28+
expect(callback).toHaveBeenCalledWith('flashFirmware');
29+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { noWebBluetooth } from './NoWebBluetooth';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = noWebBluetooth(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022-2023 The Pybricks Authors
3+
4+
import { Toast } from '@blueprintjs/core';
5+
import React from 'react';
6+
import { testRender } from '../../../test';
7+
import { oldFirmware } from './OldFirmware';
8+
9+
it('should dismiss when close is clicked', async () => {
10+
const callback = jest.fn();
11+
const toast = oldFirmware(callback, undefined as never);
12+
13+
const [user, message] = testRender(<Toast {...toast} />);
14+
15+
await user.click(message.getByRole('button', { name: /close/i }));
16+
17+
expect(callback).toHaveBeenCalledWith('dismiss');
18+
});
19+
20+
it('should flash firmware when button is clicked', async () => {
21+
const callback = jest.fn();
22+
const toast = oldFirmware(callback, undefined as never);
23+
24+
const [user, message] = testRender(<Toast {...toast} />);
25+
26+
await user.click(message.getByRole('button', { name: /firmware/i }));
27+
28+
expect(callback).toHaveBeenCalledWith('flashFirmware');
29+
});

src/blueprintjs-icons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// HACK: Prevent webpack from picking up all icons.
55
// https://github.com/palantir/blueprint/issues/2193
66

7+
// istanbul ignore file
8+
79
import {
810
Add,
911
Archive,
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2022 The Pybricks Authors
2+
// Copyright (c) 2022-2023 The Pybricks Authors
33

4+
import { Toast } from '@blueprintjs/core';
45
import React from 'react';
56
import { testRender } from '../../../test';
67
import { fileInUse } from './FileInUseAlert';
78

8-
it('should be valid', () => {
9+
it('should dismiss when close is clicked', async () => {
910
const callback = jest.fn();
1011
const toast = fileInUse(callback, { fileName: 'test.file' });
1112

12-
// TODO: refactor this to a common function to be used by all alerts
13+
const [user, message] = testRender(<Toast {...toast} />);
1314

14-
// it should render
15-
const [, message] = testRender(<>{toast.message}</>);
16-
expect(message).toBeDefined();
15+
await user.click(message.getByRole('button', { name: /close/i }));
1716

18-
// it should have a dismiss callback
19-
toast.onDismiss?.(false);
2017
expect(callback).toHaveBeenCalledWith('dismiss');
2118
});

0 commit comments

Comments
 (0)