Skip to content

Commit

Permalink
custom-compose
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Dec 6, 2024
1 parent 66e3398 commit f38fb48
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ describe('Compose clean task form', () => {

it('Validate task description', () => {
const desc = makeDefaultComposeCleanTaskDescription();
const emptyZoneDesc = insertCleaningZone(desc, '');
expect(isComposeCleanTaskDescriptionValid(emptyZoneDesc)).not.toBeTruthy();
const insertedDesc = insertCleaningZone(desc, 'clean_zone_3');
expect(isComposeCleanTaskDescriptionValid(insertedDesc)).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

import { CustomComposeTaskForm } from './custom-compose';

describe('Custom compose task form', () => {
it('Renders custom compose task form', async () => {
const onChange = vi.fn();
const onValidate = vi.fn();

render(<CustomComposeTaskForm taskDesc={''} onChange={onChange} onValidate={onValidate} />);
});

it('CustomComposeTaskForm validates input', () => {
const onChange = vi.fn();
const onValidate = vi.fn();

render(<CustomComposeTaskForm taskDesc="" onChange={onChange} onValidate={onValidate} />);

const textArea = screen.getByRole('textbox', { name: /multiline/i });

// Invalid input (invalid JSON)
fireEvent.change(textArea, { target: { value: 'invalid json' } });
expect(onValidate).toHaveBeenCalledWith(false);

// Valid input
const validTaskDesc = '{"valid": "json"}';
fireEvent.change(textArea, { target: { value: validTaskDesc } });
expect(onValidate).toHaveBeenCalledWith(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Meta, StoryObj } from '@storybook/react';

import { CustomComposeTaskForm } from './custom-compose';

export default {
title: 'Tasks/CustomComposeTaskForm',
component: CustomComposeTaskForm,
} satisfies Meta;

type Story = StoryObj<typeof CustomComposeTaskForm>;

export const Default: Story = {
args: {
taskDesc: '',
onChange: () => {},
onValidate: () => {},
},
};

0 comments on commit f38fb48

Please sign in to comment.