From f114035a6b4470c5a8e9ec2f470a9a667e0dd7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20G=C3=B3mez=20Morales?= Date: Wed, 4 Sep 2024 08:04:35 +0200 Subject: [PATCH] refactor(editor): Remove Trial logic in personalization modal and port to script setup (#10649) Co-authored-by: Csaba Tuncsik --- .../components/PersonalizationModal.test.ts | 157 +++ .../src/components/PersonalizationModal.vue | 1075 ++++++++--------- .../__tests__/PersonalizationModal.spec.ts | 144 --- 3 files changed, 635 insertions(+), 741 deletions(-) create mode 100644 packages/editor-ui/src/components/PersonalizationModal.test.ts delete mode 100644 packages/editor-ui/src/components/__tests__/PersonalizationModal.spec.ts diff --git a/packages/editor-ui/src/components/PersonalizationModal.test.ts b/packages/editor-ui/src/components/PersonalizationModal.test.ts new file mode 100644 index 0000000000000..160beefccd617 --- /dev/null +++ b/packages/editor-ui/src/components/PersonalizationModal.test.ts @@ -0,0 +1,157 @@ +import userEvent from '@testing-library/user-event'; +import { createComponentRenderer } from '@/__tests__/render'; +import { getDropdownItems, mockedStore } from '@/__tests__/utils'; +import { createUser } from '@/__tests__/data/users'; +import { useSettingsStore } from '@/stores/settings.store'; +import PersonalizationModal from '@/components/PersonalizationModal.vue'; +import { useUsersStore } from '@/stores/users.store'; +import { createTestingPinia } from '@pinia/testing'; +import { + COMPANY_TYPE_KEY, + EMAIL_KEY, + COMPANY_INDUSTRY_EXTENDED_KEY, + OTHER_COMPANY_INDUSTRY_EXTENDED_KEY, + MARKETING_AUTOMATION_GOAL_KEY, + OTHER_MARKETING_AUTOMATION_GOAL_KEY, + ROLE_KEY, + ROLE_OTHER_KEY, + DEVOPS_AUTOMATION_GOAL_OTHER_KEY, + DEVOPS_AUTOMATION_GOAL_KEY, +} from '@/constants'; + +const renderModal = createComponentRenderer(PersonalizationModal, { + global: { + stubs: { + Modal: { + template: ` +
+ + + + +
+ `, + }, + }, + }, +}); + +describe('PersonalizationModal', () => { + it('mounts', () => { + const { getByTitle } = renderModal({ pinia: createTestingPinia() }); + expect(getByTitle('Customize n8n to you')).toBeInTheDocument(); + }); + + it('shows user input when needed for desktop deployment', () => { + const pinia = createTestingPinia(); + const usersStore = mockedStore(useUsersStore); + usersStore.currentUser = createUser({ firstName: undefined }); + + const settingsStore = mockedStore(useSettingsStore); + settingsStore.isDesktopDeployment = true; + + const { getByTestId } = renderModal({ pinia }); + expect(getByTestId(EMAIL_KEY)).toBeInTheDocument(); + }); + + describe('Company field', () => { + it('allows completion of company related fields', async () => { + const { getByTestId } = renderModal({ pinia: createTestingPinia() }); + + const companyTypeSelect = getByTestId(COMPANY_TYPE_KEY); + + const otherTypeOfCompanyOption = [...(await getDropdownItems(companyTypeSelect))].find( + (node) => node.textContent === 'Other', + ) as Element; + + await userEvent.click(otherTypeOfCompanyOption); + + const industrySelect = getByTestId(COMPANY_INDUSTRY_EXTENDED_KEY); + expect(industrySelect).toBeInTheDocument(); + + const otherIndustryOption = [...(await getDropdownItems(industrySelect))].find( + (node) => node.textContent === 'Other (please specify)', + ) as Element; + + await userEvent.click(otherIndustryOption); + + expect(getByTestId(OTHER_COMPANY_INDUSTRY_EXTENDED_KEY)).toBeInTheDocument(); + }); + + it('shows only company and source select when not used for work', async () => { + const { getByTestId, baseElement } = renderModal({ pinia: createTestingPinia() }); + + const companyTypeSelect = getByTestId(COMPANY_TYPE_KEY); + + const nonWorkOption = [...(await getDropdownItems(companyTypeSelect))].find( + (node) => node.textContent === "I'm not using n8n for work", + ) as Element; + + await userEvent.click(nonWorkOption); + + expect(baseElement.querySelectorAll('input').length).toBe(2); + }); + }); + + it('allows completion of role related fields', async () => { + const { getByTestId, queryByTestId } = renderModal({ pinia: createTestingPinia() }); + + const roleSelect = getByTestId(ROLE_KEY); + const roleItems = [...(await getDropdownItems(roleSelect))]; + + const devOps = roleItems.find((node) => node.textContent === 'Devops') as Element; + const engineering = roleItems.find((node) => node.textContent === 'Engineering') as Element; + const it = roleItems.find((node) => node.textContent === 'IT') as Element; + const other = roleItems.find( + (node) => node.textContent === 'Other (please specify)', + ) as Element; + + await userEvent.click(devOps); + const automationGoalSelect = getByTestId(DEVOPS_AUTOMATION_GOAL_KEY); + expect(automationGoalSelect).toBeInTheDocument(); + + await userEvent.click(engineering); + expect(automationGoalSelect).toBeInTheDocument(); + + await userEvent.click(it); + expect(automationGoalSelect).toBeInTheDocument(); + + const otherGoalsItem = [...(await getDropdownItems(automationGoalSelect))].find( + (node) => node.textContent === 'Other', + ) as Element; + + await userEvent.click(otherGoalsItem); + expect(getByTestId(DEVOPS_AUTOMATION_GOAL_OTHER_KEY)).toBeInTheDocument(); + + await userEvent.click(other); + expect(queryByTestId(DEVOPS_AUTOMATION_GOAL_KEY)).not.toBeInTheDocument(); + expect(getByTestId(ROLE_OTHER_KEY)).toBeInTheDocument(); + }); + + it('allows completion of marketing and sales related fields', async () => { + const { getByTestId } = renderModal({ pinia: createTestingPinia() }); + + const companyTypeSelect = getByTestId(COMPANY_TYPE_KEY); + + const anyWorkOption = [...(await getDropdownItems(companyTypeSelect))].find( + (node) => node.textContent !== "I'm not using n8n for work", + ) as Element; + + await userEvent.click(anyWorkOption); + + const roleSelect = getByTestId(ROLE_KEY); + const salesAndMarketingOption = [...(await getDropdownItems(roleSelect))].find( + (node) => node.textContent === 'Sales and Marketing', + ) as Element; + + await userEvent.click(salesAndMarketingOption); + + const salesAndMarketingSelect = getByTestId(MARKETING_AUTOMATION_GOAL_KEY); + const otherItem = [...(await getDropdownItems(salesAndMarketingSelect))].find( + (node) => node.textContent === 'Other', + ) as Element; + + await userEvent.click(otherItem); + expect(getByTestId(OTHER_MARKETING_AUTOMATION_GOAL_KEY)).toBeInTheDocument(); + }); +}); diff --git a/packages/editor-ui/src/components/PersonalizationModal.vue b/packages/editor-ui/src/components/PersonalizationModal.vue index 13e360c3c1981..1eab5e4b20816 100644 --- a/packages/editor-ui/src/components/PersonalizationModal.vue +++ b/packages/editor-ui/src/components/PersonalizationModal.vue @@ -1,6 +1,5 @@ -