Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow #459

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
45c13ed
testing
KariannNor Mar 20, 2024
67ff0db
Adds README
KariannNor Mar 20, 2024
41b4d4d
adds dependencies
KariannNor Mar 21, 2024
36add93
adds lint staged and husky
KariannNor Mar 21, 2024
4f8dec4
adds hooks
KariannNor Mar 21, 2024
32776c9
adds type to package
KariannNor Mar 21, 2024
c578652
adds Jest
KariannNor Mar 21, 2024
bd101b5
Adds Babel
KariannNor Mar 21, 2024
303bd25
installs Cypress
KariannNor Mar 22, 2024
6d734db
cionfigs cypress e2e-testing
KariannNor Mar 22, 2024
f73a35c
edited readme
KariannNor Apr 11, 2024
bdfe8f4
edits name and version
KariannNor Apr 11, 2024
fd487da
adds unit testing
KariannNor Apr 11, 2024
6fe4b84
adds a midification to the logout unit test
KariannNor Apr 11, 2024
6b02bc2
adds cypress script to package.json
KariannNor Apr 12, 2024
d97872a
ready to test cypress on login and logout
KariannNor Apr 12, 2024
0842ec3
cypress test - allows valid user to log in successfully
KariannNor Apr 16, 2024
03e2a2e
Cypress tests completed
KariannNor Apr 17, 2024
16f9736
README d
KariannNor Apr 17, 2024
44e12c8
edits logout.cy.js + README.md
KariannNor Apr 18, 2024
bad44fb
Edits readme.md
KariannNor Apr 19, 2024
bb49ca6
Edits cy. test after feedback
KariannNor Apr 19, 2024
d6c3cd6
Edits jest and cypress testing after feedback
KariannNor Apr 21, 2024
239e45c
edits the readme
KariannNor Apr 24, 2024
8160959
Merge branch 'workflow-test-branch'
KariannNor Apr 24, 2024
342c25a
status badge added
KariannNor Apr 24, 2024
63f4bce
edits cypress test on login and pages.yml on push to workflow branch
KariannNor Apr 24, 2024
fd3983d
Merge branch 'workflow-test-branch'
KariannNor Apr 24, 2024
cc536cd
badge applied
KariannNor Apr 24, 2024
42b34bd
updates a passing status badge
KariannNor Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"overrides": [
{
"files": ["**/*.test.js"],
"env": { "jest": true },
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": {
"jest/prefer-expect-assertions": "off",
"no-undef": "off"
}
},
{
"files": ["**/*.cy.js", "cypress.config.js"],
"env": { "cypress/globals": true },
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"rules": {
"cypress/no-unnecessary-waiting": "off",
"no-unused-vars": "off"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
}
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
branches: ["master", "workflow"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
/dist
/dist
.DS_Store
.eslintcache
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": false
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["javascript"]
}
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Workflow Course Assignment

[![Deploy static content to Pages](https://github.com/KariannNor/workflow-ca/actions/workflows/pages.yml/badge.svg?branch=workflow)](https://github.com/KariannNor/workflow-ca/actions/workflows/pages.yml)

## Description

This CA is focused on how to use the skills and knowledge from this course to improve the quality of a package by establishing helpful workflows that make the development process more efficient.

## Built with:

- HTML
- CSS
- SASS
- Bootstrap
- JavaScript

## Packages used

- NPM package manager
- Prettier
- ESLint
- Husky
- Jest
- Babel
- Cypress

## Getting started

### Installing

1. Clone the repo

```
git clone https://github.com/KariannNor/workflow-ca
```

2. Install dependencies

```
npm i
```

3. Build production files

```
npm run build
```

4. Other useful commands and formatting:

```
// sass and live server:
npm run start

// testing with Cypress:
npm run test-e2e

// unit tests with jest:
npm run test-unit

// prettier:
npm run format

// eslint:
npm run lint-fix
```
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
}
16 changes: 16 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "cypress";

export default defineConfig({
env: {
validEmail: "benny123@noroff.no",
validPassword: "11111111",
wrongEmail: "wrong@email.com",
wrongPassword: "wrongPassword",
},

e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
38 changes: 38 additions & 0 deletions cypress/e2e/testing/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("login", () => {
beforeEach(() => {
cy.visit("/");
});

it("Should deny an invalid user to log in and show error message", () => {
cy.wait(500);
cy.get("#registerForm .btn-close").click();
cy.get(`header button[data-bs-target="#loginModal"]`).click();
cy.wait(500);
cy.get("#loginForm").should("be.visible");
cy.get("#loginForm #loginEmail").type(Cypress.env("wrongEmail"));
cy.get("#loginForm #loginPassword").type(Cypress.env("wrongPassword"));
cy.get("button[type=submit]").contains("Login").click();
cy.wait(500);
cy.on("window:alert", (text) => {
expect(text).to.include(
"Either your username was not found or your password is incorrect",
);
});
cy.window()
.its("localStorage")
.invoke("getItem", "token")
.should("be.null");
});

it("should allow a valid user to log in", () => {
cy.wait(500);
cy.get("#registerForm .btn-close").click();
cy.get(`header button[data-bs-target="#loginModal"]`).click();
cy.wait(500);
cy.get("#loginForm").should("be.visible");
cy.get("#loginForm #loginEmail").type(Cypress.env("validEmail"));
cy.get("#loginForm #loginPassword").type(Cypress.env("validPassword"));
cy.get("button[type=submit]").contains("Login").click();
cy.get(`header button[data-auth="logout"]`).should("be.visible");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to see a local storage check here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback Oliver. I'll take a look at it.

});
});
29 changes: 29 additions & 0 deletions cypress/e2e/testing/logout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe("logout", () => {
it("should allow a valid user to log out", () => {
cy.visit("/");
cy.wait(500);

cy.get("#registerModal").contains("Login").click();
cy.wait(500);

cy.get("#loginForm").should("be.visible");
cy.get("#loginForm #loginEmail").type(Cypress.env("validEmail"));
cy.get("#loginForm #loginPassword").type(Cypress.env("validPassword"));
cy.get("button[type=submit]").contains("Login").click();
cy.wait(1000);

cy.window().then((window) => {
const token = window.localStorage.getItem("token");
expect(token).to.be.a("string");
cy.wait(500);

cy.get(`header button[data-auth="logout"]`).contains("Logout").click();
cy.wait(500);

cy.window().then((window) => {
const tokenAfterLogout = window.localStorage.getItem("token");
expect(tokenAfterLogout).to.be.null;
});
});
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading