From e48291a3cf2e35535db5823fdd9d59d281008c84 Mon Sep 17 00:00:00 2001 From: Khushi Shukla Date: Tue, 21 Mar 2023 22:40:17 +0530 Subject: [PATCH 1/2] test/signin-github --- acceptance/new-user/sign-up-flow.test.js | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 acceptance/new-user/sign-up-flow.test.js diff --git a/acceptance/new-user/sign-up-flow.test.js b/acceptance/new-user/sign-up-flow.test.js new file mode 100644 index 0000000..24ebf5f --- /dev/null +++ b/acceptance/new-user/sign-up-flow.test.js @@ -0,0 +1,66 @@ +const puppeteer = require("puppeteer"); +const config = require("config"); + +const URLS = require("../../constants/urls"); + +const { HOME_PAGE, SIGN_UP_PAGE, MY_HOST } = URLS; +const {signupPageTitle} = require("../../constants/pageTitles") + +beforeAll(async () => { + browser = await puppeteer.launch({ + headless: false, + slowMo: 0, + }); + + const context = await browser.createIncognitoBrowserContext(); + + page = await context.newPage(); + return page; +}); + + +// afterAll(async () => { +// await browser.close(); +// }); + +describe("New user navigates in the page", () => { + test("github signin", async () => { + await page.goto(HOME_PAGE); + + await Promise.all([ + page.waitForNavigation(), + page.click("a.btn-login"), + ]); + + const ghUsernameInput = await page.waitForSelector("input#login_field"); + const ghPasswordInput = await page.waitForSelector("input#password"); + + if(ghPasswordInput && ghUsernameInput) + { + await ghUsernameInput.type(config.get("testUser.username")); + await ghPasswordInput.type(config.get("testUser.password")); + await Promise.all([page.waitForNavigation(), page.keyboard.press("Enter")]); + + // const pageTitle = await page.$eval(document.title) + // console.log(pageTitle) + // // Authorization applition + // await delay(2000) + + // await page.waitForSelector("button#js-oauth-authorize-btn"); + // await Promise.all([ + // await page.click("button#js-oauth-authorize-btn"), + // await page.waitForNavigation() + // ]) + } + + await Promise.all([ + page.waitForNavigation(), + page.keyboard.press("Enter") + ]); + }) +}) + + + + + From 67ac12e643f8f1ba80e7fccf177568bf9e5deaad Mon Sep 17 00:00:00 2001 From: Khushi Shukla Date: Sat, 25 Mar 2023 00:02:18 +0530 Subject: [PATCH 2/2] sign up navigation --- acceptance/new-user/sign-up-flow.test.js | 101 ++++++++++++++++------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/acceptance/new-user/sign-up-flow.test.js b/acceptance/new-user/sign-up-flow.test.js index 24ebf5f..e14f650 100644 --- a/acceptance/new-user/sign-up-flow.test.js +++ b/acceptance/new-user/sign-up-flow.test.js @@ -3,7 +3,7 @@ const config = require("config"); const URLS = require("../../constants/urls"); -const { HOME_PAGE, SIGN_UP_PAGE, MY_HOST } = URLS; +const { HOME_PAGE, SIGN_UP_PAGE, MY_HOST , SELF_USER_API} = URLS; const {signupPageTitle} = require("../../constants/pageTitles") beforeAll(async () => { @@ -19,46 +19,85 @@ beforeAll(async () => { }); -// afterAll(async () => { -// await browser.close(); -// }); + -describe("New user navigates in the page", () => { - test("github signin", async () => { +test('can sign in and authorize with GitHub', async () => { await page.goto(HOME_PAGE); - await Promise.all([ page.waitForNavigation(), page.click("a.btn-login"), ]); - const ghUsernameInput = await page.waitForSelector("input#login_field"); - const ghPasswordInput = await page.waitForSelector("input#password"); + // Fill in the test account's login credentials and submit the login form + await page.type('#login_field', config.get("testUser.username")); + await page.type('#password', config.get("testUser.password")); + await page.click('[type="submit"]'); - if(ghPasswordInput && ghUsernameInput) - { - await ghUsernameInput.type(config.get("testUser.username")); - await ghPasswordInput.type(config.get("testUser.password")); - await Promise.all([page.waitForNavigation(), page.keyboard.press("Enter")]); - - // const pageTitle = await page.$eval(document.title) - // console.log(pageTitle) - // // Authorization applition - // await delay(2000) - - // await page.waitForSelector("button#js-oauth-authorize-btn"); - // await Promise.all([ - // await page.click("button#js-oauth-authorize-btn"), - // await page.waitForNavigation() - // ]) - } - + // Wait for the GitHub authorization page to load + await page.waitForSelector('#js-oauth-authorize-btn'); + + // Click the "Authorize" button to authorize the application await Promise.all([ - page.waitForNavigation(), - page.keyboard.press("Enter") - ]); + await page.click("button#js-oauth-authorize-btn"), + await page.waitForNavigation() + ]) + + /* navigate to signup */ + // await page.setRequestInterception(true); + // page.on("request", (request) => { + + // if (request.url().endsWith("/users/self") && request.method() === "GET") { + + // request.respond({ + // headers: { + // "Access-Control-Allow-Credentials": true, + // "Access-Control-Allow-Origin": MY_HOST, + // }, + // body: JSON.stringify({ + // id: "<>", + // incompleteUserDetails: true, + // github_display_name: "<>", + // github_id: "<>", + // }), + // }); + // } else { + // request.continue(); + // } + // }); + // await page.goto(SIGN_UP_PAGE) + + browser.close() + }); + +describe("New user sign up page works correctly",() => { + test("Incomplete user sees sign up page", async () => { + await page.setRequestInterception(true); + page.on("request", (request) => { + if (request.url().endsWith("/users/self") && request.method() === "GET") { + request.respond({ + headers: { + "Access-Control-Allow-Credentials": true, + "Access-Control-Allow-Origin": MY_HOST, + }, + body: JSON.stringify({ + id: "<>", + incompleteUserDetails: true, + github_display_name: "<>", + github_id: "<>", + }), + }); + } else { + request.continue(); + } + }); + await page.goto(SIGN_UP_PAGE); + + browser.close() }) -}) +}) + + +