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

CI integration and tests creation #180

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
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Farol Verde Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
Cypress:
runs-on: ubuntu-latest
steps:
- name: Checkout repository content
uses: actions/checkout@v2
- name: Run Project containers
run: docker-compose up -d
- name: Run Migrate
run: docker exec farol_verde_server /bin/bash -c "python manage.py migrate"
- name: Run Cypress
run: docker exec farol_verde_tests /bin/bash -c "cd /tests && cypress run"

Black:
runs-on: ubuntu-latest
steps:
- name: Checkout repository content
uses: actions/checkout@v2
- name: Run Project containers
run: docker-compose up -d
- name: Run Black Check
run: docker exec farolwagtail /bin/bash -c "black --check ."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ __pycache__/
*.pyc
.vscode*
landing/static
/tests/cypress/videos
/tests/cypress/screenshots
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
SERVER_CONTAINER=farol_verde_server
SERVER_CONTAINER=farolwagtail
TEST_CONTAINER=faroltests

attach:
docker exec -it $(SERVER_CONTAINER) bash

test-attach:
docker exec -it $(TEST_CONTAINER) bash

up:
docker-compose up

Expand All @@ -12,6 +16,9 @@ stop:
rm:
docker-compose rm

test:
docker exec $(TEST_CONTAINER) /bin/bash -c "cd /tests && cypress run"

createsu:
docker exec -it $(SERVER_CONTAINER) poetry run python manage.py createsuperuser

Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.3"

services:

farol_verde_server:
server:
environment:
- PYTHONUNBUFFERED=1
env_file:
Expand All @@ -15,7 +15,7 @@ services:
- ./landing:/landing
- farol_verde:/tmp/farol_verde_db
- media:/landing/media
container_name: farol_verde_server
container_name: farolwagtail
depends_on:
- farol_verde_db
entrypoint: ["/bin/bash", "run.sh"]
Expand All @@ -38,6 +38,16 @@ services:
ports:
- "5656:5656"

tests:
image: cypress/included:10.7.0
container_name: faroltests
working_dir: /tests
volumes:
- ./tests:/tests
depends_on:
- server
entrypoint: ["tail", "-f", "/dev/null"]

volumes:
farol_verde:
media:
Expand Down
8 changes: 8 additions & 0 deletions tests/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
e2e: {
baseUrl: 'http://farolwagtail:8000',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
};
11 changes: 11 additions & 0 deletions tests/cypress/e2e/candidates/profile.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe('Test candidate profile page', () => {
it("Open UF board", () => {
cy.visit('/candidatos/');
cy.get('.right a').click();

cy.get('.candidate').each(candidate => {
cy.wrap(candidate)
.should('have.attr', 'href');
})
})
});
23 changes: 23 additions & 0 deletions tests/cypress/e2e/candidates/senators.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('Test senators and deputies', () => {
it('Select "Senadores" and "Deputados"', () => {
cy.visit('/candidatos/');
cy.get('.right a').click();

cy.get('#deputies').click();
cy.wait(600);
cy.get('.candidate__info').each(info => {
cy.wrap(info)
.invoke('text')
.should('contain', 'Senador(a)');
});

cy.get('#deputies').click();
cy.get('#senators').click();
cy.wait(600);
cy.get('.candidate__info').each(info => {
cy.wrap(info)
.invoke('text')
.should('contain', 'Deputado(a)');
});
})
})
22 changes: 22 additions & 0 deletions tests/cypress/e2e/candidates/uf.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('Test UF filter', () => {
it("Open UF board", () => {
cy.visit('/candidatos/');
cy.get('.right a').click();
cy.get('#uf .input-board__content label')
.each(stateBtn => {
cy.get('#uf button.input-board__btn').click();
cy.wrap(stateBtn)
.click()
.invoke('text')
.then(state => {
state = state.trim().replaceAll('\n', '');
cy.wait(750);
cy.get('.candidate__info').each(info => {
cy.wrap(info)
.invoke('text')
.should('contain', state);
});
});
});
})
});
25 changes: 25 additions & 0 deletions tests/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/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')