more code coverage

This commit is contained in:
David Lechner
2023-03-08 15:07:16 -06:00
committed by David Lechner
parent 5fa0e90783
commit af160c99a8
28 changed files with 580 additions and 40 deletions
+5 -8
View File
@@ -1,21 +1,18 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import React from 'react';
import { testRender } from '../../../test';
import { fileInUse } from './FileInUseAlert';
it('should be valid', () => {
it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = fileInUse(callback, { fileName: 'test.file' });
// TODO: refactor this to a common function to be used by all alerts
const [user, message] = testRender(<Toast {...toast} />);
// it should render
const [, message] = testRender(<>{toast.message}</>);
expect(message).toBeDefined();
await user.click(message.getByRole('button', { name: /close/i }));
// it should have a dismiss callback
toast.onDismiss?.(false);
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 { noFilesToBackup } from './NoFilesToBackup';
it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = noFilesToBackup(callback, undefined as never);
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
expect(callback).toHaveBeenCalledWith('dismiss');
});
+18
View File
@@ -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 { noPyFiles } from './NoPyFiles';
it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = noPyFiles(callback, undefined as never);
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
expect(callback).toHaveBeenCalledWith('dismiss');
});
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import React from 'react';
@@ -27,3 +27,54 @@ describe('should handle all possible validation results', () => {
);
});
});
it('should fix file names with spaces', async () => {
const callback = jest.fn();
const [user, group] = testRender(
<FileNameFormGroup
fileName="test name"
fileExtension=".file"
validationResult={FileNameValidationResult.HasSpaces}
onChange={callback}
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
expect(callback).toHaveBeenCalledWith('test_name');
});
it('should fix file names with file extension', async () => {
const callback = jest.fn();
const [user, group] = testRender(
<FileNameFormGroup
fileName="test.file"
fileExtension=".file"
validationResult={FileNameValidationResult.HasFileExtension}
onChange={callback}
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
expect(callback).toHaveBeenCalledWith('test');
});
it('should fix file names with invalid characters', async () => {
const callback = jest.fn();
const [user, group] = testRender(
<FileNameFormGroup
fileName="test-name"
fileExtension=".file"
validationResult={FileNameValidationResult.HasInvalidCharacters}
onChange={callback}
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
expect(callback).toHaveBeenCalledWith('test_name');
});