Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor): Migrate FixedCollectionParameter to composition API #11555

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions packages/editor-ui/src/components/FixedCollectionParameter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { mount } from '@vue/test-utils';
import FixedCollectionParameter from '@/components/FixedCollectionParameter.vue';
import { createTestingPinia } from '@pinia/testing';
import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
import { STORES } from '@/constants';
import { setActivePinia } from 'pinia';

describe('FixedCollectionParameter.vue', () => {
const pinia = createTestingPinia({
initialState: {
[STORES.SETTINGS]: {
settings: SETTINGS_STORE_DEFAULT_STATE.settings,
},
},
});
setActivePinia(pinia);
let props: any;

beforeEach(() => {
props = {
nodeValues: {},
parameter: {
typeOptions: { multipleValues: true, sortable: true },
options: [{ name: 'values', values: [] }],
},
path: 'some.path',
values: {},
isReadOnly: false,
};
vi.mock('n8n-workflow', async () => {
const original = await vi.importActual('n8n-workflow');
return {
...original,
isINodePropertyCollectionList: vi.fn(() => true),
};
});
});
afterEach(() => {
vi.clearAllMocks();
});

it('renders the component', () => {
const wrapper = mount(FixedCollectionParameter, { props });
expect(wrapper.exists()).toBe(true);
});

it('computes placeholder text correctly', () => {
const wrapper = mount(FixedCollectionParameter, { props });
expect(wrapper.vm.getPlaceholderText).toBe('Choose...');
});

it('emits valueChanged event on option deletion', async () => {
const wrapper = mount(FixedCollectionParameter, { props });
await wrapper.vm.deleteOption('option1', 0);
expect(wrapper.emitted().valueChanged).toBeTruthy();
});

it('emits valueChanged event on option order change (moveOptionUp)', async () => {
const wrapper = mount(FixedCollectionParameter, { props });
await wrapper.vm.moveOptionUp('option1', 1);
expect(wrapper.emitted().valueChanged).toBeTruthy();
});

it('updates mutableValues when values prop changes', async () => {
const wrapper = mount(FixedCollectionParameter, { props });
const newValues = {
option1: [{ name: 'newOption', value: 'newValue' }],
};
await wrapper.setProps({ values: newValues });
expect(wrapper.vm.mutableValues).toEqual(newValues);
});

it('computes parameterOptions correctly when multiple values allowed', () => {
const wrapper = mount(FixedCollectionParameter, { props });
expect(wrapper.vm.parameterOptions).toContainEqual({ name: 'values', values: [] });
});

it('computes sortable correctly based on props', () => {
const wrapper = mount(FixedCollectionParameter, { props });
expect(wrapper.vm.sortable).toBe(true);
});
});
Loading
Loading