From 0c1acf1083d5c6ea6e6819d1c73d7a0813ad5ed1 Mon Sep 17 00:00:00 2001 From: Annie Huang Date: Fri, 20 Oct 2023 21:45:01 +0800 Subject: [PATCH] add testinglibrary, some basic test --- tests/cypress.config.js | 2 + tests/cypress/e2e/helloworld.cy.js | 69 +++++++++++++++++++++++++++--- tests/cypress/support/commands.js | 8 ++++ tests/package.json | 4 ++ 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/tests/cypress.config.js b/tests/cypress.config.js index 3a0330e..1b6d22e 100644 --- a/tests/cypress.config.js +++ b/tests/cypress.config.js @@ -8,5 +8,7 @@ const getConfig = (key, defaultValue) => { module.exports = defineConfig({ e2e: { baseUrl: getConfig('BASE_URL', 'http://localhost:5173'), + viewportWidth: 1920, + viewportHeight: 1080, }, }) diff --git a/tests/cypress/e2e/helloworld.cy.js b/tests/cypress/e2e/helloworld.cy.js index b772b68..9964b55 100644 --- a/tests/cypress/e2e/helloworld.cy.js +++ b/tests/cypress/e2e/helloworld.cy.js @@ -1,11 +1,70 @@ /// describe('example helloworld app', () => { - beforeEach(() => { - cy.visit('/') + describe('Login tests', () => { + beforeEach(() => { + cy.visit('/') + }) + it('Check Login Page Elements-Register', () => { + cy.get('h1.text-text-primary') + .should('contain', 'Linux Odyssey') + .and('be.visible') + cy.get('label[for="username"]') + .should('contain', 'Username') + .and('be.visible') + cy.get('#username') + .invoke('attr', 'placeholder') + .should('contain', 'Enter your username') + cy.get('label.text-text-secondary') + .should( + 'contain', + `Username should start with lowercase and consist of lowercase, numbers, '_' and '-'` + ) + .and('be.visible') + cy.get('label[for="email"]').should('contain', 'Email').and('be.visible') + cy.get('#email') + .invoke('attr', 'placeholder') + .should('contain', 'Enter your email') + cy.get('label[for="password"]') + .should('contain', 'Password') + .and('be.visible') + cy.get('#password') + .invoke('attr', 'placeholder') + .should('contain', 'Enter your password') + cy.findByRole('button', { name: 'Register' }).should('be.visible') + cy.get('span').contains('Already have an account?').should('be.visible') + }) + it('Check social account UI', () => { + cy.get('p').contains('Log in with social account').should('be.visible') + cy.findByRole('link', { name: 'Google' }).should('be.visible') + cy.findByRole('link', { name: 'GitHub' }).should('be.visible') + }) + it('Login-Already Register', () => { + cy.get('a.text-text-primary').should('contain', 'Log in').click() + cy.get('#username').type('alex') + cy.get('#password').type('123456') + cy.findByRole('button', { name: 'Log in' }).click() + }) }) + describe('Hello world', () => { + beforeEach(() => { + cy.visit('/') + cy.Login() + cy.get('.xterm-screen').as('Terminaltextbox') + cy.findByRole('button', { name: 'Reset' }).click() + cy.get('@Terminaltextbox').should('contain', 'commander') + }) - it('open login page', () => { - cy.get('#username').type('alex') - cy.get('#password').type('123456{enter}') + it('Typing in Terminal', () => { + cy.get('@Terminaltextbox').type('12345{enter}') + cy.get('@Terminaltextbox').should( + 'contain', + 'zsh: command not found: 12345' + ) + }) + it('Clear first task', () => { + cy.get('@Terminaltextbox').type('echo Hello World!{enter}') + // cy.wait(5000) + cy.get('@Terminaltextbox').should('contain', '你聽到了一個聲音:') + }) }) }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 119ab03..f4a0297 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -23,3 +23,11 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +import '@testing-library/cypress/add-commands' + +Cypress.Commands.add('Login', () => { + cy.get('a.text-text-primary').should('contain', 'Log in').click() + cy.get('#username').type('alex') + cy.get('#password').type('123456') + cy.findByRole('button', { name: 'Log in' }).click() +}) diff --git a/tests/package.json b/tests/package.json index af8e1fa..5241b0a 100644 --- a/tests/package.json +++ b/tests/package.json @@ -9,5 +9,9 @@ }, "dependencies": { "cypress": "^13.2.0" + }, + "devDependencies": { + "@testing-library/cypress": "^10.0.1", + "cypress": "^13.3.2" } }