Skip to content

Add Cypress #37

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

Merged
merged 5 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# testing
/coverage

/cypress/videos
/cypress/fixtures
/cypress/plugins
/cypress/support
/cypress/integration/examples

# production
/build

Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ script:
- yarn build
- yarn test
- yarn test:coverage
- yarn start:ci
- yarn cypress:run

after_success:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
Expand Down
4 changes: 4 additions & 0 deletions __tests__/components/__snapshots__/Header.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ exports[`<Header /> component renders with DARK theme 1`] = `
>
<button
className="c5"
data-cy="js"
onClick={[Function]}
>
<svg
Expand All @@ -194,6 +195,7 @@ exports[`<Header /> component renders with DARK theme 1`] = `
</button>
<button
className="c5"
data-cy="mode"
onClick={[Function]}
>
<svg
Expand Down Expand Up @@ -399,6 +401,7 @@ exports[`<Header /> component renders with LIGHT theme 1`] = `
>
<button
className="c5"
data-cy="js"
onClick={[Function]}
>
<svg
Expand All @@ -425,6 +428,7 @@ exports[`<Header /> component renders with LIGHT theme 1`] = `
</button>
<button
className="c5"
data-cy="mode"
onClick={[Function]}
>
<svg
Expand Down
4 changes: 4 additions & 0 deletions __tests__/components/__snapshots__/Toggle.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exports[`<Toggle /> renders JS toggle in DARK more 1`] = `
<div>
<button
className="c0"
data-cy="js"
onClick={[Function]}
>
<svg
Expand Down Expand Up @@ -105,6 +106,7 @@ exports[`<Toggle /> renders JS toggle in LIGHT more 1`] = `
<div>
<button
className="c0"
data-cy="js"
onClick={[Function]}
>
<svg
Expand Down Expand Up @@ -171,6 +173,7 @@ exports[`<Toggle /> renders the MODE toggle in DARK mode 1`] = `
<div>
<button
className="c0"
data-cy="mode"
onClick={[Function]}
>
<svg
Expand Down Expand Up @@ -231,6 +234,7 @@ exports[`<Toggle /> renders the MODE toggle in LIGHT mode 1`] = `
<div>
<button
className="c0"
data-cy="mode"
onClick={[Function]}
>
<svg
Expand Down
3 changes: 3 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projectId": "design-patterns-javascript"
}
60 changes: 60 additions & 0 deletions cypress/integration/about.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* globals context, cy */
context('About', () => {
beforeEach(() => {
cy.visit('http://localhost:8080/about');
});

describe('Header', () => {
it('should have 2 navigation links', () => {
cy.get('header a').should('have.length', 2);
});

it('should have _Game_ link', () => {
cy.get('header a')
.first()
.should('have.text', 'Game')
.should('have.attr', 'href')
.and('include', '/');
});

it('should have _Pattern Reference_ link', () => {
cy.get('header a:last')
.first()
.should('have.text', 'Pattern Reference')
.should('have.attr', 'href')
.and('include', '/patterns');
});

it('should have the current page title in a span', () => {
cy.get('header span')
.should('exist')
.should('have.text', 'About');
});

it('should have the MODE switch', () => {
cy.get('header button[data-cy=mode]').should('exist');
cy.get('header button[data-cy=mode]').should('be.visible');
});

it('should NOT have the JS switch', () => {
cy.get('header button[data-cy=js]').should('not.exist');
});
});

describe('Content', () => {
it('should have 2 section headers', () => {
cy.get('h3').should('have.length', 2);

cy.get('h3:first').should('have.text', 'The Game');
cy.get('h3:last').should('have.text', 'References');
});
});

describe('Behavior', () => {
it('should switch the mode', () => {
cy.get('body').should('have.css', 'background-color', 'rgb(34, 34, 34)');
cy.get('header button[data-cy=mode]').click();
cy.get('body').should('have.css', 'background-color', 'rgb(255, 255, 255)');
});
});
});
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
},
"scripts": {
"start": "webpack-dev-server --mode development",
"start:ci": "npm start & wait-on http://localhost:8080",
"format": "prettier --write \"src/**/*.js\"",
"stats": "webpack-bundle-analyzer stats/stats.json",
"build": "webpack --mode production",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook"
},
Expand All @@ -34,7 +37,8 @@
],
"testPathIgnorePatterns": [
"<rootDir>/__tests__/config/",
"<rootDir>/__tests__/helpers/"
"<rootDir>/__tests__/helpers/",
"<rootDir>/cypress/"
]
},
"devDependencies": {
Expand All @@ -55,6 +59,7 @@
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"coveralls": "^3.0.3",
"cypress": "^3.2.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.8.0",
"enzyme-to-json": "^3.3.5",
Expand All @@ -70,6 +75,7 @@
"redux-mock-store": "^1.5.3",
"storybook-addon-styled-component-theme": "^1.1.1",
"surge": "^0.20.1",
"wait-on": "^3.2.0",
"webpack": "^4.29.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toggle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Toggle = props => {
if (control === 'mode' && mode === 'light') isActive = 'active';

return (
<StyledToggle onClick={() => onToggle(control)} className={isActive}>
<StyledToggle onClick={() => onToggle(control)} className={isActive} data-cy={control}>
<SVG control={control} />
</StyledToggle>
);
Expand Down
Loading