Skip to content

Commit

Permalink
Remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Jun 20, 2024
1 parent 03c9d35 commit f68c22e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 89 deletions.
50 changes: 0 additions & 50 deletions packages/snaps-jest/src/internals/simulation/interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import {
clickElement,
getElement,
getFormValues,
getInterface,
getInterfaceResponse,
mergeValue,
Expand Down Expand Up @@ -273,55 +272,6 @@ describe('getElement', () => {
});
});

describe('getFormValues', () => {
it('returns an empty object for the value and files if the state is undefined', () => {
const result = getFormValues(undefined);
expect(result).toStrictEqual({
value: {},
files: {},
});
});

it('returns the form values from the state', () => {
const state = {
foo: 'bar',
baz: {
name: 'qux',
size: 3,
contentType: 'application/octet-stream',
contents: 'AQID',
},
};

const result = getFormValues(state);

expect(result).toStrictEqual({
value: { foo: 'bar' },
files: {
baz: {
name: 'qux',
size: 3,
contentType: 'application/octet-stream',
contents: 'AQID',
},
},
});
});

it('returns null values as null', () => {
const state = {
foo: null,
};

const result = getFormValues(state);

expect(result).toStrictEqual({
value: { foo: null },
files: {},
});
});
});

describe('clickElement', () => {
const rootControllerMessenger = getRootControllerMessenger();
const controllerMessenger = getRestrictedSnapInterfaceControllerMessenger(
Expand Down
39 changes: 0 additions & 39 deletions packages/snaps-jest/src/internals/simulation/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,45 +275,6 @@ async function handleEvent(
}
}

/**
* The values and files of a form.
*
* @property value - The values of the form fields, if any.
* @property files - The files of the form fields, if any.
*/
export type FormValues = {
value: Record<string, string | null>;
files: Record<string, File | null>;
};

/**
* Get the form values from the interface state. If the event is not a form
* submit event, an empty object is returned. Otherwise, the form values are
* extracted from the state, and the values and files are returned separately.
*
* @param state - The interface state.
* @returns The form values.
*/
export function getFormValues(state?: FormState): FormValues {
if (!state) {
return { value: {}, files: {} };
}

return Object.entries(state).reduce<FormValues>(
(accumulator, [key, value]) => {
const formValue = value as string | File | null;
if (typeof formValue === 'string' || formValue === null) {
accumulator.value[key] = formValue;
} else {
accumulator.files[key] = formValue;
}

return accumulator;
},
{ value: {}, files: {} },
);
}

/**
* Click on an element of the Snap interface.
*
Expand Down

0 comments on commit f68c22e

Please sign in to comment.