Skip to content

Commit

Permalink
[#81] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Dec 13, 2023
1 parent ad293b5 commit 08b517f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:

- name: Run tests
run: |
npm run test-jest
npm run test:jest
env:
CI: 'true'

Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
cd storybook-static/ && tar -xvf artifact.tar && cd ..
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --quiet" \
"npx wait-on -l http://127.0.0.1:6006 && npm test -- --browsers ${{ matrix.browser }}"
"npx wait-on -l http://127.0.0.1:6006 && npm run test:storybook -- --browsers ${{ matrix.browser }}"
deploy:
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"build:esm": "ttsc -p tsconfig.prod.json && tsc-alias -p tsconfig.prod.json",
"build:cjs": "ttsc -p tsconfig.prod.json --module commonjs --outDir lib/cjs && tsc-alias -p tsconfig.prod.json --outDir lib/cjs",
"build": "npm-run-all build:*",
"test": "test-storybook",
"test-jest": "jest",
"test": "npm-run-all test:*",
"test:storybook": "test-storybook",
"test:jest": "jest",
"format": "prettier --write 'src/**/*'",
"checkformat": "prettier --check 'src/**/*'",
"start": "npm run storybook",
Expand Down
12 changes: 6 additions & 6 deletions src/components/ComponentEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ export interface ComponentEditFormProps {
// don't know (yet), so we need to handle FallbackSchema.
component: AnyComponentSchema | FallbackSchema;
builderInfo: BuilderInfo;
onCancel?: (e: React.MouseEvent<HTMLButtonElement>) => void;
onRemove?: (e: React.MouseEvent<HTMLButtonElement>) => void;
onSubmit?: (component: AnyComponentSchema | FallbackSchema) => void;
onCancel: (e: React.MouseEvent<HTMLButtonElement>) => void;
onRemove: (e: React.MouseEvent<HTMLButtonElement>) => void;
onSubmit: (component: AnyComponentSchema | FallbackSchema) => void;
}

const ComponentEditForm: React.FC<ComponentEditFormProps> = ({
isNew,
component,
builderInfo,
onCancel = () => {},
onRemove = () => {},
onSubmit = () => {},
onCancel,
onRemove,
onSubmit,
}) => {
const intl = useIntl();
const builderContext = useContext(BuilderContext);
Expand Down
50 changes: 28 additions & 22 deletions src/registry/select/select-validation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@ import ComponentEditForm from '@/components/ComponentEditForm';
import {contextRender, screen} from '@/test-utils';

describe('Manual values: must have at least one non-empty value', () => {
const args = {
isNew: true,
component: {
id: 'wqimsadk',
type: 'select',
key: 'select',
label: 'A select field',
openForms: {
dataSrc: 'manual',
translations: {},
},
values: [{value: '', label: ''}],
defaultValue: '',
},
builderInfo: {
title: 'Select',
icon: 'th-list',
group: 'basic',
weight: 70,
schema: {},
const component = {
id: 'wqimsadk',
type: 'select',
key: 'select',
label: 'A select field',
openForms: {
dataSrc: 'manual',
translations: {},
},
values: [{value: '', label: ''}],
defaultValue: '',
};
const builderInfo = {
title: 'Select',
icon: 'th-list',
group: 'basic',
weight: 70,
schema: {},
};

contextRender(<ComponentEditForm {...args} />);

test('Option values and labels are required fields', async () => {
contextRender(
<ComponentEditForm
isNew
component={component}
builderInfo={builderInfo}
onCancel={jest.fn()}
onRemove={jest.fn()}
onSubmit={jest.fn()}
/>
);

const labelInput = screen.getByLabelText('Option label');
await userEvent.type(labelInput, 'Foo');
await userEvent.clear(labelInput);
Expand Down
2 changes: 1 addition & 1 deletion src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const contextRender = (
builderOptions: Partial<BuilderOptions> = {},
renderOptions: RenderOptions = {}
): RenderResult => {
function Wrapper({children}: {children: React.ReactElement}) {
function Wrapper({children}: {children: React.ReactNode}) {
return (
<IntlProvider locale={locale}>
{!enableContext ? (
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"noErrorTruncation": true,
"paths": {
"@/*": ["./*"],
"@/sb-decorators": ["../.storybook/decorators.tsx"],
"@/sb-decorators": ["../.storybook/decorators.tsx"]
},
"plugins": [
{
Expand All @@ -31,8 +31,8 @@
"ast": true
}
],
"types": ["node", "jest", "@testing-library/jest-dom"],
"types": ["node", "jest", "@testing-library/jest-dom"]
},
"include": ["src"],
"exclude": ["node_modules", "lib"],
"exclude": ["node_modules", "lib"]
}

0 comments on commit 08b517f

Please sign in to comment.