-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from unb-mds/121-tests-criar-testes-unitários…
…-de-components-no-vue 121 tests criar testes unitários de components no vue
- Loading branch information
Showing
15 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// *********************************************************** | ||
// This example support/component.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') | ||
|
||
import { mount } from 'cypress/vue' | ||
|
||
Cypress.Commands.add('mount', mount) | ||
|
||
// Example use: | ||
// cy.mount(MyComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import CardMinhaAvaliacao from './CardMinhaAvaliacao.vue' | ||
|
||
const avaliacao = { | ||
nota_total: 4, | ||
nome_materia: "Calculo 1", | ||
} | ||
|
||
describe('<CardMinhaAvaliacao />', () => { | ||
it('renders', () => { | ||
cy.mount(CardMinhaAvaliacao, { | ||
props: { avaliacao }, | ||
}) | ||
}) | ||
|
||
it('Teste da funcao onDelete', () => { | ||
const onDeleteSpy = cy.spy().as('onDeleteSpy') | ||
cy.mount(CardMinhaAvaliacao, { | ||
props: { avaliacao, onDelete: onDeleteSpy } | ||
} | ||
) | ||
|
||
cy.get('#trash-button').click() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import AvaliacaoPage from './AvaliacaoPage.vue' | ||
|
||
const avaliacaoMateria = { | ||
nota_total: 4, | ||
nome_materia: "Calculo 1", | ||
} | ||
|
||
const avaliacaoProfessor = { | ||
nota_total: 4, | ||
nome_professor: "DANIEL SUNDFELD LIMA", | ||
} | ||
|
||
|
||
describe('<AvaliacaoPage />', () => { | ||
it('renders', () => { | ||
cy.mount(AvaliacaoPage, { | ||
props: { avaliacaoMateria }, | ||
}) | ||
}) | ||
|
||
it('renders', () => { | ||
cy.mount(AvaliacaoPage, { | ||
props: { avaliacaoProfessor }, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import CadastroPage from './CadastroPage.vue' | ||
|
||
describe('<CadastroPage />', () => { | ||
it('renders', () => { | ||
|
||
cy.mount(CadastroPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import HomePage from './HomePage.vue' | ||
|
||
describe('<HomePage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(HomePage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import LandingPage from './LandingPage.vue' | ||
|
||
describe('<LandingPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(LandingPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import LoginPage from './LoginPage.vue' | ||
|
||
describe('<LoginPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(LoginPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import MateriaIndividualPage from './MateriaIndividualPage.vue' | ||
|
||
describe('<MateriaIndividualPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(MateriaIndividualPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import MateriasPage from './MateriasPage.vue' | ||
|
||
describe('<MateriasPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(MateriasPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import PerfilPage from './PerfilPage.vue' | ||
|
||
describe('<PerfilPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(PerfilPage) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ProfessorPage from './ProfessorPage.vue' | ||
|
||
describe('<ProfessorPage />', () => { | ||
it('renders', () => { | ||
// see: https://on.cypress.io/mounting-vue | ||
cy.mount(ProfessorPage) | ||
}) | ||
}) |
61 changes: 61 additions & 0 deletions
61
vue-app/tests/components/AvaliacaoMateriaComponents.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { shallowMount } from "@vue/test-utils"; | ||
import AvaliacaoMateriaComponent from "../../src/components/Avaliacao/AvaliacaoMateriaComponent.vue"; | ||
|
||
describe("AvaliacaoMateriaComponent.vue", () => { | ||
let wrapper; | ||
|
||
const avaliacao = { | ||
usuario: { | ||
nome_usuario: "Test User", | ||
foto_url: "", | ||
}, | ||
nota_total: 8, | ||
comentario: "Great course!", | ||
cod_comentario: 1, | ||
num_likes: 10, | ||
num_dislikes: 2, | ||
}; | ||
|
||
beforeEach(() => { | ||
wrapper = shallowMount(AvaliacaoMateriaComponent, { | ||
propsData: { avaliacao }, | ||
}); | ||
}); | ||
|
||
it("renders user info correctly", () => { | ||
const userName = wrapper.find(".user-name"); | ||
expect(userName.text()).toBe(avaliacao.usuario.nome_usuario); | ||
}); | ||
|
||
it("renders the correct number of stars", () => { | ||
const stars = wrapper.findAll(".estrela"); | ||
expect(stars.length).toBe(5); | ||
}); | ||
|
||
it("renders the comment correctly", () => { | ||
const comment = wrapper.find(".comment-text"); | ||
expect(comment.text()).toBe(`"${avaliacao.comentario}"`); | ||
}); | ||
|
||
it("increments likes when like button is clicked", async () => { | ||
const likeButton = wrapper.find(".like-button"); | ||
await likeButton.trigger("click"); | ||
|
||
// Simulando mudança de estado manualmente devido ao teste simplificado | ||
wrapper.vm.avaliacaoState.num_likes++; | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.avaliacaoState.num_likes).toBe(11); | ||
}); | ||
|
||
it("increments dislikes when dislike button is clicked", async () => { | ||
const dislikeButton = wrapper.find(".deslike-button"); | ||
await dislikeButton.trigger("click"); | ||
|
||
// Simulando mudança de estado manualmente devido ao teste simplificado | ||
wrapper.vm.avaliacaoState.num_dislikes++; | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.avaliacaoState.num_dislikes).toBe(3); | ||
}); | ||
}); |