Skip to content

Commit

Permalink
Merge pull request #129 from unb-mds/121-tests-criar-testes-unitários…
Browse files Browse the repository at this point in the history
…-de-components-no-vue

121 tests criar testes unitários de components no vue
  • Loading branch information
ana-pfeilsticker authored Aug 12, 2024
2 parents 66813e5 + 80e298f commit 2244e94
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions vue-app/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ module.exports = defineConfig({
// implement node event listeners here
},
},

component: {
devServer: {
framework: "vue-cli",
bundler: "webpack",
},
},
});
12 changes: 12 additions & 0 deletions vue-app/cypress/support/component-index.html
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>
27 changes: 27 additions & 0 deletions vue-app/cypress/support/component.js
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)
24 changes: 24 additions & 0 deletions vue-app/src/components/Avaliacao/CardMinhaAvaliacao.cy.js
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()
})
})
26 changes: 26 additions & 0 deletions vue-app/src/pages/AvaliacaoPage.cy.js
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 },
})
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/CadastroPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/HomePage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/LandingPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/LoginPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/MateriaIndividualPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/MateriasPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/PerfilPage.cy.js
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)
})
})
8 changes: 8 additions & 0 deletions vue-app/src/pages/ProfessorPage.cy.js
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 vue-app/tests/components/AvaliacaoMateriaComponents.spec.js
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);
});
});

0 comments on commit 2244e94

Please sign in to comment.