-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from xenosf/test-cases
Add test cases
- Loading branch information
Showing
38 changed files
with
5,501 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import App from "./App"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
|
||
test('renders "PeerPrep" text (in toolbar)', () => { | ||
render( | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter> | ||
); | ||
const peerprep = screen.getByText(/PeerPrep/i); | ||
expect(peerprep).toBeInTheDocument(); | ||
test("placeholder test (major client functionality already tested in e2e)", () => { | ||
expect(true).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
let { | ||
getWebDriver, | ||
findButtonContainingText, | ||
waitForUrl, | ||
click, | ||
findElementWithWait, | ||
} = require("./utils/driver"); | ||
let { URLS, TEST_QUESTION } = require("./utils/const"); | ||
const { By } = require("selenium-webdriver"); | ||
const { resetServer, fillAddQuestionForm, fillUpdateQuestionForm } = require("./utils/utils"); | ||
const { getNewTestUser } = require("./utils/users"); | ||
const { resetQuestions } = require("./utils/server"); | ||
const { signUpAndLogIn } = require("./utils/utils"); | ||
|
||
describe("Questions test", () => { | ||
let driver; | ||
const user = getNewTestUser(); | ||
|
||
beforeAll(async () => { | ||
driver = await getWebDriver(); | ||
await resetServer(); | ||
await signUpAndLogIn(driver, user); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (driver) await driver.quit(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await resetQuestions(); | ||
}); | ||
|
||
describe("button on home page brings you to questions page", () => { | ||
test("button on home page brings you to questions page", async () => { | ||
await click(await findButtonContainingText(driver, "Questions List")); | ||
await waitForUrl(driver, URLS.questions); | ||
expect(await driver.getCurrentUrl()).toEqual(URLS.questions); | ||
}); | ||
}); | ||
|
||
describe("simulate viewing question and clicking link", () => { | ||
test("simulate viewing question and clicking link", async () => { | ||
const titleXpath = `//p[contains(normalize-space(), '${TEST_QUESTION.title}')]`; | ||
const descriptionXpath = `//div[contains(@class,'MuiCollapse-entered')][contains(normalize-space(), 'Category: ${TEST_QUESTION.categories}')]`; | ||
const linkXpath = descriptionXpath + "//a"; | ||
|
||
await driver.get(URLS.questions); | ||
|
||
await click(await findElementWithWait(driver, By.xpath(titleXpath))); | ||
// expect correct description to be shown | ||
await findElementWithWait(driver, By.xpath(descriptionXpath)); | ||
|
||
let link = await findElementWithWait(driver, By.xpath(linkXpath)); | ||
expect(await link.getAttribute("href")).toEqual(TEST_QUESTION.link); | ||
}); | ||
}); | ||
|
||
describe("adding question successfully", () => { | ||
test("adding question successfully", async () => { | ||
let newQuestion = { ...TEST_QUESTION }; | ||
newQuestion.title = "hello"; | ||
let successMsg = `Successfully submitted question “${newQuestion.title}”.`; | ||
let successMsgXpath = `//p[normalize-space()='${successMsg}']`; | ||
|
||
await driver.get(URLS.questions); | ||
await click(await findButtonContainingText(driver, "Add question")); | ||
await fillAddQuestionForm(driver, newQuestion); | ||
await expect(findElementWithWait(driver, By.xpath(successMsgXpath))).resolves.not.toThrow(); | ||
|
||
// check that added question appears in list | ||
await click(await findButtonContainingText(driver, "View questions")); | ||
let newTitleXpath = `//p[contains(normalize-space(), '${newQuestion.title}')]`; | ||
await expect(findElementWithWait(driver, By.xpath(newTitleXpath))).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("adding question unsuccessfully", () => { | ||
test("adding question unsuccessfully", async () => { | ||
let failureMsg = `Question with the title "${TEST_QUESTION.title}" already exists.`; | ||
let failureMsgXpath = `//p[normalize-space()='${failureMsg}']`; | ||
|
||
await driver.get(URLS.questions); | ||
await click(await findButtonContainingText(driver, "Add question")); | ||
await fillAddQuestionForm(driver, TEST_QUESTION); | ||
await expect(findElementWithWait(driver, By.xpath(failureMsgXpath))).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("updating question", () => { | ||
test("updating question", async () => { | ||
let newQuestion = { ...TEST_QUESTION }; | ||
newQuestion.title = "hello"; | ||
let successMsgXpath = `//div[@role='alert'][contains(normalize-space(), 'Question updated successfully!')]`; | ||
let updateButtonXpath = `//div[contains(normalize-space(), '${TEST_QUESTION.title}')]/button[contains(text(), 'Update/Delete')]`; | ||
|
||
await driver.get(URLS.questions); | ||
await click(await findElementWithWait(driver, By.xpath(updateButtonXpath))); | ||
await fillUpdateQuestionForm(driver, newQuestion); | ||
await expect(findElementWithWait(driver, By.xpath(successMsgXpath))).resolves.not.toThrow(); | ||
await driver.sleep(3000); | ||
// check that updated question appears in list | ||
await click(await findButtonContainingText(driver, "View questions")); | ||
let newTitleXpath = `//p[contains(normalize-space(), '${newQuestion.title}')]`; | ||
await expect(findElementWithWait(driver, By.xpath(newTitleXpath))).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("deleting question", () => { | ||
test("deleting question", async () => { | ||
let successMsgXpath = `//div[@role='alert'][contains(normalize-space(), 'Question deleted successfully!')]`; | ||
let updateButtonXpath = `//div[contains(normalize-space(), '${TEST_QUESTION.title}')]/button[contains(text(), 'Update/Delete')]`; | ||
|
||
await driver.get(URLS.questions); | ||
await click(await findElementWithWait(driver, By.xpath(updateButtonXpath))); | ||
await click(await findButtonContainingText(driver, "Delete Question")); | ||
await expect(findElementWithWait(driver, By.xpath(successMsgXpath))).resolves.not.toThrow(); | ||
await driver.sleep(3000); | ||
// check that deleted question disappears from list | ||
let titleXpath = `//p[contains(normalize-space(), '${TEST_QUESTION.title}')]`; | ||
await expect(findElementWithWait(driver, By.xpath(titleXpath))).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.