mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
more code coverage
This commit is contained in:
committed by
David Lechner
parent
5fa0e90783
commit
af160c99a8
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { dfuError } from './DfuError';
|
||||
|
||||
it('should dismiss when close is clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = dfuError(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
});
|
||||
|
||||
it('should try again when clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = dfuError(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /again/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('tryAgain');
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { flashProgress } from './FlashProgress';
|
||||
|
||||
type ActionType = 'erase' | 'flash';
|
||||
|
||||
it.each(['erase' as ActionType, 'flash' as ActionType])(
|
||||
'should dismiss when close is clicked',
|
||||
async (action) => {
|
||||
const callback = jest.fn();
|
||||
const toast = flashProgress(callback, { action, progress: 0 });
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { isLinux, isWindows } from '../../utils/os';
|
||||
import { noDfuHub } from './NoDfuHub';
|
||||
|
||||
jest.mock('../../utils/os');
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should dismiss when close is clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = noDfuHub(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
});
|
||||
|
||||
it('should install windows driver when clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = noDfuHub(callback, undefined as never);
|
||||
|
||||
jest.mocked(isLinux).mockReturnValue(true);
|
||||
jest.mocked(isWindows).mockReturnValue(true);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /driver/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('installWindowsDriver');
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { noDfuInterface } from './NoDfuInterface';
|
||||
|
||||
it('should dismiss when close is clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = noDfuInterface(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { noWebUsb } from './NoWebUsb';
|
||||
|
||||
it('should dismiss when close is clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = noWebUsb(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { Toast } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { releaseButton } from './ReleaseButton';
|
||||
|
||||
it('should dismiss when close is clicked', async () => {
|
||||
const callback = jest.fn();
|
||||
const toast = releaseButton(callback, undefined as never);
|
||||
|
||||
const [user, message] = testRender(<Toast {...toast} />);
|
||||
|
||||
await user.click(message.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(callback).toHaveBeenCalledWith('dismiss');
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import { cleanup } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import { InstallPybricksDialog } from './InstallPybricksDialog';
|
||||
import {
|
||||
firmwareInstallPybricksDialogAccept,
|
||||
firmwareInstallPybricksDialogCancel,
|
||||
} from './actions';
|
||||
|
||||
jest.mock('./hooks');
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
cleanup();
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
});
|
||||
|
||||
it('should dispatch when close is clicked', async () => {
|
||||
const [user, dialog, dispatch] = testRender(<InstallPybricksDialog />, {
|
||||
firmware: { installPybricksDialog: { isOpen: true } },
|
||||
});
|
||||
|
||||
await user.click(dialog.getByRole('button', { name: /close/i }));
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith(firmwareInstallPybricksDialogCancel());
|
||||
});
|
||||
|
||||
it('should dispatch when done is clicked', async () => {
|
||||
const [user, dialog, dispatch] = testRender(<InstallPybricksDialog />, {
|
||||
firmware: { installPybricksDialog: { isOpen: true } },
|
||||
});
|
||||
|
||||
// first page - select hub
|
||||
await user.click(dialog.getByRole('button', { name: /next/i }));
|
||||
|
||||
// second page - accept license
|
||||
await user.click(dialog.getByRole('checkbox', { name: /agree/i }));
|
||||
await user.click(dialog.getByRole('button', { name: /next/i }));
|
||||
|
||||
// third page - options
|
||||
await user.click(dialog.getByRole('button', { name: /next/i }));
|
||||
|
||||
// last page
|
||||
await user.click(dialog.getByRole('button', { name: /install/i }));
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith(
|
||||
firmwareInstallPybricksDialogAccept(
|
||||
'ble-lwp3-bootloader',
|
||||
new ArrayBuffer(0),
|
||||
'',
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2023 The Pybricks Authors
|
||||
|
||||
import type { Hub } from '../../../components/hubPicker';
|
||||
|
||||
export function useFirmware(_hubType: Hub) {
|
||||
return {
|
||||
firmwareData: {
|
||||
firmwareZip: new ArrayBuffer(0),
|
||||
licenseText: 'test',
|
||||
metadata: {},
|
||||
},
|
||||
firmwareError: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function useCustomFirmware(_zipFile: File | undefined) {
|
||||
return {
|
||||
isCustomFirmwareRequested: false,
|
||||
customFirmwareData: undefined,
|
||||
customFirmwareError: undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user