fix: fix personalization modal tests

This commit is contained in:
Alex Grozav 2023-07-21 12:26:33 +03:00
parent beea77229c
commit 7d38ed939d
5 changed files with 29 additions and 6 deletions

View file

@ -42,6 +42,7 @@
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
:name="name" :name="name"
:teleported="teleported"
ref="inputRef" ref="inputRef"
> >
<n8n-option <n8n-option
@ -125,6 +126,7 @@ export interface Props {
activeColor?: string; activeColor?: string;
inactiveLabel?: string; inactiveLabel?: string;
inactiveColor?: string; inactiveColor?: string;
teleported?: boolean;
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
@ -133,6 +135,7 @@ const props = withDefaults(defineProps<Props>(), {
type: 'text', type: 'text',
showRequiredAsterisk: true, showRequiredAsterisk: true,
validateOnBlur: true, validateOnBlur: true,
teleported: true,
}); });
const emit = defineEmits<{ const emit = defineEmits<{

View file

@ -25,6 +25,7 @@
:modelValue="values[input.name]" :modelValue="values[input.name]"
:data-test-id="input.name" :data-test-id="input.name"
:showValidationWarnings="showValidationWarnings" :showValidationWarnings="showValidationWarnings"
:teleported="teleported"
@update:modelValue="(value) => onUpdateModelValue(input.name, value)" @update:modelValue="(value) => onUpdateModelValue(input.name, value)"
@validate="(value) => onValidate(input.name, value)" @validate="(value) => onValidate(input.name, value)"
@enter="onSubmit" @enter="onSubmit"
@ -68,6 +69,10 @@ export default defineComponent({
default: '', default: '',
validator: (value: string): boolean => ['', 'xs', 's', 'm', 'm', 'l', 'xl'].includes(value), validator: (value: string): boolean => ['', 'xs', 's', 'm', 'm', 'l', 'xl'].includes(value),
}, },
teleported: {
type: Boolean,
default: true,
},
}, },
data() { data() {
return { return {

View file

@ -12,7 +12,7 @@
:close-on-click-modal="closeOnClickModal" :close-on-click-modal="closeOnClickModal"
:close-on-press-escape="closeOnPressEscape" :close-on-press-escape="closeOnPressEscape"
:style="styles" :style="styles"
append-to-body :append-to-body="appendToBody"
:data-test-id="`${this.name}-modal`" :data-test-id="`${this.name}-modal`"
> >
<template #header v-if="$slots.header"> <template #header v-if="$slots.header">
@ -46,6 +46,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ElDialog } from 'element-plus';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
@ -55,6 +56,7 @@ import { useUIStore } from '@/stores/ui.store';
export default defineComponent({ export default defineComponent({
name: 'Modal', name: 'Modal',
props: { props: {
...ElDialog.props,
name: { name: {
type: String, type: String,
}, },
@ -121,6 +123,10 @@ export default defineComponent({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
appendToBody: {
type: Boolean,
default: true,
},
}, },
mounted() { mounted() {
window.addEventListener('keydown', this.onWindowKeydown); window.addEventListener('keydown', this.onWindowKeydown);

View file

@ -18,6 +18,7 @@
:inputs="survey" :inputs="survey"
:columnView="true" :columnView="true"
:eventBus="formBus" :eventBus="formBus"
:teleported="teleported"
@submit="onSubmit" @submit="onSubmit"
/> />
</div> </div>
@ -141,6 +142,12 @@ export default defineComponent({
name: 'PersonalizationModal', name: 'PersonalizationModal',
mixins: [workflowHelpers], mixins: [workflowHelpers],
components: { Modal }, components: { Modal },
props: {
teleported: {
type: Boolean,
default: true,
},
},
data() { data() {
return { return {
isSaving: false, isSaving: false,

View file

@ -4,8 +4,13 @@ import { PERSONALIZATION_MODAL_KEY, STORES } from '@/constants';
import { retry } from '@/__tests__/utils'; import { retry } from '@/__tests__/utils';
import { createComponentRenderer } from '@/__tests__/render'; import { createComponentRenderer } from '@/__tests__/render';
import { fireEvent } from '@testing-library/vue'; import { fireEvent } from '@testing-library/vue';
import { nextTick } from 'vue';
const renderComponent = createComponentRenderer(PersonalizationModal, { const renderComponent = createComponentRenderer(PersonalizationModal, {
props: {
teleported: false,
appendToBody: false,
},
pinia: createTestingPinia({ pinia: createTestingPinia({
initialState: { initialState: {
[STORES.UI]: { [STORES.UI]: {
@ -33,7 +38,6 @@ describe('PersonalizationModal.vue', () => {
); );
expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(5); expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(5);
expect(wrapper.html()).toMatchSnapshot();
}); });
it('should display new option when role is "Devops", "Engineering", "IT", or "Sales and marketing"', async () => { it('should display new option when role is "Devops", "Engineering", "IT", or "Sales and marketing"', async () => {
@ -44,7 +48,7 @@ describe('PersonalizationModal.vue', () => {
); );
for (const index of [3, 4, 5, 6]) { for (const index of [3, 4, 5, 6]) {
const select = wrapper.container.querySelector('.n8n-select[name="role"]')!; const select = wrapper.container.querySelectorAll('.n8n-select')[1]!;
await fireEvent.click(select); await fireEvent.click(select);
@ -54,9 +58,7 @@ describe('PersonalizationModal.vue', () => {
await retry(() => { await retry(() => {
expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6); expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6);
expect( expect(wrapper.container.querySelector('[name^="automationGoal"]')).toBeInTheDocument();
wrapper.container.querySelector('.n8n-select[name^="automationGoal"]'),
).toBeInTheDocument();
}); });
} }
}); });