Skip to content

Commit

Permalink
Merge pull request #4138 from novuhq/nv-2689-cypress-e2e-tests-for-th…
Browse files Browse the repository at this point in the history
…e-integration-conditions

test: conditions for integration tests
  • Loading branch information
ainouzgali authored Sep 11, 2023
2 parents ed118da + b9a8787 commit 1aaa712
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 53 deletions.
190 changes: 156 additions & 34 deletions apps/web/cypress/tests/integrations-list-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -46,13 +61,15 @@ describe('Integrations List Page', function () {
channel,
environment,
status,
conditions,
}: {
name: string;
isFree?: boolean;
provider: string;
channel: string;
environment?: string;
status: string;
conditions?: number;
},
nth: number
) => {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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(
Expand All @@ -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('[email protected]');
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');
Expand Down Expand Up @@ -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');
Expand Down
41 changes: 26 additions & 15 deletions apps/web/src/components/conditions/Conditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function Conditions({
>
{fields.map((item, index) => {
return (
<div key={item.id}>
<div data-test-id="conditions-form-item" key={item.id}>
<Grid columns={20} align="center" gutter="xs">
<Grid.Col span={2}>
{index > 0 ? (
Expand Down Expand Up @@ -146,12 +146,7 @@ export function Conditions({
defaultValue={FilterPartTypeEnum.TENANT}
render={({ field }) => {
return (
<Select
placeholder="On"
data={FilterPartTypeList}
{...field}
data-test-id="conditions-form-on-dropdown"
/>
<Select placeholder="On" data={FilterPartTypeList} {...field} data-test-id="conditions-form-on" />
);
}}
/>
Expand All @@ -162,17 +157,25 @@ export function Conditions({
withArrow={false}
offset={0}
control={
<ActionIcon variant={'transparent'}>
<ActionIcon data-test-id="conditions-row-btn" variant={'transparent'}>
<DotsHorizontal color={colors.B60} />
</ActionIcon>
}
middlewares={{ flip: false, shift: false }}
position="bottom-end"
>
<Dropdown.Item onClick={() => handleDuplicate(index)} icon={<Duplicate />}>
<Dropdown.Item
data-test-id="conditions-row-duplicate"
onClick={() => handleDuplicate(index)}
icon={<Duplicate />}
>
Duplicate
</Dropdown.Item>
<Dropdown.Item onClick={() => handleDelete(index)} icon={<Trash />}>
<Dropdown.Item
data-test-id="conditions-row-delete"
onClick={() => handleDelete(index)}
icon={<Trash />}
>
Delete
</Dropdown.Item>
</Dropdown>
Expand All @@ -194,6 +197,7 @@ export function Conditions({
});
}}
icon={<ConditionPlus />}
data-test-id="add-new-condition"
>
Add condition
</Button>
Expand Down Expand Up @@ -224,7 +228,7 @@ function EqualityForm({ control, index }: { control: Control<IConditionsForm>; i
{ value: 'identifier', label: 'Identifier' },
]}
{...field}
data-test-id="conditions-form-field-dropdown"
data-test-id="conditions-form-key"
/>
);
}}
Expand All @@ -247,7 +251,7 @@ function EqualityForm({ control, index }: { control: Control<IConditionsForm>; i
{ value: 'IS_DEFINED', label: 'Is defined' },
]}
{...field}
data-test-id="conditions-form-operator-dropdown"
data-test-id="conditions-form-operator"
/>
);
}}
Expand All @@ -268,16 +272,23 @@ function EqualityForm({ control, index }: { control: Control<IConditionsForm>; i
value={field.value as string}
rightSection={
<When truthy={!!fieldState.error}>
<Tooltip error position="top" offset={15} label={'Value is missing'}>
<Tooltip
opened
data-test-id="conditions-form-tooltip-error"
error
position="top"
offset={15}
label={'Value is missing'}
>
<span>
<ErrorIcon color={colors.error} />
<ErrorIcon data-test-id="conditions-form-value-error" color={colors.error} />
</span>
</Tooltip>
</When>
}
error={!!fieldState.error}
placeholder="Value"
data-test-id="conditions-form-value-input"
data-test-id="conditions-form-value"
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TestWrapper>
<ExecutionDetailsConditionItem condition={condition} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TestWrapper>
<ExecutionDetailsConditions conditions={conditions} />
Expand Down
Loading

0 comments on commit 1aaa712

Please sign in to comment.