added cypress e2e tests

This commit is contained in:
Wenszel
2023-12-19 09:27:47 +01:00
parent 97513eac2d
commit ce9e93d68f
13 changed files with 2467 additions and 35 deletions
+29
View File
@@ -0,0 +1,29 @@
const io = require('socket.io-client');
const socket = io.connect('http://localhost:8080', { withCredentials: true });
const uniqName = Date.now().toString();
describe('game', () => {
before(() => {
cy.visit('http://localhost:3000');
cy.get('[placeholder="Server Name"]').type(uniqName);
cy.get('button:contains("Host")').click();
const room = cy.contains(`${uniqName}`).should('exist');
room.closest('tr').find('button:contains("Join")').click();
const e = cy.get('[placeholder="Nickname"]').type('player1');
e.type('{enter}');
setTimeout(() => {
socket.emit('room:rooms');
socket.on('room:rooms', rooms => {
const roomId = JSON.parse(rooms).find(r => r.name === uniqName)._id;
socket.emit('player:login', { roomId: roomId, name: 'player2', password: '' });
});
}, 1000);
});
it('starts game correctly', () => {
socket.emit('player:ready');
cy.get('.PrivateSwitchBase-input').click();
cy.get('[data-testid="animated-overlay"]').should('exist');
socket.emit('');
});
});
+29
View File
@@ -0,0 +1,29 @@
describe('login', () => {
it('should change color of input if the server name is invalid', () => {
cy.visit('http://localhost:3000');
cy.get('button:contains("Host")').click();
cy.get('[placeholder="Server Name"]').should('have.css', 'border-color', 'rgb(255, 0, 0)');
});
it('should redirect user to game when filling inputs correctly', () => {
cy.visit('http://localhost:3000');
const uniqName = Date.now().toString();
cy.get('[placeholder="Server Name"]').type(uniqName);
cy.get('.PrivateSwitchBase-input').click();
cy.get('[placeholder="password"]').type('123456');
cy.get('button:contains("Host")').click();
const room = cy
.contains(`${uniqName}`)
.should('exist')
.then($room => {
cy.wrap($room).scrollIntoView();
});
room.closest('tr').find('button:contains("Join")').click();
cy.get('[placeholder="Nickname"]').type('player1');
const e = cy.get('[placeholder="Room password"]').type('123456');
e.type('{enter}');
cy.url().should('include', '/game');
cy.contains('player1').should('exist');
cy.get('canvas').should('exist');
});
});
+5
View File
@@ -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"
}
+25
View File
@@ -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
View File
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')