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

181 - Setup Cypress #182

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions games-vue-client/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 8 additions & 0 deletions games-vue-client/cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [
"cypress"
],
"extends": [
"plugin:cypress/recommended"
]
}
21 changes: 21 additions & 0 deletions games-vue-client/cypress/integration/CookieBanner.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BASE_URL } from "../utils/constants";

context('Cookie Banner', () => {
beforeEach(() => {
cy.visit(BASE_URL);
})

it('should provide a cookie banner', () => {
cy.get('[class="Cookie__button"]').should('be.visible');
})

it('should not display a cookie banner after accept and reload', () => {
cy.get('[class="Cookie__button"]').should('be.visible');
cy.get('[class="Cookie__button"]').click();
cy.get('[class="Cookie__button"]').should('not.exist');

cy.reload();

cy.get('[class="Cookie__button"]').should('not.exist');
})
})
9 changes: 9 additions & 0 deletions games-vue-client/cypress/integration/gameList.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
context('Game List', () => {
beforeEach(() => {
cy.login();
})

it('should have a list of games', () => {
cy.get('.game-type').should('be.gt', 10);
})
})
25 changes: 25 additions & 0 deletions games-vue-client/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <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
// ***********************************************************

let percyHealthCheck = require('@percy/cypress/task')

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("task", percyHealthCheck);
}
39 changes: 39 additions & 0 deletions games-vue-client/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import '@percy/cypress';
import { BASE_URL, GUEST_TOKEN } from '../utils/constants';

// ***********************************************
// 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) => { ... })

Cypress.Commands.add('login', () => {
cy.visit(BASE_URL)
.then(() => {
window.localStorage.setItem('lastUsedProvider', 'guest');
window.localStorage.setItem('authCookie', GUEST_TOKEN);
window.localStorage.setItem('cookie:accepted', 'true');
});
cy.get('[class="server-selection"]').should('be.visible');
cy.reload();
})
20 changes: 20 additions & 0 deletions games-vue-client/cypress/support/index.js
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')
2 changes: 2 additions & 0 deletions games-vue-client/cypress/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const BASE_URL = 'http://localhost:8080'
export const GUEST_TOKEN = 'C3qH3VVmoqR/rbxJIiVys1jW5jE0bDtuixWVorDfJhE=';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upps. Public now and 4-ever.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guest token can easily be changed later

Loading