This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create basic redux actions unit tests * Update jest collect coverage settings * Write basic reducer integration test * Remove redux actions unit tests - we are testing action in our reducer integration test * Add react-testing-library and jest-styled-components dependencies * Create basic button component unit test * Create basic button component snapshot * Create test case for disabled button - just to show how coverage works and why button was not 100 % covered * Create failing test for not found page * Create successful test for not found page - create render with router helper - create basic test case * Create basic products list snapshot test * Create basic products list snapshot test when products loaded * Fix react-testing-library react-hooks errors * Add jest-mock dependency * Added CartItem product id into array * Getting rid of classes * Adding number of products per size selector * Refactored getting url params in product list * Mock Fetch requests - add fetch-mock dev dependency - mock GET /api/skus - mock POST /oauth/token * ramdify * Create basic tests for product detail page * Create basic tests for cart page - initialize redux store with mock data - update cart item component so that we can differentiate between loaded and not loaded state * Use routes constants instead of hard-coded routes * Create basic test for not-logged-in user on account page * Create basic test user account page * Create basic signup page test * Write advanced tests for signup page - test unsuccessful submit - test successful submit * Replace hard-coded user data with constant mock user data * Write tests for sign in page * Update products list snapshot * Fix typo * Polish source code * Make store mock nicer * Detect account page by page-id * Fix snapshot tests * Install cypress * Initialize cypress * Add eslint-plugin-cypress * Fix cypress base url * Write basic cypress test * Fix cypress test * Resolve tasks from code review - fix naming in reducer test - rename test files from index.test.js to [testee].test.js - replace some snapshots with normal jest expectations * Run tests before every commit * Add cross-env * Revert "Add cross-env" This reverts commit 0ceeb98 * Revert "Run tests before every commit" This reverts commit c6635c0 * Recover README files 💣
- Loading branch information
1 parent
af41308
commit 9502fdc
Showing
38 changed files
with
1,766 additions
and
53 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
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,3 @@ | ||
{ | ||
"baseUrl": "http://localhost:3000" | ||
} |
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 @@ | ||
{} |
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 @@ | ||
describe('home page', () => { | ||
it('should display home page', () => { | ||
cy.visit('/products') | ||
// Find first Add To Cart button | ||
cy.get('button') | ||
.eq(0) | ||
.click() // put the product into shopping cart | ||
// Find second Add To Cart button | ||
cy.get('button') | ||
.eq(1) | ||
.click() // put the product into shopping cart | ||
.click() // put the product into shopping cart | ||
// Navigate to shopping cart | ||
cy.contains('My Cart').click() | ||
// Expect to have 2 different products in shopping cart | ||
cy.get('li').should('have.length', 2) | ||
}) | ||
}) |
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,17 @@ | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
module.exports = () => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
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,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 is will overwrite an existing command -- | ||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) |
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,20 @@ | ||
// *********************************************************** | ||
// This example support/index.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') |
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
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
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,20 @@ | ||
import React from 'react' | ||
import { render } from 'react-testing-library' | ||
import 'jest-styled-components' | ||
|
||
import Button from '../index' | ||
|
||
// This is just an example how to test components | ||
describe('[components] Button', () => { | ||
it('should render correctly', () => { | ||
const renderer = render(<Button>My Button</Button>) | ||
expect(renderer.container).toMatchSnapshot() | ||
}) | ||
|
||
describe('when disabled', () => { | ||
it('should render correctly', () => { | ||
const renderer = render(<Button disabled>My Button</Button>) | ||
expect(renderer.container).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
src/components/Button/test/__snapshots__/Button.test.js.snap
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,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`[components] Button should render correctly 1`] = ` | ||
.c0 { | ||
background: #ef0d33; | ||
cursor: pointer; | ||
padding: 1rem; | ||
margin-top: 0.5rem; | ||
border: none; | ||
border-radius: 5px; | ||
color: #fff; | ||
} | ||
<div> | ||
<button | ||
class="c0" | ||
> | ||
My Button | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`[components] Button when disabled should render correctly 1`] = ` | ||
.c0 { | ||
background: #e5e5e5; | ||
cursor: default; | ||
padding: 1rem; | ||
margin-top: 0.5rem; | ||
border: none; | ||
border-radius: 5px; | ||
color: #fff; | ||
} | ||
<div> | ||
<button | ||
class="c0" | ||
disabled="" | ||
> | ||
My Button | ||
</button> | ||
</div> | ||
`; |
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
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
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
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,36 @@ | ||
import React from 'react' | ||
import 'jest-styled-components' | ||
|
||
import { App } from '../../../App' | ||
import * as routes from '../../../routes' | ||
import { renderWithRouter } from '../../../utilsTest/render' | ||
import { configureStore } from '../../../store' | ||
import { USER } from '../../../utilsTest/mockData' | ||
|
||
describe('[pages] Account', () => { | ||
describe('when not logged in', () => { | ||
it('should redirect to login page', () => { | ||
const renderer = renderWithRouter(<App />, routes.ACCOUNT) | ||
const HTMLDivElement = renderer.getByTestId('login-page') | ||
expect(HTMLDivElement).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('when logged in', () => { | ||
it('should render private user account page', () => { | ||
const store = configureStore({ | ||
customer: { | ||
attributes: { | ||
metadata: { | ||
firstName: USER.firstName, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
const renderer = renderWithRouter(<App store={store} />, routes.ACCOUNT) | ||
const H1HtmlElement = renderer.getByTestId('account-page') | ||
expect(H1HtmlElement).toBeTruthy() | ||
}) | ||
}) | ||
}) |
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
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,37 @@ | ||
import React from 'react' | ||
import { waitForElement } from 'react-testing-library' | ||
import 'jest-styled-components' | ||
|
||
import { App } from '../../../App' | ||
import * as routes from '../../../routes' | ||
import { renderWithRouter } from '../../../utilsTest/render' | ||
import { mockFetchProduct } from '../../../utilsTest/mockHelpers' | ||
import { configureStore } from '../../../store' | ||
import { getCustomer } from '../../../utils/customer' | ||
|
||
describe('[pages] Cart', () => { | ||
describe('when loading', () => { | ||
it('should render correctly', () => { | ||
const renderer = renderWithRouter(<App />, routes.CART) | ||
expect(renderer.container).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('when products loaded', () => { | ||
mockFetchProduct() | ||
|
||
it('should render correctly', async () => { | ||
const productId = 1 | ||
const store = configureStore({ | ||
customer: getCustomer(), | ||
cart: { | ||
[productId]: productId, | ||
}, | ||
}) | ||
|
||
const renderer = renderWithRouter(<App store={store} />, routes.CART) | ||
await waitForElement(() => renderer.getByTestId('product-in-cart')) | ||
expect(renderer.getAllByTestId('product-in-cart').length).toEqual(1) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.