From 4e9fd31a3b09e4afd83aeac8439ed97a71e51385 Mon Sep 17 00:00:00 2001 From: zilin Date: Wed, 5 Jun 2024 18:49:35 -0700 Subject: [PATCH] test --- .github/workflows/main.yml | 4 +++- __tests__/Contacts.E2E.test.js | 2 +- __tests__/ProjectCard.E2E.test.js | 32 +++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 46bc2c7..3cd8427 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,9 +28,11 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Dependencies - run: npm install --save-dev puppeteer + run: npm install --save-dev puppeteer jest - name: '[E2E test] project cards' run: npm test ./__tests__/ProjectCard.E2E.test.js --runInBand + - name: '[E2E test] contacts' + run: npm test ./__tests__/Contacts.E2E.test.js --runInBand linting: name: Linting # job name (unique id) runs-on: ubuntu-latest # on which machine to run diff --git a/__tests__/Contacts.E2E.test.js b/__tests__/Contacts.E2E.test.js index 0134e73..c2c33ef 100644 --- a/__tests__/Contacts.E2E.test.js +++ b/__tests__/Contacts.E2E.test.js @@ -11,7 +11,7 @@ describe('Unit test: contact management', () => { }); page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); - await page.goto('http://127.0.0.1:5501/'); + await page.goto('https://cse110-sp24-group31.github.io/Dev-Journal/'); // Click the "Contacts" link await page.click('.nav-links a:nth-child(1)'); }); diff --git a/__tests__/ProjectCard.E2E.test.js b/__tests__/ProjectCard.E2E.test.js index 51f1411..cd80664 100644 --- a/__tests__/ProjectCard.E2E.test.js +++ b/__tests__/ProjectCard.E2E.test.js @@ -1,3 +1,5 @@ +const puppeteer = require('puppeteer'); + /** * E2E test, focus on class interactions * MAKE SURE USE: npm test ProjectCard.E2E.test.js --runInBand @@ -48,6 +50,18 @@ describe('E2E test: create project card workflow', () => { it('should have a submit button', async () => { submitBtnHandle = await addProjectCardModalHandle.$('#submitButton'); expect(submitBtnHandle).not.toBe(null); + + //button should be visible + const buttonVisible = await page.waitForSelector('#submitButton', { + visible: true, + }); + expect(buttonVisible).not.toBe(null); + + const buttonNotDisabled = await page.$eval( + '#submitButton', + el => el.getAttribute('disabled') === null + ); + expect(buttonNotDisabled).toBe(true); }); it('should not accept empty submission', async () => { @@ -106,27 +120,29 @@ describe('E2E test: create project card workflow', () => { ) ).toBe(TEST_CASE[2]); - submitBtnHandle = await page.waitForSelector('#submitButton', { - visible: true, - }); - await submitBtnHandle.click(); + await page.click('#submitButton'); const isHidden = await page.$eval('#addCardModal', modal => { return window.getComputedStyle(modal).display; }); expect(isHidden).toBe('none'); }, 20000); + + afterAll(async () => { + await page.waitForSelector('project-card'); + }); }); //TODO: edit and update project card workflow describe('E2E test: updateCard(title, desc, imgURL, progress)', () => { beforeAll(async () => { await page.goto('https://cse110-sp24-group31.github.io/Dev-Journal/'); //change this for live server - }, 20000); - let projectCardHandle; + }); it('should have a card', async () => { - projectCardHandle = await page.$('project-card'); - expect(projectCardHandle).not.toBe(null); + const pcIsNull = await page.$eval('project-card', ele => { + return ele === null; + }); + expect(pcIsNull).toBe(false); }); it('should be same', async () => { //arrange