Skip to content

Commit

Permalink
feat: dashboard E2E tests migrated from main repo (#669)
Browse files Browse the repository at this point in the history
* E2E tests migrated from main repo

* E2E tests migrated from main repo - dir change

* updated after linter

* updated after linter

* updated after linter

* typo fixed

* semicolons

* fixes after eslint

* fixes after eslint
  • Loading branch information
tkonieczny authored May 16, 2023
1 parent 611f7e2 commit 2d22d89
Show file tree
Hide file tree
Showing 21 changed files with 1,152 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/dashboard-e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_URL=http://localhost:8080
API_URL=localhost:8088/v1
4 changes: 4 additions & 0 deletions test/dashboard-e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
148 changes: 148 additions & 0 deletions test/dashboard-e2e/api/api-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import superagent from 'superagent';

export class ApiHelpers {
constructor(apiUrl) {
this.API_URL = apiUrl;
}

async getTests() {
const request = `${this.API_URL}/tests`;

try {
const response = await superagent.get(request);

return response.body;
} catch (e) {
throw Error(`getTests failed on "${request}" with: "${e}"`);
}
}

async createTest(testData) {
const request = `${this.API_URL}/tests`;

try {
const response = await superagent.post(request)
.set('Content-Type', 'application/json')
.send(testData);

return response.body;
} catch (e) {
throw Error(`createTest failed on "${request}" with: "${e}"`);
}
}

async abortTest(testName, executionId) {
const request = `${this.API_URL}/tests/${testName}/executions/${executionId}`;

try {
const response = await superagent.patch(request);

return response;
} catch (e) {
throw Error(`abortTest failed on "${request}" with: "${e}"`);
}
}

async removeTest(testName) {
const request = `${this.API_URL}/tests/${testName}`;

try {
await superagent.delete(request);
} catch (e) {
throw Error(`removeTest failed on "${request}" with: "${e}"`);
}
}

async updateTest(testData) {
const request = `${this.API_URL}/tests/${testData.name}`;

try {
const response = await superagent.patch(request)
.set('Content-Type', 'application/json')
.send(testData);

return response.body;
} catch (e) {
throw Error(`updateTest failed on "${request}" with: "${e}"`);
}
}

async isTestCreated(testName) {
try {
const currentTests = await this.getTests();
const test = currentTests.find(singleTest => singleTest.name === testName);

if(test !== undefined) {
return true;
}

return false;
} catch (e) {
throw Error(`isTestCreated failed for "${testName}" with: "${e}"`);
}
}

async assureTestNotCreated(testName) {
try {
const alreadyCreated = await this.isTestCreated(testName);
if(alreadyCreated) {
await this.removeTest(testName);
}

return true;
} catch (e) {
throw Error(`assureTestNotCreated failed for "${testName}" with: "${e}"`);
}
}

async assureTestCreated(testData, fullCleanup=false) {
try {
const alreadyCreated = await this.isTestCreated(testData.name);

if(alreadyCreated) {
if(fullCleanup) {
await this.removeTest(testData.name);
await this.createTest(testData);
} else {
await this.updateTest(testData);
}
} else {
await this.createTest(testData);
}
} catch (e) {
throw Error(`assureTestCreated failed for "${testData.name}" with: "${e}"`);
}
}

async getTestData(testName) {
const request = `${this.API_URL}/tests/${testName}`;

try {
const response = await superagent.get(request);

return response.body;
} catch (e) {
throw Error(`getTestData failed on "${request}" with: "${e}"`);
}
}

async getLastExecutionNumber(testName) {
const request = `${this.API_URL}/tests/${testName}/executions`;

try {
const response = await superagent.get(request);
const totalsResults = response.body.totals.results;

if(totalsResults === 0) {
return totalsResults;
}

const lastExecutionResults = response.body.results[0];

return lastExecutionResults.number;

} catch (e) {
throw Error(`getLastExecutionNumber failed on "${request}" with: "${e}"`);
}
}
}
7 changes: 7 additions & 0 deletions test/dashboard-e2e/data-handlers/test-data-handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import testsData from '../fixtures/tests.json';

export class TestDataHandler {
static getTest(testName) {
return testsData[testName];
}
}
130 changes: 130 additions & 0 deletions test/dashboard-e2e/fixtures/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cypress-git": {
"name": "internal-dashboard-e2e-cypress-git",
"type": "cypress/project",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/cypress/executor-tests/cypress-without-envs"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"cypress-git-created": {
"name": "internal-dashboard-e2e-cypress-git-created",
"type": "cypress/project",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/cypress/executor-tests/cypress-without-envs"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"k6-git": {
"name": "internal-dashboard-e2e-k6-git",
"type": "k6/script",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/k6/executor-tests/k6-smoke-test-without-envs.js"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"k6-git-created": {
"name": "internal-dashboard-e2e-k6-git-created",
"type": "k6/script",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/k6/executor-tests/k6-smoke-test-without-envs.js"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"postman-git": {
"name": "internal-dashboard-e2e-postman-git",
"type": "postman/collection",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/postman/executor-tests/postman-executor-smoke-without-envs.postman_collection.json"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"postman-git-created": {
"name": "internal-dashboard-e2e-postman-git-created",
"type": "postman/collection",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/postman/executor-tests/postman-executor-smoke-without-envs.postman_collection.json"
}
},
"labels": {
"core-tests": "dashboard-e2e-internal"
}
},
"postman-negative-test": {
"name": "internal-dashboard-e2e-postman-git-ran-negative-test",
"type": "postman/collection",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "main",
"path": "test/postman/executor-tests/postman-executor-smoke.postman_collection.json"
}
},
"labels": {
"core-tests": "cli-internal"
}
},
"postman-negative-init": {
"name": "internal-dashboard-e2e-postman-git-ran-negative-init",
"type": "postman/collection",
"content": {
"type": "git",
"repository": {
"type": "git",
"uri": "https://github.com/kubeshop/testkube",
"branch": "some-non-existing-branch",
"path": "some/incorrect/path/non-existing-file.json"
}
},
"labels": {
"core-tests": "cli-internal"
}
}
}
18 changes: 18 additions & 0 deletions test/dashboard-e2e/helpers/common-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from '@playwright/test';

export class CommonHelpers {
static validateTest(testData, createdTestData) {
expect(testData.name).toEqual(createdTestData.name);
// TODO: label
expect(testData.type).toEqual(createdTestData.type);
expect(testData.content.type).toEqual(createdTestData.content.type);

// testSources
const contentType = testData.content.type;
if (contentType === "git") {
for (let key in testData.content.repository) { // eslint-disable-line no-restricted-syntax, guard-for-in
expect(testData.content.repository[key]).toEqual(createdTestData.content.repository[key]);
}
}
}
}
Loading

0 comments on commit 2d22d89

Please sign in to comment.