Skip to content

Commit

Permalink
Merge pull request activepieces#4199 from activepieces/fix/e2e-test
Browse files Browse the repository at this point in the history
test: e2e execution flow test
  • Loading branch information
abuaboud authored Mar 19, 2024
2 parents 7aae8b9 + 9b681cc commit 4bba8bb
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ApFlagId, PlatformRole, PrincipalType, Project, ProjectMemberRole, User } from '@activepieces/shared'
import { PlatformRole, PrincipalType, Project, ProjectMemberRole, User } from '@activepieces/shared'
import { projectService } from '../../../project/project-service'
import { AuthenticationServiceHooks } from './authentication-service-hooks'
import { accessTokenManager } from '../../lib/access-token-manager'
import { flagService } from '../../../flags/flag.service'
import { userService } from '../../../user/user-service'
import { platformService } from '../../../platform/platform.service'

Expand All @@ -16,10 +15,6 @@ export const communityAuthenticationServiceHooks: AuthenticationServiceHooks = {
// Empty
},
async postSignUp({ user }) {
const platformCreated = await flagService.getOne(ApFlagId.PLATFORM_CREATED)
if (platformCreated?.value) {
return getProjectAndToken(user)
}
const platform = await platformService.create({
ownerId: user.id,
name: DEFAULT_PLATFORM_NAME,
Expand All @@ -32,10 +27,6 @@ export const communityAuthenticationServiceHooks: AuthenticationServiceHooks = {
})
await userService.updatePlatformId({ id: user.id, platformId: platform.id })

await flagService.save({
id: ApFlagId.PLATFORM_CREATED,
value: true,
})
return getProjectAndToken(user)
},

Expand Down
20 changes: 20 additions & 0 deletions packages/tests-e2e/.env.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
AP_API_KEY=api-key
AP_QUEUE_MODE=MEMORY
AP_DB_TYPE=SQLITE3
AP_ENVIRONMENT=test
AP_ENCRYPTION_KEY=7e19fad4c13eaea8f657afb12e8f9c40
AP_FRONTEND_URL=http://localhost:4200
AP_WEBHOOK_URL=http://localhost:3000
AP_WEBHOOK_TIMEOUT_SECONDS=30
AP_LOG_LEVEL=error
AP_LOG_PRETTY=true
AP_QUEUE_MODE=MEMORY
AP_TELEMETRY_ENABLED=false
AP_ENRICH_ERROR_CONTEXT=true
AP_TRIGGER_DEFAULT_POLL_INTERVAL=1
AP_CACHE_PATH=./dev/cache
AP_SIGN_UP_ENABLED=true
AP_EXECUTION_MODE=UNSANDBOXED
AP_PIECES_SOURCE=CLOUD_AND_DB
AP_JWT_SECRET=secret

4 changes: 0 additions & 4 deletions packages/tests-e2e/.env.sample

This file was deleted.

5 changes: 5 additions & 0 deletions packages/tests-e2e/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export const globalConfig = {
instanceUrl: 'http://localhost:4200',
password: 'Test@1234578',
}
20 changes: 0 additions & 20 deletions packages/tests-e2e/helper/test-utils.ts

This file was deleted.

48 changes: 48 additions & 0 deletions packages/tests-e2e/page/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { globalConfig } from "../config";
import { Page } from "@playwright/test";
import { dashboard } from "./dashboard";

export const authentication = {
async signIn(page: Page, params: { email: string, password: string }) {
await page.goto(`${globalConfig.instanceUrl}/sign-in`);

const emailField = page.getByPlaceholder('Email');

await emailField.click();
await emailField.fill(params.email);
await emailField.press('Tab');

const passwordField = page.getByPlaceholder('Password');
await passwordField.fill(params.password);
await passwordField.press('Enter');

await dashboard.waitFor(page);
},
async signUp(page: Page, params: { email: string, password: string }) {
await page.goto(`${globalConfig.instanceUrl}/sign-up`);

const firstNameField = page.getByText('First Name').first()
await firstNameField.click();
await firstNameField.fill('Bugs');
await firstNameField.press('Tab');

const lastNameField = page.getByText('Last Name').first()
await lastNameField.click();
await lastNameField.fill('Bunny');
await lastNameField.press('Tab');

const emailField = page.getByPlaceholder('Email');
await emailField.click();
await emailField.fill(params.email);
await emailField.press('Tab');

const passwordField = page.getByText('Password').first();
await passwordField.fill(params.password);

await page.locator('.cdk-overlay-backdrop').click();

await page.getByRole('button', { name: 'Sign up' }).click();

await dashboard.waitFor(page);
}
}
48 changes: 48 additions & 0 deletions packages/tests-e2e/page/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Page, expect } from '@playwright/test';

const property = {
async selectConnection(page: Page, params: { connection: string }) {
await page.getByRole('combobox', { name: 'Connection' }).locator('span').click();
await page.getByText(params.connection, { exact: true }).click();
},
async selectDropdown(page: Page, params: { property: string, value: string }) {
await page.getByText(params.property, { exact: true }).click()
await page.getByText(params.value).click();
}
}

export const builder = {
async selectInitalTrigger(page: Page, params: { piece: string, trigger: string }) {
await page.getByText('Choose a trigger', { exact: true }).click();
await page.getByPlaceholder('Search').click();
await page.getByPlaceholder('Search').fill(params.piece);
await page.getByAltText(params.piece).click();

await page.getByText('Select a Trigger').click();
await page.getByText(params.trigger, { exact: true }).click();
await page.waitForTimeout(5000);
},
async addAction(page: Page, params: { piece: string, action: string }) {
await page.locator('app-small-add-button div').first().click();
await page.getByPlaceholder('Search').click();
await page.getByPlaceholder('Search').fill(params.piece);
await page.getByText(params.piece).click();

await page.getByText('Select an action').click();
await page.getByText(params.action, { exact: true }).click();
},
async testFlowAndWaitForSuccess(page: Page) {
await page.getByText('Test flow').click();
await page.waitForSelector('//*[contains(text(),"Run succeeded")]'); // Wait for the element to appear
const runSuccessText = await page.locator('//*[contains(text(),"Run succeeded")]').textContent();
expect(runSuccessText).toContain('Run succeeded');
},
async exitRun(page: Page) {
await page.getByRole('button', { name: 'Exit Run' }).click();
},
async clickHome(page: Page) {
await page.getByLabel('Home').click();
},
property,
}

10 changes: 10 additions & 0 deletions packages/tests-e2e/page/dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Page } from "@playwright/test";


export const dashboard = {
waitFor: async (page: Page) => {
await page.getByLabel("Home").waitFor({
timeout: 5000
});
}
}
25 changes: 25 additions & 0 deletions packages/tests-e2e/page/flows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Page } from "@playwright/test";

export const flows = {
deleteFlow: async (page: Page, params: { flowName: string }) => {
await page.getByRole('row', { name: new RegExp(`^${params.flowName}`) }).getByRole('button').first().click();
await page.getByRole('menuitem', { name: 'Delete' }).click();

await page.getByPlaceholder('DELETE').fill('DELETE');
const confirmButton = await page.getByRole('button', { name: 'Confirm' });
await confirmButton.click()

await page.waitForSelector('button:has-text("Confirm")', { state: 'hidden' });
},
newFlowFromScratch: async (page: Page) => {
const startBuildingButton = await page.getByText('Start building your first flow');
if (startBuildingButton) {
await startBuildingButton.click();
await page.getByText('Start from scratch').click();
} else {
const newFlowButton = await page.getByRole('button', { name: 'New Flow' });
await newFlowButton.click();
await page.getByText('From Scratch').click();
}
},
}
25 changes: 0 additions & 25 deletions packages/tests-e2e/playwright.config.ts

This file was deleted.

13 changes: 11 additions & 2 deletions packages/tests-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
"sourceRoot": "packages/tests-e2e",
"projectType": "application",
"targets": {
"test": {
"test-local": {
"executor": "nx:run-commands",
"options": {
"commands": [
"npx playwright test ./packages/tests-e2e/tests/ --project=chrome"
"export $(cat packages/tests-e2e/.env.e2e | xargs) && npm start",
"sleep 30 && curl -s -o /dev/null -w \"%{http_code}\" http://localhost:3000/v1/flags | grep -q \"2[0-9][0-9]\" && npx nx run tests-e2e:test-scenarios"
]
}
},
"test-scenarios": {
"executor": "nx:run-commands",
"options": {
"commands": [
"npx playwright test packages/tests-e2e/tests/*.spec.ts"
]
}
},
Expand Down
70 changes: 0 additions & 70 deletions packages/tests-e2e/tests/send-slack-message.spec.ts

This file was deleted.

12 changes: 12 additions & 0 deletions packages/tests-e2e/tests/sign-up.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from '@playwright/test';
import { authentication } from '../page/authentication';
import { faker } from '@faker-js/faker'
import { globalConfig } from '../config';

test('Sign Up New Account', async ({ page }) => {
const email = faker.internet.email();
await authentication.signUp(page, {
email: email,
password: globalConfig.password
})
});
30 changes: 30 additions & 0 deletions packages/tests-e2e/tests/test-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test } from '@playwright/test';
import { builder } from '../page/builder';
import { flows } from '../page/flows';
import { authentication } from '../page/authentication';
import { faker } from '@faker-js/faker'
import { globalConfig } from '../config';

test('Test Execute Flow', async ({ page }) => {
test.setTimeout(100000);
const email = faker.internet.email();
await authentication.signUp(page, {
email: email,
password: globalConfig.password
})
await flows.newFlowFromScratch(page);
await builder.selectInitalTrigger(page, {
piece: 'Schedule',
trigger: 'Every Day'
});

await builder.addAction(page, {
piece: 'Data Mapper',
action: 'Advanced Mapping'
});

await builder.testFlowAndWaitForSuccess(page);
await builder.clickHome(page);
await flows.deleteFlow(page, { flowName: 'Untitled' })

});

0 comments on commit 4bba8bb

Please sign in to comment.