Skip to content

Commit

Permalink
Merge pull request #7 from wexnox/workflow_End-to-End-Testing
Browse files Browse the repository at this point in the history
Workflow end to end testing
  • Loading branch information
wexnox authored Aug 20, 2023
2 parents baf3a1e + 363d5de commit 691173b
Show file tree
Hide file tree
Showing 12 changed files with 1,895 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintcache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/login.js":"1","/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/login.test.js":"2","/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/logout.test.js":"3","/Users/lasseronningen/Sites/WorkflowCA/src/js/storage/index.js":"4","/Users/lasseronningen/Sites/WorkflowCA/src/js/storage/localStorageMock.js":"5","/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/createPost.cy.js":"6","/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/login.cy.js":"7","/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/logout.cy.js":"8"},{"size":593,"mtime":1692549155944,"results":"9","hashOfConfig":"10"},{"size":1556,"mtime":1692551277305,"results":"11","hashOfConfig":"10"},{"size":629,"mtime":1692551512666,"results":"12","hashOfConfig":"10"},{"size":83,"mtime":1692549155942,"results":"13","hashOfConfig":"10"},{"size":292,"mtime":1692551746655,"results":"14","hashOfConfig":"10"},{"size":1535,"mtime":1692560463222,"results":"15","hashOfConfig":"16"},{"size":2390,"mtime":1692560338617,"results":"17","hashOfConfig":"16"},{"size":1003,"mtime":1692560187159,"results":"18","hashOfConfig":"16"},{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1jrrb2y",{"filePath":"22","messages":"23","suppressedMessages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","suppressedMessages":"36","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"oqzilt",{"filePath":"37","messages":"38","suppressedMessages":"39","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","suppressedMessages":"42","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/login.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/login.test.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/src/js/api/auth/logout.test.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/src/js/storage/index.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/src/js/storage/localStorageMock.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/createPost.cy.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/login.cy.js",[],[],"/Users/lasseronningen/Sites/WorkflowCA/cypress/e2e/logout.cy.js",[],[]]
30 changes: 17 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
"extends": "eslint:recommended",
"overrides": [
{
"files": [
"**/*.test.js"
],
"env": {
"jest": true
},
"plugins": [
"jest"
],
"extends": [
"plugin:jest/recommended"
],
"files": ["**/*.test.js"],
"env": {"jest": true},
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": {
"jest/prefer-expect-assertions": "off"
"jest/prefer-expect-assertions": "off",
"no-undef": "off",
"no-unused-vars": "off"
}
},
{
"files": ["**/*.cy.js"],
"env": {"cypress/globals": true},
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"rules": {
"cypress/no-unnecessary-waiting": "off",
"no-unused-vars": "off"
}
}
],
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/node_modules
/dist/*
.env
#**/*.config.js

/cypress/screenshots
/cypress/support
/cypress/videos
/.eslintcache
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Description of the project

[Github Pages link](https://wexnox.github.io/WorkflowCA/)

## Goal
Using the skills and knowledge from this course, improve the quality of a package by establishing helpful workflows that make the development process more efficient.

Expand Down
3 changes: 0 additions & 3 deletions TODO.md

This file was deleted.

9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
51 changes: 51 additions & 0 deletions cypress/e2e/createPost.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe("Login and validate user input", () => {
beforeEach(() => {
cy.clearLocalStorage();
cy.visit("http://127.0.0.1:5555/");

cy.wait(800);
cy.get(".btn-close:visible").click({ force: true });
cy.get("button[data-auth='login']:visible").click({ force: true });

cy.wait(800);
cy.get("input[type='email']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");

cy.get("input[type='password']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");
cy.get(".btn-success:visible").click({ force: true });

cy.wait(800);
cy.then(() => expect(window.localStorage.getItem("token")).to.not.be.null);
cy.then(
() => expect(window.localStorage.getItem("profile")).to.not.be.null,
);
cy.url().should("include", "profile");
});

it("It validates post title input", () => {
cy.get("footer [data-visible='loggedIn']:visible")
.contains("New Post")
.click();

cy.get("#postTitle:visible").should("exist");

cy.get("#postTitle:visible").type("New blog post title");

cy.get("#postTitle:visible").should("have.value", "New blog post title");

cy.get("#postTags:visible").should("exist").type("Bob is your uncle");

cy.get("#postMedia:visible")
.should("exist")
.type("https://picsum.photos/200/300");

cy.get("#postBody:visible").should("exist").type("m0000");

cy.get("span[data-action='publish']:visible").should("exist").click();

cy.url().should("include", "post");
});
});
77 changes: 77 additions & 0 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
describe("Login to app", () => {
beforeEach(() => {
cy.visit("http://127.0.0.1:5555/");
cy.clearLocalStorage();
});

it("It can login successfully", () => {
cy.visit("http://127.0.0.1:5555/");

cy.wait(800);
cy.get(".btn-close:visible").click({ force: true });
cy.get("button[data-auth='login']:visible").click({ force: true });

cy.wait(2000);
cy.get("input[type='email']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");

cy.get("input[type='password']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");
cy.get(".btn-success:visible").click({ force: true });

cy.wait(600);
cy.then(
() => expect(window.localStorage.getItem("profile")).to.not.be.null,
);
cy.then(() => expect(window.localStorage.getItem("token")).to.not.be.null);
cy.url().should("include", "profile");
});

it("It tries to validates fake email input", () => {
cy.visit("http://127.0.0.1:5555/");

cy.wait(800);
cy.get(".btn-close:visible").click({ force: true });
cy.get("button[data-auth='login']:visible").click({ force: true });

cy.wait(2000);
cy.get("input[type='email']:visible")
.should("exist")
.type("faketrude@fakeemail.com");

cy.get("input[type='password']:visible")
.should("exist")
.type("trudesfakepassword");
cy.get(".btn-success:visible").click({ force: true });

cy.wait(2000);
cy.then(() => expect(window.localStorage.getItem("token")).to.be.null);
cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null);
cy.url().should("not.include", "profile");
});

it("It validates password", () => {
cy.visit("http://127.0.0.1:5555/");

cy.wait(800);
cy.get(".btn-close:visible").click();
cy.get("button[data-auth='login']:visible").click({ force: true });

cy.wait(2000);
cy.get("input[type='email']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");

cy.get("input[type='password']:visible")
.should("exist")
.type("bobbyfrida@stud.noroff.no");
cy.get(".btn-success:visible").click({ force: true });

cy.wait(2000);
cy.then(() => expect(window.localStorage.getItem("token")).to.exist);
cy.then(() => expect(window.localStorage.getItem("profile")).to.exist);
cy.url().should("include", "profile");
});
});
38 changes: 38 additions & 0 deletions cypress/e2e/logout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("Logout of App", () => {
beforeEach(() => {
cy.visit("http://127.0.0.1:5555/");
cy.clearLocalStorage();
});

it("It can logout the current user", () => {
cy.get("#registerModalLabel")
.should("have.text", "Create Profile")
.should("be.visible");

cy.wait(800);
cy.get("#registerForm")
.find(".btn-outline-success")
.should("be.visible")
.click({ force: true });
cy.get("#loginModalLabel")
.should("have.text", "Login")
.should("be.visible");

cy.wait(800);
cy.get("#loginEmail").type("bobbyfrida@stud.noroff.no");
cy.get("#loginPassword").type("bobbyfrida@stud.noroff.no");

cy.wait(800);
cy.get("#loginForm .btn-success")
.should("be.visible")
.click({ force: true });

cy.wait(800);
cy.get("button[data-auth='logout']")
.should("be.visible")
.click({ force: true });
cy.then(() => {
expect(window.localStorage.getItem("token")).to.be.null;
});
});
});
Loading

0 comments on commit 691173b

Please sign in to comment.