test: add tests for executions

This commit is contained in:
Jakub P.
2024-12-10 21:03:23 +01:00
parent feba2a32f9
commit 0012c9fb59
12 changed files with 443 additions and 45 deletions

View File

@@ -114,6 +114,7 @@ jobs:
- name: Run Playwright tests
working-directory: ./packages/e2e-tests
env:
PORT: 3000
LOGIN_EMAIL: user@automatisch.io
LOGIN_PASSWORD: sample
BASE_URL: http://localhost:3000

View File

@@ -0,0 +1,21 @@
const { AuthenticatedPage } = require('./authenticated-page');
const { expect } = require('@playwright/test');
export class ExecutionDetailsPage extends AuthenticatedPage {
constructor(page) {
super(page);
this.executionCreatedAt = page.getByTestId('execution-created-at');
this.executionId = page.getByTestId('execution-id');
this.executionName = page.getByTestId('execution-name');
this.executionStep = page.getByTestId('execution-step');
}
async verifyExecutionData(flowId) {
await expect(this.executionCreatedAt).toContainText(/\d+ seconds? ago/);
await expect(this.executionId).toHaveText(
/Execution ID: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
);
await expect(this.executionName).toHaveText(flowId);
}
}

View File

@@ -0,0 +1,93 @@
const { ExecutionDetailsPage } = require('./execution-details-page');
const { expect } = require('@playwright/test');
export class ExecutionStepDetails extends ExecutionDetailsPage {
constructor(page, executionStep) {
super(page);
this.executionStep = executionStep;
this.stepType = executionStep.getByTestId('step-type');
this.stepPositionAndName = executionStep.getByTestId(
'step-position-and-name'
);
this.executionStepId = executionStep.getByTestId('execution-step-id');
this.executionStepExecutedAt = executionStep.getByTestId(
'execution-step-executed-at'
);
this.dataInTab = executionStep.getByTestId('data-in-tab');
this.dataInPanel = executionStep.getByTestId('data-in-panel');
this.dataOutTab = executionStep.getByTestId('data-out-tab');
this.dataOutPanel = executionStep.getByTestId('data-out-panel');
}
async expectDataInTabToBeSelectedByDefault() {
await expect(this.dataInTab).toHaveClass(/Mui-selected/);
}
async expectDataInToContainText(searchText, desiredText) {
await expect(this.dataInPanel).toContainText(desiredText);
await this.dataInPanel.locator('#search-input').fill(searchText);
await expect(this.dataInPanel).toContainText(desiredText);
}
async expectDataOutToContainText(searchText, desiredText) {
await expect(this.dataOutPanel).toContainText(desiredText);
await this.dataOutPanel.locator('#search-input').fill(searchText);
await expect(this.dataOutPanel).toContainText(desiredText);
}
async verifyTriggerExecutionStep({
stepPositionAndName,
stepDataInKey,
stepDataInValue,
stepDataOutKey,
stepDataOutValue,
}) {
await expect(this.stepType).toHaveText('Trigger');
await this.verifyExecutionStep({
stepPositionAndName,
stepDataInKey,
stepDataInValue,
stepDataOutKey,
stepDataOutValue,
});
}
async verifyActionExecutionStep({
stepPositionAndName,
stepDataInKey,
stepDataInValue,
stepDataOutKey,
stepDataOutValue,
}) {
await expect(this.stepType).toHaveText('Action');
await this.verifyExecutionStep({
stepPositionAndName,
stepDataInKey,
stepDataInValue,
stepDataOutKey,
stepDataOutValue,
});
}
async verifyExecutionStep({
stepPositionAndName,
stepDataInKey,
stepDataInValue,
stepDataOutKey,
stepDataOutValue,
}) {
await expect(this.stepPositionAndName).toHaveText(stepPositionAndName);
await expect(this.executionStepId).toHaveText(
/ID: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
);
await expect(this.executionStepExecutedAt).toContainText(
/executed \d+ seconds? ago/
);
await this.expectDataInTabToBeSelectedByDefault();
await this.expectDataInToContainText(stepDataInKey, stepDataInValue);
await this.dataOutTab.click();
await expect(this.dataOutPanel).toContainText(stepDataOutValue);
await this.expectDataOutToContainText(stepDataOutKey, stepDataOutValue);
}
}

View File

@@ -2,4 +2,11 @@ const { AuthenticatedPage } = require('./authenticated-page');
export class ExecutionsPage extends AuthenticatedPage {
screenshotPath = '/executions';
constructor(page) {
super(page);
this.executionRow = this.page.getByTestId('execution-row');
this.executionsPageLoader = this.page.getByTestId('executions-loader');
}
}

View File

@@ -2,6 +2,7 @@ const { test, expect } = require('@playwright/test');
const { ApplicationsPage } = require('./applications-page');
const { ConnectionsPage } = require('./connections-page');
const { ExecutionsPage } = require('./executions-page');
const { ExecutionDetailsPage } = require('./execution-details-page');
const { FlowEditorPage } = require('./flow-editor-page');
const { UserInterfacePage } = require('./user-interface-page');
const { LoginPage } = require('./login-page');
@@ -29,6 +30,9 @@ exports.test = test.extend({
executionsPage: async ({ page }, use) => {
await use(new ExecutionsPage(page));
},
executionDetailsPage: async ({ page }, use) => {
await use(new ExecutionDetailsPage(page));
},
flowEditorPage: async ({ page }, use) => {
await use(new FlowEditorPage(page));
},

View File

@@ -0,0 +1,15 @@
const { expect } = require('../fixtures/index');
export const getToken = async (apiRequest) => {
const tokenResponse = await apiRequest.post(
`http://localhost:${process.env.PORT}/api/v1/access-tokens`,
{
data: {
email: process.env.LOGIN_EMAIL,
password: process.env.LOGIN_PASSWORD,
},
}
);
await expect(tokenResponse.status()).toBe(200);
return await tokenResponse.json();
};

View File

@@ -0,0 +1,108 @@
const { expect } = require('../fixtures/index');
export const createFlow = async (request, token) => {
const response = await request.post(
`http://localhost:${process.env.PORT}/api/v1/flows`,
{ headers: { Authorization: token } }
);
await expect(response.status()).toBe(201);
return await response.json();
};
export const getFlow = async (request, token, flowId) => {
const response = await request.get(
`http://localhost:${process.env.PORT}/api/v1/flows/${flowId}`,
{ headers: { Authorization: token } }
);
await expect(response.status()).toBe(200);
return await response.json();
};
export const updateFlowName = async (request, token, flowId) => {
const updateFlowNameResponse = await request.patch(
`http://localhost:${process.env.PORT}/api/v1/flows/${flowId}`,
{
headers: { Authorization: token },
data: { name: flowId },
}
);
await expect(updateFlowNameResponse.status()).toBe(200);
};
export const updateFlowStep = async (request, token, stepId, requestBody) => {
const updateTriggerStepResponse = await request.patch(
`http://localhost:${process.env.PORT}/api/v1/steps/${stepId}`,
{
headers: { Authorization: token },
data: requestBody,
}
);
await expect(updateTriggerStepResponse.status()).toBe(200);
return await updateTriggerStepResponse.json();
};
export const testStep = async (request, token, stepId) => {
const testTriggerStepResponse = await request.post(
`http://localhost:${process.env.PORT}/api/v1/steps/${stepId}/test`,
{
headers: { Authorization: token },
}
);
await expect(testTriggerStepResponse.status()).toBe(200);
};
export const publishFlow = async (request, token, flowId) => {
const publishFlowResponse = await request.patch(
`http://localhost:${process.env.PORT}/api/v1/flows/${flowId}/status`,
{
headers: { Authorization: token },
data: { active: true },
}
);
await expect(publishFlowResponse.status()).toBe(200);
return publishFlowResponse.json();
};
export const triggerFlow = async (request, url) => {
const triggerFlowResponse = await request.get(url);
await expect(triggerFlowResponse.status()).toBe(204);
};
export const addWebhookFlow = async (request, token) => {
let flow = await createFlow(request, token);
const flowId = flow.data.id;
await updateFlowName(request, token, flowId);
flow = await getFlow(request, token, flowId);
const flowSteps = flow.data.steps;
const triggerStepId = flowSteps.find((step) => step.type === 'trigger').id;
const actionStepId = flowSteps.find((step) => step.type === 'action').id;
const triggerStep = await updateFlowStep(request, token, triggerStepId, {
appKey: 'webhook',
key: 'catchRawWebhook',
parameters: {
workSynchronously: false,
},
});
await request.get(triggerStep.data.webhookUrl);
await testStep(request, token, triggerStepId);
await updateFlowStep(request, token, actionStepId, {
appKey: 'webhook',
key: 'respondWith',
parameters: {
statusCode: '200',
body: 'ok',
headers: [
{
key: '',
value: '',
},
],
},
});
await testStep(request, token, actionStepId);
return flowId;
};

View File

@@ -2,11 +2,14 @@ const { publicTest: setup, expect } = require('../../fixtures/index');
setup.describe.serial('Admin setup page', () => {
// eslint-disable-next-line no-unused-vars
setup('should not be able to login if admin is not created', async ({ page, adminSetupPage, loginPage }) => {
await expect(async () => {
await expect(await page.url()).toContain(adminSetupPage.path);
}).toPass();
});
setup(
'should not be able to login if admin is not created',
async ({ page, adminSetupPage }) => {
await expect(async () => {
await expect(await page.url()).toContain(adminSetupPage.path);
}).toPass();
}
);
setup('should validate the inputs', async ({ adminSetupPage }) => {
await adminSetupPage.open();

View File

@@ -1,37 +1,138 @@
const { request } = require('@playwright/test');
const { test, expect } = require('../../fixtures/index');
const {
triggerFlow,
publishFlow,
addWebhookFlow,
} = require('../../helpers/flow-api-helper');
const {
ExecutionStepDetails,
} = require('../../fixtures/execution-step-details');
const { getToken } = require('../../helpers/auth-api-helper');
test.describe('Executions page', () => {
let flowId;
test.beforeAll(async () => {
const apiRequest = await request.newContext();
const tokenJsonResponse = await getToken(apiRequest);
flowId = await addWebhookFlow(apiRequest, tokenJsonResponse.data.token);
const { data } = await publishFlow(
apiRequest,
tokenJsonResponse.data.token,
flowId
);
const triggerStepWebhookUrl = data.steps.find(
(step) => step.type === 'trigger'
).webhookUrl;
await triggerFlow(apiRequest, triggerStepWebhookUrl);
});
// no execution data exists in an empty account
test.describe.skip('Executions page', () => {
test.beforeEach(async ({ page }) => {
await page.getByTestId('executions-page-drawer-link').click();
await page.getByTestId('execution-row').first().click();
await expect(page).toHaveURL(/\/executions\//);
});
test('displays data in by default', async ({ page, executionsPage }) => {
await expect(page.getByTestId('execution-step').last()).toBeVisible();
await expect(page.getByTestId('execution-step')).toHaveCount(2);
test('show correct step data for trigger and actions on test and non-test execution', async ({
page,
executionsPage,
executionDetailsPage,
}) => {
await executionsPage.executionsPageLoader.waitFor({
state: 'detached',
});
const flowExecutions = await executionsPage.executionRow.filter({
hasText: flowId,
});
await test.step('show only trigger step on test execution', async () => {
await expect(flowExecutions.last()).toContainText('Test run');
await flowExecutions.last().click();
await executionsPage.screenshot({
path: 'Execution - data in.png',
await executionDetailsPage.verifyExecutionData(flowId);
await expect(executionDetailsPage.executionStep).toHaveCount(1);
const executionStepDetails = new ExecutionStepDetails(
page,
executionDetailsPage.executionStep.last()
);
await executionStepDetails.verifyTriggerExecutionStep({
stepPositionAndName: '1. Webhook',
stepDataInKey: 'workSynchronously',
stepDataInValue: 'workSynchronously',
stepDataOutKey: 'host',
stepDataOutValue: 'localhost',
});
await page.goBack();
});
await test.step('show trigger and action step on action test execution', async () => {
await expect(flowExecutions.nth(1)).toContainText('Test run');
await flowExecutions.nth(1).click();
await expect(executionDetailsPage.executionStep).toHaveCount(2);
await executionDetailsPage.verifyExecutionData(flowId);
const firstExecutionStepDetails = new ExecutionStepDetails(
page,
executionDetailsPage.executionStep.first()
);
await firstExecutionStepDetails.verifyTriggerExecutionStep({
stepPositionAndName: '1. Webhook',
stepDataInKey: 'workSynchronously',
stepDataInValue: 'workSynchronously',
stepDataOutKey: 'host',
stepDataOutValue: 'localhost',
});
const lastExecutionStepDetails = new ExecutionStepDetails(
page,
executionDetailsPage.executionStep.last()
);
await lastExecutionStepDetails.verifyActionExecutionStep({
stepPositionAndName: '2. Webhook',
stepDataInKey: 'body',
stepDataInValue: 'body:"ok"',
stepDataOutKey: 'body',
stepDataOutValue: 'body:"ok"',
});
await page.goBack();
});
await test.step('show trigger and action step on flow execution', async () => {
await expect(flowExecutions.first()).not.toContainText('Test run');
await flowExecutions.first().click();
await expect(executionDetailsPage.executionStep).toHaveCount(2);
await executionDetailsPage.verifyExecutionData(flowId);
const firstExecutionStepDetails = new ExecutionStepDetails(
page,
executionDetailsPage.executionStep.first()
);
await firstExecutionStepDetails.verifyTriggerExecutionStep({
stepPositionAndName: '1. Webhook',
stepDataInKey: 'workSynchronously',
stepDataInValue: 'workSynchronously',
stepDataOutKey: 'host',
stepDataOutValue: 'localhost',
});
const lastExecutionStepDetails = new ExecutionStepDetails(
page,
executionDetailsPage.executionStep.last()
);
await lastExecutionStepDetails.verifyActionExecutionStep({
stepPositionAndName: '2. Webhook',
stepDataInKey: 'body',
stepDataInValue: 'body:"ok"',
stepDataOutKey: 'body',
stepDataOutValue: 'body:"ok"',
});
});
});
test('displays data out', async ({ page, executionsPage }) => {
const executionStepCount = await page.getByTestId('execution-step').count();
for (let i = 0; i < executionStepCount; i++) {
await page.getByTestId('data-out-tab').nth(i).click();
await expect(page.getByTestId('data-out-panel').nth(i)).toBeVisible();
await executionsPage.screenshot({
path: `Execution - data out - ${i}.png`,
animations: 'disabled',
});
}
});
test('does not display error', async ({ page }) => {
await expect(page.getByTestId('error-tab')).toBeHidden();
});
});

View File

@@ -1,17 +1,54 @@
const { request } = require('@playwright/test');
const { test, expect } = require('../../fixtures/index');
const {
triggerFlow,
publishFlow,
addWebhookFlow,
} = require('../../helpers/flow-api-helper');
const { getToken } = require('../../helpers/auth-api-helper');
test.describe('Executions page', () => {
let flowId;
test.beforeAll(async () => {
const apiRequest = await request.newContext();
const tokenJsonResponse = await getToken(apiRequest);
flowId = await addWebhookFlow(apiRequest, tokenJsonResponse.data.token);
const { data } = await publishFlow(
apiRequest,
tokenJsonResponse.data.token,
flowId
);
const triggerStepWebhookUrl = data.steps.find(
(step) => step.type === 'trigger'
).webhookUrl;
await triggerFlow(apiRequest, triggerStepWebhookUrl);
});
test.beforeEach(async ({ page }) => {
await page.getByTestId('executions-page-drawer-link').click();
});
// no executions exist in an empty account
test.skip('displays executions', async ({ page, executionsPage }) => {
await page.getByTestId('executions-loader').waitFor({
test('should be able to see normal and test executions', async ({
executionsPage,
}) => {
await executionsPage.executionsPageLoader.waitFor({
state: 'detached',
});
await expect(page.getByTestId('execution-row').first()).toBeVisible();
const flowExecutions = await executionsPage.executionRow.filter({
hasText: flowId,
});
await executionsPage.screenshot({ path: 'Executions.png' });
await expect(flowExecutions).toHaveCount(4);
await expect(flowExecutions.first()).toContainText('Success');
await expect(flowExecutions.first()).not.toContainText('Test run');
for (let testFlow = 1; testFlow < 4; testFlow++) {
await expect(flowExecutions.nth(testFlow)).toContainText('Test run');
await expect(flowExecutions.nth(testFlow)).toContainText('Success');
}
});
});

View File

@@ -10,7 +10,7 @@ import { ExecutionPropType } from 'propTypes/propTypes';
function ExecutionName(props) {
return (
<Typography variant="h3" gutterBottom>
<Typography data-test="execution-name" variant="h3" gutterBottom>
{props.name}
</Typography>
);
@@ -29,7 +29,7 @@ function ExecutionId(props) {
);
return (
<Box sx={{ display: 'flex' }}>
<Typography variant="body2">
<Typography data-test="execution-id" variant="body2">
{formatMessage('execution.id', { id })}
</Typography>
</Box>
@@ -47,7 +47,7 @@ function ExecutionDate(props) {
<Tooltip
title={createdAt.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)}
>
<Typography variant="body1" gutterBottom>
<Typography data-test="execution-created-at" variant="body1" gutterBottom>
{relativeCreatedAt}
</Typography>
</Tooltip>

View File

@@ -36,7 +36,11 @@ function ExecutionStepId(props) {
return (
<Box sx={{ display: 'flex' }} gridArea="id">
<Typography variant="caption" fontWeight="bold">
<Typography
data-test="execution-step-id"
variant="caption"
fontWeight="bold"
>
{formatMessage('executionStep.id', { id })}
</Typography>
</Box>
@@ -56,7 +60,11 @@ function ExecutionStepDate(props) {
<Tooltip
title={createdAt.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)}
>
<Typography variant="caption" gutterBottom>
<Typography
data-test="execution-step-executed-at"
variant="caption"
gutterBottom
>
{formatMessage('executionStep.executedAt', {
datetime: relativeCreatedAt,
})}
@@ -119,12 +127,12 @@ function ExecutionStep(props) {
<ExecutionStepId id={executionStep.step.id} />
<Box flex="1" gridArea="step">
<Typography variant="caption">
<Typography data-test="step-type" variant="caption">
{isTrigger && formatMessage('flowStep.triggerType')}
{isAction && formatMessage('flowStep.actionType')}
</Typography>
<Typography variant="body2">
<Typography data-test="step-position-and-name" variant="body2">
{step.position}. {app?.name}
</Typography>
</Box>
@@ -152,7 +160,7 @@ function ExecutionStep(props) {
</Tabs>
</Box>
<TabPanel value={activeTabIndex} index={0}>
<TabPanel value={activeTabIndex} index={0} data-test="data-in-panel">
<SearchableJSONViewer data={executionStep.dataIn} />
</TabPanel>