Skip to content

Commit

Permalink
Merge pull request #72 from ThePhrontistery/71-front-test-cypress
Browse files Browse the repository at this point in the history
cypress test
  • Loading branch information
jjarbona authored Nov 20, 2023
2 parents 9f7b1e8 + ee84a67 commit 51aa4e0
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ dmypy.json
.idea

#poetry
poetry.lock
poetry.lock

# Node
tests/cypress/node_modules

#Visual Studio Code
tests/cypress/package-lock.json
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h1 class="text-xl font-bold pylabartitle">♠ PyLabar ♠</h1>
{% if username %}
<nav class="flex items-right gap-4 padding-top">
<a href="#" class="btn btn-sm bg-blue-500 text-white border-0 ml-auto" hx-get="/groups/create" hx-target="#content" hx-trigger="click">New Group</a>
<a href="#" class="btn btn-sm bg-blue-500 text-white border-0" hx-get="/topics/newtopic" hx-target="#content" hx-trigger="click">New Topic</a>
<a href="#" class="btn btn-sm bg-blue-500 text-white border-0" hx-get="/topics/newtopic" hx-target="#content" hx-trigger="click" id="new-topic-button">New Topic</a>
</nav>
{% endif %}
{% block content %}{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ <h2 class="text-xl font-bold my-3 text-center">Pylabar - Log in</h2>
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
type="submit"
id="login-button"
>
Log in
</button>
Expand Down
1 change: 1 addition & 0 deletions templates/new_topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h1 class="text-4xl font-bold mb-6 text-blue-500">Nuevo topic</h1>
<button
type="submit"
class="btn bg-blue-500 text-white border-0 py-3 px-6 rounded"
id="save-topic-button"
>
Guardar
</button>
Expand Down
20 changes: 20 additions & 0 deletions tests/cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
env: {
CYPRESS_BASE_URL: "http://localhost:80",
CYPRESS_USERNAME: "Juanjo",
CYPRESS_PASSWORD: "pass123"
},

production: {
CYPRESS_BASE_URL: "https://www.example.com",
CYPRESS_USERNAME: "production_user",
CYPRESS_PASSWORD: "tu_contraseña_produccion",
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
22 changes: 22 additions & 0 deletions tests/cypress/cypress/e2e/create-group.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('template spec', () => {
beforeEach(() => {
cy.viewport(2048, 1043);

cy.visit(Cypress.env("CYPRESS_BASE_URL"));
cy.wait(1000);

cy.get('#user_code').type(Cypress.env("CYPRESS_USERNAME"));
cy.wait(1000);

cy.get('#password').type(
Cypress.env("CYPRESS_PASSWORD")
);
cy.wait(1000);
cy.get("#login-button").click();
cy.wait(1000);
cy.url().should("include", "/home");
});
it('passes', () => {
cy.visit('https://example.cypress.io')
})
})
35 changes: 35 additions & 0 deletions tests/cypress/cypress/e2e/create_topic.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('template spec', () => {
beforeEach(() => {
cy.viewport(2048, 1043);

cy.visit(Cypress.env("CYPRESS_BASE_URL"));
cy.wait(1000);

cy.get('#user_code').type(Cypress.env("CYPRESS_USERNAME"));
cy.wait(1000);

cy.get('#password').type(
Cypress.env("CYPRESS_PASSWORD")
);
cy.wait(1000);
cy.get("#login-button").click();
cy.wait(1000);
cy.url().should("include", "/home");
});
it('passes', () => {
cy.log("Vamos a crear un topic");
cy.get("#new-topic-button").click();
cy.wait(1000);
cy.get('#title').type("Prueba cypress");
cy.wait(1000);
cy.get("#close_date").type("2024-12-30");
cy.wait(1000);
cy.get('#group').find('option').first().then(($option) => {
const valorPrimerElemento = $option.attr('value');

cy.get('#group').select(valorPrimerElemento);
});
cy.wait(1000);
cy.get("#save-topic-button").click();
})
})
5 changes: 5 additions & 0 deletions tests/cypress/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": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions tests/cypress/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 will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions tests/cypress/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -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')
5 changes: 5 additions & 0 deletions tests/cypress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"cypress": "^13.5.1"
}
}

0 comments on commit 51aa4e0

Please sign in to comment.