-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dashboard E2E tests migrated from main repo (#669)
* 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
1 parent
611f7e2
commit 2d22d89
Showing
21 changed files
with
1,152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BASE_URL=http://localhost:8080 | ||
API_URL=localhost:8088/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.