Skip to content
Open
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
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
language: node_js
node_js:
- v11

cache:
# cache both npm modules and Cypress binary
directories:
- ~/.npm
- ~/.cache
# install dependencies and check that Cypress can run
override:
- npm ci
- npm run cy:verify

script:
# run all Cypress tests
- npm run cy:run
# after all tests finish running we need
# to kill all background jobs (like "npm start &")
# this avoids flake in Travis jobs
- kill $(jobs -p) || true
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# time-calculator

[![XO code style][codestyle-image]][codestyle-url]
[![Cypress.io tests][cypress-image]][cypress-url]

[![Build Status][travis-image]][travis-url]
[![Dependency Status][depstat-image]][depstat-url]
Expand Down Expand Up @@ -28,3 +29,6 @@ MIT © [Vladimir Rodkin](https://github.com/VovanR)

[depstat-dev-url]: https://david-dm.org/VovanR/time-calculator
[depstat-dev-image]: https://david-dm.org/VovanR/time-calculator/dev-status.svg?style=flat-square

[cypress-url]: https://cypress.io
[cypress-image]: https://img.shields.io/badge/cypress.io-tests-green.svg?style=flat-square
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
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"
}
64 changes: 64 additions & 0 deletions cypress/integration/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* global describe beforeEach cy it */

// https://example.cypress.io/

const INPUT_PLACEHOLDER = `1h 30m
-45m
2h
1h`;
const OUTPUT_PLACEHOLDER = '3h 45m';

describe('time-calculator', () => {
beforeEach(() => {
cy.visit('index.html');
});

it('should loaded input focused', () => {
cy.focused().should('have.attr', 'id', 'time-calculator-input');
});

it('should loaded with placeholder demo', () => {
cy.get('#time-calculator-input').should('have.attr', 'placeholder', INPUT_PLACEHOLDER);
cy.get('#time-calculator-output').should('have.attr', 'placeholder', OUTPUT_PLACEHOLDER);
});

it('should calculate input time', () => {
cy.get('#time-calculator-input')
.type('1h 30m')
.type('\n')
.type('30m')
.type('\n')
.type('-5m')
.type('\n')
.type('-1h 5m');
cy.get('#time-calculator-output').should('have.value', '50m');
});

it('should respect time labels', () => {
cy.get('#time-calculator-input')
.type(`shower 20m
dress 10m
walk bus station 10m
sleep 35m
walk to work 10m
make coffee 10m`);
cy.get('#time-calculator-output').should('have.value', '95m');
});

it('should have output input read only', () => {
// TODO: Waiting for https://github.com/cypress-io/cypress/issues/1246
// cy.get('#time-calculator-output')
// .type('5h')
// .should('have.value', '');
cy.get('#time-calculator-output')
.should('have.attr', 'readonly', 'readonly');
});

it('should have copyright block with project source URL', () => {
cy.get('.copyright').should('have.attr', 'href', 'https://github.com/vovanr/time-calculator');
});

it('should have copyright block opens new tab URL', () => {
cy.get('.copyright').should('have.attr', 'target', '_blank');
});
});
17 changes: 17 additions & 0 deletions cypress/plugins/index.js
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, config */) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
22 changes: 22 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint import/no-unassigned-import:0 */

// ***********************************************************
// 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')
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
"author": "Vladimir Rodkin <mail@vovanr.com> (https://github.com/VovanR)",
"scripts": {
"start": "http-server .",
"test": "xo"
"test": "xo",
"cy:open": "cypress open",
"cy:verify": "cypress verify",
"cy:run": "cypress run"
},
"browser": "./js/index.js",
"keywords": [],
"dependencies": {},
"devDependencies": {
"cypress": "3.1.5",
"http-server": "^0.11.1",
"xo": "^0.24.0"
},
Expand Down