From b9a8787ff662a184fa378c82d30169b718604e38 Mon Sep 17 00:00:00 2001 From: ainouzgali Date: Mon, 11 Sep 2023 13:20:18 +0300 Subject: [PATCH] test: conditions for integration tests --- .../tests/integrations-list-page.spec.ts | 190 ++++++++++++++---- .../src/components/conditions/Conditions.tsx | 41 ++-- .../ExecutionDetailsConditionItem.cy.tsx | 2 +- .../ExecutionDetailsConditions.cy.tsx | 2 +- .../integrations/components/ConditionCell.tsx | 2 + .../components/ConditionIconButton.tsx | 2 + .../components/IntegrationNameCell.tsx | 2 +- .../components/PrimaryIconButton.tsx | 2 + .../CreateProviderInstanceSidebar.tsx | 3 +- 9 files changed, 193 insertions(+), 53 deletions(-) diff --git a/apps/web/cypress/tests/integrations-list-page.spec.ts b/apps/web/cypress/tests/integrations-list-page.spec.ts index e3684f0bc12..0df7867ade7 100644 --- a/apps/web/cypress/tests/integrations-list-page.spec.ts +++ b/apps/web/cypress/tests/integrations-list-page.spec.ts @@ -30,6 +30,21 @@ describe('Integrations List Page', function () { .as('session'); }); + const interceptIntegrationRequests = () => { + cy.intercept('GET', '*/integrations', async () => { + await new Promise((resolve) => setTimeout(resolve, 1000)); + }).as('getIntegrations'); + cy.intercept('POST', '*/integrations', async () => { + await new Promise((resolve) => setTimeout(resolve, 1000)); + }).as('createIntegration'); + cy.intercept('*/environments').as('getEnvironments'); + + cy.visit('/integrations'); + + cy.wait('@getIntegrations'); + cy.wait('@getEnvironments'); + }; + const checkTableLoading = () => { cy.getByTestId('integration-name-cell-loading').should('have.length', 10).first().should('be.visible'); cy.getByTestId('integration-provider-cell-loading').should('have.length', 10).first().should('be.visible'); @@ -46,6 +61,7 @@ describe('Integrations List Page', function () { channel, environment, status, + conditions, }: { name: string; isFree?: boolean; @@ -53,6 +69,7 @@ describe('Integrations List Page', function () { channel: string; environment?: string; status: string; + conditions?: number; }, nth: number ) => { @@ -95,6 +112,14 @@ describe('Integrations List Page', function () { .should('be.visible') .contains(environment); } + if (conditions) { + cy.get('@integrations-table') + .get('tr') + .eq(nth) + .getByTestId('integration-conditions-cell') + .should('be.visible') + .contains(conditions); + } cy.get('@integrations-table') .get('tr') @@ -398,7 +423,7 @@ describe('Integrations List Page', function () { cy.getByTestId('select-provider-sidebar-next').should('be.disabled').contains('Next'); }); - it('should show emply search results', () => { + it('should show empty search results', () => { cy.intercept('*/integrations', async () => { await new Promise((resolve) => setTimeout(resolve, 1000)); }).as('getIntegrations'); @@ -535,18 +560,39 @@ describe('Integrations List Page', function () { }); it('should create a new mailjet integration', () => { - cy.intercept('GET', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('getIntegrations'); - cy.intercept('POST', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('createIntegration'); - cy.intercept('*/environments').as('getEnvironments'); + interceptIntegrationRequests(); - cy.visit('/integrations'); + cy.getByTestId('add-provider').should('be.enabled').click(); + cy.location('pathname').should('equal', '/integrations/create'); + cy.getByTestId('select-provider-sidebar').should('be.visible'); - cy.wait('@getIntegrations'); - cy.wait('@getEnvironments'); + cy.getByTestId(`provider-${EmailProviderIdEnum.Mailjet}`).contains('Mailjet').click(); + cy.getByTestId('select-provider-sidebar-next').should('not.be.disabled').contains('Next').click(); + + cy.location('pathname').should('equal', '/integrations/create/email/mailjet'); + cy.getByTestId('provider-instance-name').clear().type('Mailjet Integration'); + cy.getByTestId('create-provider-instance-sidebar-create').should('not.be.disabled').contains('Create').click(); + cy.getByTestId('create-provider-instance-sidebar-create').should('be.disabled'); + + cy.wait('@createIntegration'); + + cy.getByTestId('update-provider-sidebar').should('be.visible'); + cy.location('pathname').should('contain', '/integrations/'); + + checkTableRow( + { + name: 'Mailjet Integration', + provider: 'Mailjet', + channel: 'Email', + environment: 'Development', + status: 'Disabled', + }, + 6 + ); + }); + + it('should create a new mailjet integration with conditions', () => { + interceptIntegrationRequests(); cy.getByTestId('add-provider').should('be.enabled').click(); cy.location('pathname').should('equal', '/integrations/create'); @@ -557,12 +603,27 @@ describe('Integrations List Page', function () { cy.location('pathname').should('equal', '/integrations/create/email/mailjet'); cy.getByTestId('provider-instance-name').clear().type('Mailjet Integration'); + cy.getByTestId('add-conditions-btn').click(); + cy.getByTestId('conditions-form-title').contains('Conditions for Mailjet Integration provider instance'); + cy.getByTestId('add-new-condition').click(); + cy.getByTestId('conditions-form-on').should('have.value', 'Tenant'); + cy.getByTestId('conditions-form-key').should('have.value', 'Identifier'); + cy.getByTestId('conditions-form-operator').should('have.value', 'Equal'); + cy.getByTestId('conditions-form-value').type('tenant123'); + cy.getByTestId('apply-conditions-btn').click(); + cy.getByTestId('add-conditions-btn').contains('Edit conditions'); + cy.getByTestId('create-provider-instance-sidebar-create').should('not.be.disabled').contains('Create').click(); cy.getByTestId('create-provider-instance-sidebar-create').should('be.disabled'); cy.wait('@createIntegration'); cy.getByTestId('update-provider-sidebar').should('be.visible'); + cy.getByTestId('header-add-conditions-btn').contains('1').click(); + cy.getByTestId('add-new-condition').click(); + cy.getByTestId('conditions-form-value').last().type('tenant456'); + cy.getByTestId('apply-conditions-btn').click(); + cy.getByTestId('header-add-conditions-btn').contains('2'); cy.location('pathname').should('contain', '/integrations/'); checkTableRow( @@ -572,24 +633,96 @@ describe('Integrations List Page', function () { channel: 'Email', environment: 'Development', status: 'Disabled', + conditions: 1, }, 6 ); }); - it('should update the mailjet integration', () => { - cy.intercept('GET', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('getIntegrations'); - cy.intercept('POST', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('createIntegration'); - cy.intercept('*/environments').as('getEnvironments'); + it('should remove as primary when adding conditions', () => { + interceptIntegrationRequests(); - cy.visit('/integrations'); + cy.getByTestId('integrations-list-table') + .getByTestId('integration-name-cell') + .contains('SendGrid') + .getByTestId('integration-name-cell-primary') + .should('be.visible'); - cy.wait('@getIntegrations'); - cy.wait('@getEnvironments'); + clickOnListRow('SendGrid'); + cy.getByTestId('header-add-conditions-btn').click(); + + cy.getByTestId('remove-primary-flag-modal').should('be.visible'); + cy.getByTestId('remove-primary-flag-modal').contains('Primary flag will be removed'); + cy.getByTestId('remove-primary-flag-modal').contains( + 'Adding conditions to the primary provider instance removes its primary status when a user applies changes by' + ); + cy.getByTestId('remove-primary-flag-modal').find('button').contains('Cancel').should('be.visible'); + cy.getByTestId('remove-primary-flag-modal').find('button').contains('Got it').should('be.visible').click(); + + cy.getByTestId('conditions-form-title').contains('Conditions for SendGrid provider instance'); + cy.getByTestId('add-new-condition').click(); + cy.getByTestId('conditions-form-on').should('have.value', 'Tenant'); + cy.getByTestId('conditions-form-key').should('have.value', 'Identifier'); + cy.getByTestId('conditions-form-operator').should('have.value', 'Equal'); + cy.getByTestId('conditions-form-value').type('tenant123'); + + cy.getByTestId('apply-conditions-btn').click(); + cy.getByTestId('provider-instance-name').first().clear().type('SendGrid test'); + + cy.getByTestId('from').type('info@novu.co'); + cy.getByTestId('senderName').type('Novu'); + + cy.getByTestId('update-provider-sidebar-update').should('not.be.disabled').contains('Update').click(); + cy.get('.mantine-Modal-modal button').contains('Make primary'); + + cy.get('.mantine-Modal-close').click(); + }); + + it('should remove conditions when set to primary', () => { + interceptIntegrationRequests(); + + cy.getByTestId('add-provider').should('be.enabled').click(); + cy.location('pathname').should('equal', '/integrations/create'); + cy.getByTestId('select-provider-sidebar').should('be.visible'); + + cy.getByTestId(`provider-${EmailProviderIdEnum.Mailjet}`).contains('Mailjet').click(); + cy.getByTestId('select-provider-sidebar-next').should('not.be.disabled').contains('Next').click(); + + cy.location('pathname').should('equal', '/integrations/create/email/mailjet'); + cy.getByTestId('provider-instance-name').clear().type('Mailjet Integration'); + cy.getByTestId('add-conditions-btn').click(); + cy.getByTestId('conditions-form-title').contains('Conditions for Mailjet Integration provider instance'); + cy.getByTestId('add-new-condition').click(); + + cy.getByTestId('conditions-form-value').type('tenant123'); + cy.getByTestId('apply-conditions-btn').click(); + + cy.getByTestId('create-provider-instance-sidebar-create').should('not.be.disabled').contains('Create').click(); + + cy.wait('@createIntegration'); + + cy.getByTestId('update-provider-sidebar').should('be.visible'); + cy.getByTestId('header-add-conditions-btn').contains('1'); + + cy.getByTestId('header-make-primary-btn').click(); + + cy.getByTestId('remove-conditions-modal').should('be.visible'); + cy.getByTestId('remove-conditions-modal').contains('Conditions will be removed'); + cy.getByTestId('remove-conditions-modal').contains('Marking this instance as primary will remove all conditions'); + cy.getByTestId('remove-conditions-modal').find('button').contains('Cancel').should('be.visible'); + cy.getByTestId('remove-conditions-modal').find('button').contains('Remove conditions').should('be.visible').click(); + + cy.getByTestId('header-make-primary-btn').should('not.exist'); + + cy.getByTestId('integrations-list-table') + .getByTestId('integration-name-cell') + .contains('Mailjet Integration') + .getByTestId('integration-name-cell-primary') + .should('be.visible'); + }); + + it('should update the mailjet integration', () => { + interceptIntegrationRequests(); cy.getByTestId('add-provider').should('be.enabled').click(); cy.location('pathname').should('equal', '/integrations/create'); @@ -641,18 +774,7 @@ describe('Integrations List Page', function () { }); it('should update the mailjet integration from the list', () => { - cy.intercept('GET', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('getIntegrations'); - cy.intercept('POST', '*/integrations', async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); - }).as('createIntegration'); - cy.intercept('*/environments').as('getEnvironments'); - - cy.visit('/integrations'); - - cy.wait('@getIntegrations'); - cy.wait('@getEnvironments'); + interceptIntegrationRequests(); cy.getByTestId('add-provider').should('be.enabled').click(); cy.location('pathname').should('equal', '/integrations/create'); diff --git a/apps/web/src/components/conditions/Conditions.tsx b/apps/web/src/components/conditions/Conditions.tsx index f3635c2baec..65ad7d0ad46 100644 --- a/apps/web/src/components/conditions/Conditions.tsx +++ b/apps/web/src/components/conditions/Conditions.tsx @@ -110,7 +110,7 @@ export function Conditions({ > {fields.map((item, index) => { return ( -
+
{index > 0 ? ( @@ -146,12 +146,7 @@ export function Conditions({ defaultValue={FilterPartTypeEnum.TENANT} render={({ field }) => { return ( - ); }} /> @@ -162,17 +157,25 @@ export function Conditions({ withArrow={false} offset={0} control={ - + } middlewares={{ flip: false, shift: false }} position="bottom-end" > - handleDuplicate(index)} icon={}> + handleDuplicate(index)} + icon={} + > Duplicate - handleDelete(index)} icon={}> + handleDelete(index)} + icon={} + > Delete @@ -194,6 +197,7 @@ export function Conditions({ }); }} icon={} + data-test-id="add-new-condition" > Add condition @@ -224,7 +228,7 @@ function EqualityForm({ control, index }: { control: Control; i { value: 'identifier', label: 'Identifier' }, ]} {...field} - data-test-id="conditions-form-field-dropdown" + data-test-id="conditions-form-key" /> ); }} @@ -247,7 +251,7 @@ function EqualityForm({ control, index }: { control: Control; i { value: 'IS_DEFINED', label: 'Is defined' }, ]} {...field} - data-test-id="conditions-form-operator-dropdown" + data-test-id="conditions-form-operator" /> ); }} @@ -268,16 +272,23 @@ function EqualityForm({ control, index }: { control: Control; i value={field.value as string} rightSection={ - + - + } error={!!fieldState.error} placeholder="Value" - data-test-id="conditions-form-value-input" + data-test-id="conditions-form-value" /> ); }} diff --git a/apps/web/src/components/execution-detail/ExecutionDetailsConditionItem.cy.tsx b/apps/web/src/components/execution-detail/ExecutionDetailsConditionItem.cy.tsx index c47f61b64c2..5a6e0009e9f 100644 --- a/apps/web/src/components/execution-detail/ExecutionDetailsConditionItem.cy.tsx +++ b/apps/web/src/components/execution-detail/ExecutionDetailsConditionItem.cy.tsx @@ -12,7 +12,7 @@ const condition: ICondition = { }; describe('Execution Details Condition Component', function () { - it('should render ExecutionDetailsCondtions properly', function () { + it('should render ExecutionDetailsConditions properly', function () { cy.mount( diff --git a/apps/web/src/components/execution-detail/ExecutionDetailsConditions.cy.tsx b/apps/web/src/components/execution-detail/ExecutionDetailsConditions.cy.tsx index d6cdc2c55b6..dab60f4c9d5 100644 --- a/apps/web/src/components/execution-detail/ExecutionDetailsConditions.cy.tsx +++ b/apps/web/src/components/execution-detail/ExecutionDetailsConditions.cy.tsx @@ -39,7 +39,7 @@ const conditions: ICondition[] = [ ]; describe('Execution Details Condition Component', function () { - it('should render ExecutionDetailsCondtions properly', function () { + it('should render ExecutionDetailsConditions properly', function () { cy.mount( diff --git a/apps/web/src/pages/integrations/components/ConditionCell.tsx b/apps/web/src/pages/integrations/components/ConditionCell.tsx index 70c50525366..eabd3fc969f 100644 --- a/apps/web/src/pages/integrations/components/ConditionCell.tsx +++ b/apps/web/src/pages/integrations/components/ConditionCell.tsx @@ -9,6 +9,7 @@ const ConditionCellBase = ({ row: { original } }: IExtendedCellProps { if (primary && conditions === 0) { setModalOpen(true); @@ -78,6 +79,7 @@ export const ConditionIconButton = ({ diff --git a/apps/web/src/pages/integrations/components/IntegrationNameCell.tsx b/apps/web/src/pages/integrations/components/IntegrationNameCell.tsx index e0b65da5227..14dafb26ede 100644 --- a/apps/web/src/pages/integrations/components/IntegrationNameCell.tsx +++ b/apps/web/src/pages/integrations/components/IntegrationNameCell.tsx @@ -93,7 +93,7 @@ export const IntegrationNameCell = ({ row: { original }, isLoading }: IExtendedC target={ setPopoverOpened(true)} onMouseLeave={() => setPopoverOpened(false)}> {original.name} - {original.primary && } + {original.primary && } } /> diff --git a/apps/web/src/pages/integrations/components/PrimaryIconButton.tsx b/apps/web/src/pages/integrations/components/PrimaryIconButton.tsx index e81a4ab0640..250807840a7 100644 --- a/apps/web/src/pages/integrations/components/PrimaryIconButton.tsx +++ b/apps/web/src/pages/integrations/components/PrimaryIconButton.tsx @@ -56,6 +56,7 @@ export const PrimaryIconButton = ({ position="bottom" > { if (conditions > 0) { setModalOpen(true); @@ -72,6 +73,7 @@ export const PrimaryIconButton = ({ diff --git a/apps/web/src/pages/integrations/components/multi-provider/CreateProviderInstanceSidebar.tsx b/apps/web/src/pages/integrations/components/multi-provider/CreateProviderInstanceSidebar.tsx index 61bd0f96827..79cede5bee3 100644 --- a/apps/web/src/pages/integrations/components/multi-provider/CreateProviderInstanceSidebar.tsx +++ b/apps/web/src/pages/integrations/components/multi-provider/CreateProviderInstanceSidebar.tsx @@ -196,7 +196,7 @@ export function CreateProviderInstanceSidebar({ }} /> - + } @@ -285,6 +285,7 @@ export function CreateProviderInstanceSidebar({