Skip to content

Commit

Permalink
✅ Add RMC test for removeAllFields actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic committed Aug 16, 2023
1 parent 6b0d426 commit 18f0507
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:key="action.value"
:command="action.value"
:disabled="action.disabled"
:data-test-id="`action-${action.value}`"
>
{{ action.label }}
<div :class="$style.iconContainer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div
v-if="$slots.options"
:class="{ [$style.options]: true, [$style.visible]: showOptions }"
data-test-id="parameter-input-options-container"
:data-test-id="`${inputName}-parameter-input-options-container`"
>
<slot name="options" />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div data-test-id="parameter-input">
<parameter-input
ref="param"
:inputSize="inputSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ defineExpose({
:size="labelSize"
:showOptions="true"
:showExpressionSelector="false"
inputName="columns"
color="text-dark"
>
<template #options>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import ResourceMapper from '@/components/ResourceMapper/ResourceMapper.vue';
import userEvent from '@testing-library/user-event';
import { createComponentRenderer } from '@/__tests__/render';
import type { SpyInstance } from 'vitest';
import { ResourceMapperValue } from 'n8n-workflow';

let nodeTypeStore: ReturnType<typeof useNodeTypesStore>;
let fetchFieldsSpy: SpyInstance, resolveParameterSpy: SpyInstance;
let fetchFieldsSpy: SpyInstance;
let resolveParameterSpy: SpyInstance;

const renderComponent = createComponentRenderer(ResourceMapper, DEFAULT_SETUP);

Expand Down Expand Up @@ -289,4 +291,52 @@ describe('ResourceMapper.vue', () => {
await waitAllPromises();
expect(fetchFieldsSpy).not.toHaveBeenCalled();
});

it('should delete fields from UI and parameter value when they are deleted', async () => {
const { getByTestId, emitted } = renderComponent({
props: {
node: {
parameters: {
columns: {
schema: null,
},
},
},
},
});
await waitAllPromises();
// Add some values so we can test if they are gone after deletion
const idInput = getByTestId('parameter-input-value["id"]').querySelector('input');
const firstNameInput = getByTestId('parameter-input-value["First name"]').querySelector(
'input',
);
const lastNameInput = getByTestId('parameter-input-value["Last name"]').querySelector('input');
const usernameInput = getByTestId('parameter-input-value["Username"]').querySelector('input');
const addressInput = getByTestId('parameter-input-value["Address"]').querySelector('input');
if (idInput && firstNameInput && lastNameInput && usernameInput && addressInput) {
await userEvent.type(idInput, '123');
await userEvent.type(firstNameInput, 'John');
await userEvent.type(lastNameInput, 'Doe');
await userEvent.type(usernameInput, 'johndoe');
await userEvent.type(addressInput, '123 Main St');
// Remove all fields
await userEvent.click(getByTestId('columns-parameter-input-options-container'));
await userEvent.click(getByTestId('action-removeAllFields'));
// Should delete all non-mandatory fields
expect(
getByTestId('resource-mapper-container').querySelectorAll('.parameter-item').length,
).toBe(3);
const valueChangeEmits = emitted().valueChanged as [];
const lastEmittedEvent = valueChangeEmits[valueChangeEmits.length - 1] as Array<{
name: string;
value: ResourceMapperValue;
node: string;
}>;
// All non-mandatory field values should be deleted
expect(lastEmittedEvent[0].value.value).not.toHaveProperty('Username');
expect(lastEmittedEvent[0].value.value).not.toHaveProperty('Address');
} else {
throw new Error('Could not find input fields');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,5 @@ export const MAPPING_COLUMNS_RESPONSE: ResourceMapperFields = {
type: 'string',
canBeUsedToMatch: true,
},
{
id: 'Last Name',
displayName: 'Last Name',
match: false,
required: false,
defaultMatch: false,
display: true,
type: 'string',
canBeUsedToMatch: true,
},
],
};

0 comments on commit 18f0507

Please sign in to comment.