Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup fix #14

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 73 additions & 20 deletions acceptance/new-user/sign-up.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = require("config");
const URLS = require("../../constants/urls");

const { HOME_PAGE, SIGN_UP_PAGE, MY_HOST } = URLS;
const {signupPageTitle} = require("../../constants/pageTitles")
const {signupPageTitle} = require("../../constants/pageTitles");


let browser, page;
Expand All @@ -20,9 +20,9 @@ beforeAll(async () => {
headless: false,
slowMo: 0,
});

const context = await browser.createIncognitoBrowserContext();

page = await context.newPage();
return page;
});
Expand All @@ -31,39 +31,92 @@ afterAll(async () => {
await browser.close();
});

describe("New user navigates in the page", () => {
test("New user sees a sign up page", async () => {
describe('New user navigates in the page', () => {
// const response = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

// id: "<>",
// incompleteUserDetails: true,
// github_display_name: "<>",
// github_id: "<>"
// }

test('New user sees a sign up page', async () => {
await page.goto(HOME_PAGE);

await page.waitForResponse((res) => res.url().endsWith("/users/self"));
await page.waitForSelector("button.login-btn-text");
await page.waitForResponse((res) => res.url().endsWith('/users/self'));
await page.waitForSelector('button.login-btn-text');

await Promise.all([
page.waitForNavigation(),
page.click("button.login-btn-text"),
page.click('button.login-btn-text'),
]);

const ghUsernameInput = await page.waitForSelector("input#login_field");
const ghPasswordInput = await page.waitForSelector("input#password");

await ghUsernameInput.type(config.get("testUser.username"));
await ghPasswordInput.type(config.get("testUser.password"));
await Promise.all([page.waitForNavigation(), page.keyboard.press("Enter")]);
await page.waitForSelector("button#js-oauth-authorize-btn");
const ghUsernameInput = await page.waitForSelector('input#login_field');
const ghPasswordInput = await page.waitForSelector('input#password');

await ghUsernameInput.type(config.get('testUser.username'));
await ghPasswordInput.type(config.get('testUser.password'));
await Promise.all([page.waitForNavigation(), page.keyboard.press('Enter')]);
try {
await page.waitForSelector('button#js-oauth-authorize-btn');
} catch (err) {
console.log(
'The test user credentials are wrong or your test account is already has RDS as an OAuth application.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console.log

err
);
}
await delay(2000);
await page.click("button#js-oauth-authorize-btn");
await page.click('button#js-oauth-authorize-btn');
await page.waitForNavigation();
await page.waitForFunction(
`window.location.href.includes("${SIGN_UP_PAGE}")`
window.location.href.includes(`${SIGN_UP_PAGE}`)
);
await page.waitForSelector("button.submitButton");
await page.screenshot({ path: "tmp/sign-up-form.png" });
await page.waitForSelector('button.submitButton');
await page.screenshot({ path: 'tmp/sign-up-form.png' });
const pageTitle = await page.title();
expect(pageTitle).toMatch(signupPageTitle);
});
//For mocking github api -->>
// page.on('request', (request) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

// if(request.url().includes('github.com/login')){
// request.response({
// headers: {
// "Content-Type": "application/json"
// },
// body: JSON.stringify({
// access_token: "gho_16C7e42F292c6912E7710c838347Ae178B4a",
// token_type: "bearer",
// scope: "<>"
// })
// })
// }
// });

//for mocking /users/self api -->>
// page.on('request', (request) => {
// if(request.url().endsWith("/users/self")) {
// console.log('inside self');
// request.respond({
// headers: {
// "Accept": "application/json"
// },
// body: JSON.stringify({ response })
// })
// } else {
// console.log('entering else');
// }
// });
test.skip('401 response if new user haven\'t sign-in with github', async () => {
await page.goto(HOME_PAGE);
await page.goto(SIGN_UP_PAGE);
const cookies = page.cookies();
cookies.then(cookies => {
const rdsSession = cookies.find(cookie => cookie["name"] === 'rds-session')
expect(rdsSession).toBeUndefined();
});
})
});

describe("New user sign up page works correctly", () => {
describe.skip("New user sign up page works correctly", () => {
beforeEach(async () => {
await page.setRequestInterception(true);
});
Expand Down
6 changes: 6 additions & 0 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"testUser" : {
"username" : "",
"password" : ""
}
}
2 changes: 1 addition & 1 deletion constants/pageTitles.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const signupPageTitle = /Sign Up/;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the UPPERCASE for the const name and separated by the _


module.exports = signupPageTitle;
module.exports = {signupPageTitle};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"jest": "^27.1.0"
},
"scripts": {
"test": "jest"
"test": "jest sign-up"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings in the package.json should be targeted to a folder-test rather than just one file.

}
}
Binary file modified social-media/facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified social-media/instagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified social-media/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading