Skip to content

Commit a156410

Browse files
committed
181 - Setup Cypress.
1 parent 6994baf commit a156410

File tree

11 files changed

+2801
-50
lines changed

11 files changed

+2801
-50
lines changed

games-vue-client/cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
"cypress"
4+
],
5+
"extends": [
6+
"plugin:cypress/recommended"
7+
]
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { BASE_URL } from "../utils/constants";
2+
3+
context('Cookie Banner', () => {
4+
beforeEach(() => {
5+
cy.visit(BASE_URL);
6+
})
7+
8+
it('should provide a cookie banner', () => {
9+
cy.get('[class="Cookie__button"]').should('be.visible');
10+
})
11+
12+
it('should not display a cookie banner after accept and reload', () => {
13+
cy.get('[class="Cookie__button"]').should('be.visible');
14+
cy.get('[class="Cookie__button"]').click();
15+
cy.get('[class="Cookie__button"]').should('not.exist');
16+
17+
cy.reload();
18+
19+
cy.get('[class="Cookie__button"]').should('not.exist');
20+
})
21+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
context('Game List', () => {
2+
beforeEach(() => {
3+
cy.login();
4+
})
5+
6+
it('should have a list of games', () => {
7+
cy.get('.game-type').should('have.length', 18);
8+
})
9+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
let percyHealthCheck = require('@percy/cypress/task')
13+
14+
// This function is called when a project is opened or re-opened (e.g. due to
15+
// the project's config changing)
16+
17+
/**
18+
* @type {Cypress.PluginConfig}
19+
*/
20+
// eslint-disable-next-line no-unused-vars
21+
module.exports = (on, config) => {
22+
// `on` is used to hook into various events Cypress emits
23+
// `config` is the resolved Cypress config
24+
on("task", percyHealthCheck);
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import '@percy/cypress';
2+
import { BASE_URL, GUEST_TOKEN } from '../utils/constants';
3+
4+
// ***********************************************
5+
// This example commands.js shows you how to
6+
// create various custom commands and overwrite
7+
// existing commands.
8+
//
9+
// For more comprehensive examples of custom
10+
// commands please read more here:
11+
// https://on.cypress.io/custom-commands
12+
// ***********************************************
13+
//
14+
//
15+
// -- This is a parent command --
16+
// Cypress.Commands.add('login', (email, password) => { ... })
17+
//
18+
//
19+
// -- This is a child command --
20+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
21+
//
22+
//
23+
// -- This is a dual command --
24+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
25+
//
26+
//
27+
// -- This will overwrite an existing command --
28+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
29+
30+
Cypress.Commands.add('login', () => {
31+
cy.visit(BASE_URL)
32+
.then(() => {
33+
window.localStorage.setItem('lastUsedProvider', 'guest');
34+
window.localStorage.setItem('authCookie', GUEST_TOKEN);
35+
window.localStorage.setItem('cookie:accepted', 'true');
36+
});
37+
cy.get('[class="server-selection"]').should('be.visible');
38+
cy.reload();
39+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const BASE_URL = 'http://localhost:8080'
2+
export const GUEST_TOKEN = 'C3qH3VVmoqR/rbxJIiVys1jW5jE0bDtuixWVorDfJhE=';

0 commit comments

Comments
 (0)