Skip to content

Commit

Permalink
Fix & improve test
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Sep 19, 2024
1 parent 1345e65 commit 1ce6934
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 5 additions & 7 deletions public/pages/workflows/new_workflow/new_workflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import * as ReactReduxHooks from '../../../store/store';
import '@testing-library/jest-dom';
import { loadPresetWorkflowTemplates } from '../../../../test/utils';
import { INITIAL_ML_STATE } from '../../../../public/store';
import { WORKFLOW_TYPE } from '../../../../common/constants';
import { capitalizeEachWord } from '../../../../test/utils';

jest.mock('../../../services', () => {
const { mockCoreServices } = require('../../../../test');
Expand Down Expand Up @@ -54,13 +52,13 @@ describe('NewWorkflow', () => {
jest.spyOn(ReactReduxHooks, 'useAppDispatch').mockReturnValue(mockDispatch);
});

test('renders the preset workflow templates', () => {
test('renders the preset workflow names & descriptions', () => {
const presetWorkflows = loadPresetWorkflowTemplates();
const { getByPlaceholderText, getAllByText } = renderWithRouter();
expect(getByPlaceholderText('Search')).toBeInTheDocument();
Object.values(WORKFLOW_TYPE).forEach((type) => {
if (type !== WORKFLOW_TYPE.UNKNOWN) {
expect(getAllByText(capitalizeEachWord(type))).toHaveLength(1);
}
presetWorkflows.forEach((workflow) => {
expect(getAllByText(workflow.name)).toHaveLength(1);
expect(getAllByText(workflow.description)).toHaveLength(1);
});
});

Expand Down
4 changes: 0 additions & 4 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ export const loadPresetWorkflowTemplates = () =>
JSON.parse(fs.readFileSync(path.join(templatesDir, file), 'utf8'))
);

export function capitalizeEachWord(input: string): string {
return input.replace(/\b\w/g, (match) => match.toUpperCase());
}

export const resizeObserverMock = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
Expand Down

0 comments on commit 1ce6934

Please sign in to comment.