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

Add cypress. Add test for App nav. #8

Merged
merged 12 commits into from Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/README.md
Expand Up @@ -22,6 +22,10 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).

## Running Cypress Tests
mzastue marked this conversation as resolved.
Show resolved Hide resolved

Run `yarn cy:run`

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
2 changes: 2 additions & 0 deletions frontend/cypress.json
@@ -0,0 +1,2 @@
{
}
19 changes: 19 additions & 0 deletions frontend/cypress/integration/src/app_spec.ts
@@ -0,0 +1,19 @@
describe('App spec', () => {
beforeEach(() => {
cy.visit('/');
});

it('shows App nav', () => {
cy.get('ul.app__links').should('have.length', 1);
});

it('shows items in App nav', () => {
const expectedNavLinks = ['home', 'hello'];

cy.get('ul.app__links li').should($items => {
const linkTextes = $items.toArray().forEach((item, index) => {
expect(item).to.contain(expectedNavLinks[index]);
});
});
});
});
24 changes: 24 additions & 0 deletions frontend/cypress/plugins/index.js
@@ -0,0 +1,24 @@
/// <reference types="cypress" />
// ***********************************************************
// 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)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
on('task', {
protobufEncode: require('cypress-protobuf'),
});
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions frontend/cypress/support/commands.js
@@ -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 frontend/cypress/support/index.js
@@ -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')
13 changes: 13 additions & 0 deletions frontend/cypress/tsconfig.json
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts",
"../node_modules/cypress"
]
}
Binary file added frontend/cypress/videos/src/app_spec.ts.mp4
Binary file not shown.
8 changes: 6 additions & 2 deletions frontend/package.json
Expand Up @@ -8,7 +8,9 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"proto:generate": "protoc --plugin=protoc-gen-ng=./node_modules/.bin/protoc-gen-ng --ng_out=./src/app/proto -I ../services ../services/**/src/**/*.proto"
"proto:generate": "protoc --plugin=protoc-gen-ng=./node_modules/.bin/protoc-gen-ng --ng_out=./src/app/proto -I ../services ../services/**/src/**/*.proto",
"cy:open": "CYPRESS_BASE_URL=http://localhost:4200 cypress open",
"cy:run": "CYPRESS_BASE_URL=http://localhost:4200 cypress run"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -37,6 +39,8 @@
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"cypress": "^4.1.0",
"cypress-protobuf": "^1.0.5",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
Expand All @@ -49,4 +53,4 @@
"tslint": "~5.15.0",
"typescript": "~3.7.5"
}
}
}
9 changes: 2 additions & 7 deletions frontend/tsconfig.json
Expand Up @@ -11,13 +11,8 @@
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
Expand Down