Skip to content

Commit

Permalink
refactor: restructure file folder for select-dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
kalasgarov committed Nov 1, 2024
1 parent 45b4830 commit 1c5600c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/forms/src/documents/pdf/parsing-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { type InputPattern } from '../../patterns/input/index.js';
import { type ParagraphPattern } from '../../patterns/paragraph.js';
import { type CheckboxPattern } from '../../patterns/checkbox.js';
import { type RadioGroupPattern } from '../../patterns/radio-group.js';
import { type SelectDropdownPattern } from '../../patterns/select-dropdown.js';
import { type SelectDropdownPattern } from '../../patterns/select-dropdown/select-dropdown.js';

import { uint8ArrayToBase64 } from '../util.js';
import { type DocumentFieldMap } from '../types.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/forms/src/patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { pageSetConfig } from './page-set/index.js';
import { paragraphConfig } from './paragraph.js';
import { radioGroupConfig } from './radio-group.js';
import { richTextConfig } from './rich-text.js';
import { selectDropdownConfig } from './select-dropdown.js';
import { selectDropdownConfig } from './select-dropdown/select-dropdown.js';
import { sequenceConfig } from './sequence.js';

// This configuration reflects what a user of this library would provide for
Expand Down Expand Up @@ -47,5 +47,5 @@ export * from './page-set/index.js';
export { type PageSetPattern } from './page-set/config.js';
export * from './paragraph.js';
export * from './radio-group.js';
export * from './select-dropdown.js';
export * from './select-dropdown/select-dropdown.js';
export * from './sequence.js';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { createSchema, selectDropdownConfig, type SelectDropdownPattern } from '../src/patterns/select-dropdown';
import { createSchema, selectDropdownConfig, type SelectDropdownPattern } from './select-dropdown';

describe('SelectDropdownPattern tests', () => {
describe('createSchema', () => {
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('SelectDropdownPattern tests', () => {
expect(schema.safeParse('option1').success).toBe(true);
expect(schema.safeParse('option2').success).toBe(true);
expect(schema.safeParse('invalid').success).toBe(false);
expect(schema.safeParse('').success).toBe(true); // Empty string should be valid for optional fields
expect(schema.safeParse('').success).toBe(true);
});

it('should throw error if no options are provided', () => {
Expand Down Expand Up @@ -98,6 +98,7 @@ describe('SelectDropdownPattern tests', () => {
console.log('Test parse result (error case):', result);
if (!result.success) {
expect(result.error).toBeDefined();
expect(result.error.message).toBe("Invalid enum value. Expected 'option1' | 'option2', received 'invalid'");
} else {
throw new Error('Unexpected validation success');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as z from 'zod';

import { type SelectDropdownProps } from '../components.js';
import { type SelectDropdownProps } from '../../components.js';
import {
type Pattern,
type PatternConfig,
validatePattern,
} from '../pattern.js';
import { getFormSessionValue } from '../session.js';
import { safeZodParseFormErrors } from '../util/zod.js';
} from '../../pattern.js';
import { getFormSessionValue } from '../../session.js';
import { safeZodParseFormErrors, safeZodParseToFormError } from '../../util/zod.js';

const configSchema = z.object({
label: z.string().min(1),
Expand Down Expand Up @@ -88,6 +88,22 @@ export const selectDropdownConfig: PatternConfig<
}
},

// parseUserInput: (pattern, inputObj) => {
// const expectedInput = inputObj as { value: string };
// console.log('TEST parseUserInput', pattern, expectedInput);

// const schema = createSchema(pattern.data);
// console.log('TEST schema', schema);
// const result = schema.parse(expectedInput.value);
// console.log('TEST result', result);

// if (result.success) {
// return { success: true, data: result.data };
// } else {
// return { success: false, error: safeZodParseToFormError(schema, obj) };
// }
// },

parseConfigData: obj => {
const result = safeZodParseFormErrors(configSchema, obj);
return result;
Expand Down

0 comments on commit 1c5600c

Please sign in to comment.