From 20ba36c05274e068b474fda98b90de1366dfbb7f Mon Sep 17 00:00:00 2001 From: tuanvu Date: Wed, 1 Jan 2025 23:45:40 +0100 Subject: [PATCH] cypress --- cypress/e2e/Pokedemo/filter-pokemon.cy.js | 25 +++++++++++++++++++++++ cypress/e2e/Pokedemo/pokemon.cy.js | 21 +++++++++++++++++++ src/app/app.component.spec.ts | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/Pokedemo/filter-pokemon.cy.js create mode 100644 cypress/e2e/Pokedemo/pokemon.cy.js diff --git a/cypress/e2e/Pokedemo/filter-pokemon.cy.js b/cypress/e2e/Pokedemo/filter-pokemon.cy.js new file mode 100644 index 0000000..a49bd0a --- /dev/null +++ b/cypress/e2e/Pokedemo/filter-pokemon.cy.js @@ -0,0 +1,25 @@ +describe('FilterPokemonPipe', () => { + beforeEach(() => { + cy.visit('http://localhost:4200') + }) + + it('should test search', () => { + /* class using . */ + cy.get('.filter_pokedex').clear() + cy.get('.filter_pokedex').type('charm') + cy.get('.select_pokedex').select(1) + cy.get('button').contains('GO').click() + cy.get('.pokemon').should('be.visible') + }) + + it('should use combo box', () => { + cy.get('.select_pokedex').select(0) + cy.get('button').contains('GO').click() + cy.get('.pokemon').should('be.visible') + }) + + it('should navigate to previous pokemon', () => { + cy.get('.select_pokedex').select(1) + cy.get('button').contains('GO').click() + }) +}) diff --git a/cypress/e2e/Pokedemo/pokemon.cy.js b/cypress/e2e/Pokedemo/pokemon.cy.js new file mode 100644 index 0000000..b5e51fb --- /dev/null +++ b/cypress/e2e/Pokedemo/pokemon.cy.js @@ -0,0 +1,21 @@ +describe('Pokemon API Tests', () => { + beforeEach(() => { + cy.visit('http://localhost:4200') + }) + + it('should get the database', () => { + /*https://docs.cypress.io/api/commands/request*/ + cy.request('GET', 'https://pokeapi.co/api/v2/pokemon') + .then((response) => { + // 200 = OK + expect(response.status).to.eq(200) + const pokeData = response.body + expect(pokeData).to.have.property('count') + expect(pokeData.count).to.be.a('number') + expect(pokeData.next).to.be.a('string') + expect(pokeData.results[0]).to.have.property('name') + expect(pokeData.results[0].name).to.eq('bulbasaur') + }) + }) + +}) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 86953b6..48d3ae8 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -39,6 +39,6 @@ describe('AppComponent', () => { it('should render the title', () => { const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('pokedemo'); + expect(compiled.querySelector('h1')?.textContent).toContain('pokedemo!'); }); });