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 CA #272

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Workflow CA #272

wants to merge 31 commits into from

Conversation

jkjode
Copy link

@jkjode jkjode commented Aug 25, 2023

My final pull request for Workflow CA

Summary by CodeRabbit

  • New Feature: Introduced automated testing workflows using GitHub Actions for both unit and E2E tests, enhancing the reliability of the codebase.
  • Test: Added comprehensive test suites using Cypress covering various aspects of the application, improving the coverage and robustness of our testing.
  • Chore: Implemented ESLint and Prettier for consistent code styling and linting, improving code readability and maintainability.
  • Test: Added a mock implementation of localStorage for testing purposes, allowing us to isolate and test storage-related functionalities effectively.
  • Chore: Integrated Husky Git hooks to enforce linting before commits, ensuring code quality at each commit stage.

@github-actions
Copy link

github-actions bot commented Aug 25, 2023

Image description CodeRabbit

Walkthrough

This pull request introduces a comprehensive testing suite with unit and E2E tests, automated workflows via GitHub Actions, and ESLint configuration. It also includes a mock implementation of localStorage for testing purposes, a new exported function with its test case, and Git hooks setup using Husky.

Changes

Files Summary
.eslintrc.json, .gitignore, README.md Introduced ESLint rules, set up a gitignore file, and updated README content.
.github/workflows/e2e-test.yml, .github/workflows/unit-test.yml, cypress/* Added automated testing workflows and various Cypress test suites covering different aspects of the application.
.husky/_/husky.sh, .husky/pre-commit Implemented shell scripts to set up hooks for the Husky Git tool.
es6.js, es6.test.js Introduced a new exported function called wait and added a test case for it.
src/js/index.js, src/js/mocks/localStorage.mock.js, src/js/storage/save.test.js Made minor changes to function calls and introduced a mock implementation of localStorage for testing purposes.

🐇💻

In the land where code rabbits dwell,

We weave our magic, casting a spell.

With tests and lints, we make it right,

Ensuring our code is always tight.

Through day and night, we hop and write,

Celebrating each successful pipeline flight! 🎉🚀


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 5cdcf16 and 691beb3 commits.
Files selected (37)
  • .eslintrc.json (1)
  • .github/workflows/e2e-test.yml (1)
  • .github/workflows/unit-test.yml (1)
  • .gitignore (1)
  • .husky/_/husky.sh (1)
  • .husky/pre-commit (1)
  • 6 (1)
  • README.md (1)
  • cypress.config.js (1)
  • cypress/e2e/1-getting-started/todo.cy.js (1)
  • cypress/e2e/2-advanced-examples/actions.cy.js (1)
  • cypress/e2e/2-advanced-examples/aliasing.cy.js (1)
  • cypress/e2e/2-advanced-examples/assertions.cy.js (1)
  • cypress/e2e/2-advanced-examples/connectors.cy.js (1)
  • cypress/e2e/2-advanced-examples/cookies.cy.js (1)
  • cypress/e2e/2-advanced-examples/cypress_api.cy.js (1)
  • cypress/e2e/2-advanced-examples/files.cy.js (1)
  • cypress/e2e/2-advanced-examples/location.cy.js (1)
  • cypress/e2e/2-advanced-examples/misc.cy.js (1)
  • cypress/e2e/2-advanced-examples/navigation.cy.js (1)
  • cypress/e2e/2-advanced-examples/network_requests.cy.js (1)
  • cypress/e2e/2-advanced-examples/querying.cy.js (1)
  • cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js (1)
  • cypress/e2e/2-advanced-examples/storage.cy.js (1)
  • cypress/e2e/2-advanced-examples/traversal.cy.js (1)
  • cypress/e2e/2-advanced-examples/utilities.cy.js (1)
  • cypress/e2e/2-advanced-examples/viewport.cy.js (1)
  • cypress/e2e/2-advanced-examples/waiting.cy.js (1)
  • cypress/e2e/2-advanced-examples/window.cy.js (1)
  • cypress/e2e/E2E-test/e2e.test.js (1)
  • cypress/support/commands.js (1)
  • cypress/support/e2e.js (1)
  • es6.js (1)
  • es6.test.js (1)
  • src/js/index.js (1)
  • src/js/mocks/localStorage.mock.js (1)
  • src/js/storage/save.test.js (1)
Files ignored due to filter (28)
  • babel.config.json
  • cypress/fixtures/example.json
  • cypress/fixtures/profile.json
  • cypress/fixtures/users.json
  • cypress/screenshots/2-advanced-examples/misc.cy.js/my-image.png
  • cypress/videos/1-getting-started/todo.cy.js.mp4
  • cypress/videos/2-advanced-examples/actions.cy.js.mp4
  • cypress/videos/2-advanced-examples/aliasing.cy.js.mp4
  • cypress/videos/2-advanced-examples/assertions.cy.js.mp4
  • cypress/videos/2-advanced-examples/connectors.cy.js.mp4
  • cypress/videos/2-advanced-examples/cookies.cy.js.mp4
  • cypress/videos/2-advanced-examples/cypress_api.cy.js.mp4
  • cypress/videos/2-advanced-examples/files.cy.js.mp4
  • cypress/videos/2-advanced-examples/location.cy.js.mp4
  • cypress/videos/2-advanced-examples/misc.cy.js.mp4
  • cypress/videos/2-advanced-examples/navigation.cy.js.mp4
  • cypress/videos/2-advanced-examples/network_requests.cy.js.mp4
  • cypress/videos/2-advanced-examples/querying.cy.js.mp4
  • cypress/videos/2-advanced-examples/spies_stubs_clocks.cy.js.mp4
  • cypress/videos/2-advanced-examples/storage.cy.js.mp4
  • cypress/videos/2-advanced-examples/traversal.cy.js.mp4
  • cypress/videos/2-advanced-examples/utilities.cy.js.mp4
  • cypress/videos/2-advanced-examples/viewport.cy.js.mp4
  • cypress/videos/2-advanced-examples/waiting.cy.js.mp4
  • cypress/videos/2-advanced-examples/window.cy.js.mp4
  • cypress/videos/3-testing/no.wikipedia.cy.js.mp4
  • package-lock.json
  • package.json
Files not summarized due to errors (1)
  • cypress/e2e/2-advanced-examples/actions.cy.js (diff tokens exceeds limit)
Files skipped from review due to trivial changes (23)
  • .eslintrc.json
  • .github/workflows/e2e-test.yml
  • .github/workflows/unit-test.yml
  • .gitignore
  • .husky/_/husky.sh
  • .husky/pre-commit
  • cypress/e2e/2-advanced-examples/aliasing.cy.js
  • cypress/e2e/2-advanced-examples/cookies.cy.js
  • cypress/e2e/2-advanced-examples/files.cy.js
  • cypress/e2e/2-advanced-examples/location.cy.js
  • cypress/e2e/2-advanced-examples/misc.cy.js
  • cypress/e2e/2-advanced-examples/navigation.cy.js
  • cypress/e2e/2-advanced-examples/network_requests.cy.js
  • cypress/e2e/2-advanced-examples/querying.cy.js
  • cypress/e2e/2-advanced-examples/storage.cy.js
  • cypress/e2e/2-advanced-examples/utilities.cy.js
  • cypress/e2e/2-advanced-examples/waiting.cy.js
  • cypress/e2e/2-advanced-examples/window.cy.js
  • cypress/support/commands.js
  • cypress/support/e2e.js
  • es6.js
  • src/js/index.js
  • src/js/storage/save.test.js
Review comments generated (17)
  • Review: 5
  • LGTM: 12

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

- Added a new files called "localStorage.mock.js" + "save.test.js"
- Unit testing for storing token on login with valid credentials and for clearing token when logout is clicked
- Added E2E testing for login, login error and logout
- Updated content of README.md

Choose a reason for hiding this comment

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

Image description CodeRabbit

It's a good practice to always end your files with a newline. This is because some tools like cat, awk, or vi might not process the file correctly if it doesn't end with a newline.

- Updated content of README.md
+ \ No newline at end of file

Comment on lines +1 to +98
/// <reference types="cypress" />

context('Connectors', () => {
beforeEach(() => {
cy.visit('https://example.cypress.io/commands/connectors')
})

it('.each() - iterate over an array of elements', () => {
// https://on.cypress.io/each
cy.get('.connectors-each-ul>li')
.each(($el, index, $list) => {
console.log($el, index, $list)
})
})

it('.its() - get properties on the current subject', () => {
// https://on.cypress.io/its
cy.get('.connectors-its-ul>li')
// calls the 'length' property yielding that value
.its('length')
.should('be.gt', 2)
})

it('.invoke() - invoke a function on the current subject', () => {
// our div is hidden in our script.js
// $('.connectors-div').hide()
cy.get('.connectors-div').should('be.hidden')

// https://on.cypress.io/invoke
// call the jquery method 'show' on the 'div.container'
cy.get('.connectors-div').invoke('show')

cy.get('.connectors-div').should('be.visible')
})

it('.spread() - spread an array as individual args to callback function', () => {
// https://on.cypress.io/spread
const arr = ['foo', 'bar', 'baz']

cy.wrap(arr).spread((foo, bar, baz) => {
expect(foo).to.eq('foo')
expect(bar).to.eq('bar')
expect(baz).to.eq('baz')
})
})

describe('.then()', () => {
it('invokes a callback function with the current subject', () => {
// https://on.cypress.io/then
cy.get('.connectors-list > li')
.then(($lis) => {
expect($lis, '3 items').to.have.length(3)
expect($lis.eq(0), 'first item').to.contain('Walk the dog')
expect($lis.eq(1), 'second item').to.contain('Feed the cat')
expect($lis.eq(2), 'third item').to.contain('Write JavaScript')
})
})

it('yields the returned value to the next command', () => {
cy.wrap(1)
.then((num) => {
expect(num).to.equal(1)

return 2
})
.then((num) => {
expect(num).to.equal(2)
})
})

it('yields the original subject without return', () => {
cy.wrap(1)
.then((num) => {
expect(num).to.equal(1)
// note that nothing is returned from this callback
})
.then((num) => {
// this callback receives the original unchanged value 1
expect(num).to.equal(1)
})
})

it('yields the value yielded by the last Cypress command inside', () => {
cy.wrap(1)
.then((num) => {
expect(num).to.equal(1)
// note how we run a Cypress command
// the result yielded by this Cypress command
// will be passed to the second ".then"
cy.wrap(2)
})
.then((num) => {
// this callback receives the value yielded by "cy.wrap(2)"
expect(num).to.equal(2)
})
})
})
})

Choose a reason for hiding this comment

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

Image description CodeRabbit

The code looks good overall, but there's a potential issue with the use of console.log in production code. It's generally not a good practice to leave console.log statements in your production code as it can expose sensitive information and clutter the console output.

      .each(($el, index, $list) => {
-       console.log($el, index, $list)
+       // console.log($el, index, $list) // Uncomment for debugging purposes
      })

6
Comment on lines +1 to +15

added 52 packages, and audited 371 packages in 3s

53 packages are looking for funding
run `npm fund` for details

4 high severity vulnerabilities

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

Choose a reason for hiding this comment

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

Image description CodeRabbit

This hunk seems to be the output of an npm install or similar command. It's generally not a good practice to include such outputs in your codebase, as they can quickly become outdated and may contain system-specific information. Instead, consider adding instructions in your README file about how to handle package installation and addressing potential vulnerabilities.

- 1: 
- 2: added 52 packages, and audited 371 packages in 3s
- 3: 
- 4: 53 packages are looking for funding
- 5:   run `npm fund` for details
- 6: 
- 7: 4 high severity vulnerabilities
- 8: 
- 9: To address issues that do not require attention, run:
- 10:   npm audit fix
- 11: 
- 12: To address all issues (including breaking changes), run:
- 13:   npm audit fix --force
- 14: 
- 15: Run `npm audit` for details.

Comment on lines +29 to +40

it("should log out successfully", () => {
// Log in first (you can use a custom Cypress command for login)
cy.login("validUsername", "validPassword"); // Implement the login command as per your app

// Locate and click the logout button
cy.get(".logout-button").click(); // Adjust the selector for the logout button

// Assert that the user is redirected to the login page or a success message is displayed
cy.url().should("include", "/login"); // Adjust the URL accordingly
});
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

In the test case "should log out successfully", it's assumed that the login operation is successful. However, if the login operation fails for some reason (e.g., due to a change in the application's login mechanism), this test will also fail, even though the logout functionality might be working correctly. To make your tests more independent and reliable, consider mocking the login state instead of actually logging in.

    it("should log out successfully", () => {
      // Log in first (you can use a custom Cypress command for login)
- 32:       cy.login("validUsername", "validPassword"); // Implement the login command as per your app
+ 32:       cy.setLoginState(); // Mock the login state
  
      // Locate and click the logout button
      cy.get(".logout-button").click(); // Adjust the selector for the logout button
  
      // Assert that the user is redirected to the login page or a success message is displayed
      cy.url().should("include", "/login"); // Adjust the URL accordingly
    });

cy.url().should("include", "/login"); // Adjust the URL accordingly
});
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

It's a good practice to end files with a newline character. This helps with version control systems like Git and tools like cat, sed, awk, etc. which may not behave as you expect without a newline at the end of the file.

  });
+ 42:   

Copy link
Collaborator

@Fermain Fermain left a comment

Choose a reason for hiding this comment

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

A few minor changes, but no valid Jest tests found matching the assignment criteria. Please update your repo with these additional tests to avoid a resit.

// please read our getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe('example to-do app', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove all of the example files that ship with Cypress

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should not commit video files as these will change often each time the test is run. Please delete these and change your settings to avoid producing videos in cypress.config.

@@ -0,0 +1,9 @@
import { wait } from "./es6";
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should remove all example/demo files before submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants