aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2021-07-30 15:53:57 -0400
committerAjay Ramachandran <[email protected]>2021-07-30 15:53:57 -0400
commitb9bbbebc106f761002247540f421e66471024a1a (patch)
tree2448ec2fd4e6de9371205defd127aee49a02c544
parentd93e9a7d8a62dfa6b6a9bc2c1f19e0401dae0e33 (diff)
downloadSponsorBlock-b9bbbebc106f761002247540f421e66471024a1a.tar.gz
SponsorBlock-b9bbbebc106f761002247540f421e66471024a1a.zip
Add test for editing
-rw-r--r--test/selenium.test.ts74
1 files changed, 59 insertions, 15 deletions
diff --git a/test/selenium.test.ts b/test/selenium.test.ts
index 4cd292dd..f87e92cf 100644
--- a/test/selenium.test.ts
+++ b/test/selenium.test.ts
@@ -1,4 +1,4 @@
-import { Builder, By, until, Key } from "selenium-webdriver";
+import { Builder, By, until, Key, WebDriver } from "selenium-webdriver";
import * as Chrome from "selenium-webdriver/chrome";
import * as Path from "path";
@@ -21,24 +21,68 @@ test("Selenium Chrome test", async () => {
await driver.get("https://www.youtube.com/watch?v=jNQXAC9IVRw");
await driver.wait(until.elementIsVisible(await driver.findElement(By.className("ytd-video-primary-info-renderer"))));
- const startSegmentButton = await driver.findElement(By.id("startSegmentButton"));
- const cancelSegmentButton = await driver.findElement(By.id("cancelSegmentButton"));
- await driver.executeScript("document.querySelector('video').currentTime = 0");
+ await createSegment(driver, "4", "10.33", "0:04.000 to 0:10.330");
- await startSegmentButton.click();
- await driver.wait(until.elementIsVisible(cancelSegmentButton));
+ await editSegments(driver, 0, "0:04.000", "0:10.330", "5", "13.211", "0:05.000 to 0:13.211", false);
+ } finally {
+ await driver.quit();
+ }
+}, 100_000);
+
+async function createSegment(driver: WebDriver, startTime: string, endTime: string, expectedDisplayedTime: string): Promise<void> {
+ const startSegmentButton = await driver.findElement(By.id("startSegmentButton"));
+ const cancelSegmentButton = await driver.findElement(By.id("cancelSegmentButton"));
+ await driver.executeScript("document.querySelector('video').currentTime = " + startTime);
- await driver.executeScript("document.querySelector('video').currentTime = 10.33");
+ await startSegmentButton.click();
+ await driver.wait(until.elementIsVisible(cancelSegmentButton));
- await startSegmentButton.click();
- await driver.wait(until.elementIsNotVisible(cancelSegmentButton));
+ await driver.executeScript("document.querySelector('video').currentTime = " + endTime);
+ await startSegmentButton.click();
+ await driver.wait(until.elementIsNotVisible(cancelSegmentButton));
+
+ const submitButton = await driver.findElement(By.id("submitButton"));
+ await submitButton.click();
+
+ const sponsorTimeDisplays = await driver.findElements(By.className("sponsorTimeDisplay"));
+ const sponsorTimeDisplay = sponsorTimeDisplays[sponsorTimeDisplays.length - 1];
+ await driver.wait(until.elementTextIs(sponsorTimeDisplay, expectedDisplayedTime));
+}
+
+async function editSegments(driver: WebDriver, index: number, expectedStartTimeBox: string, expectedEndTimeBox: string,
+ startTime: string, endTime: string, expectedDisplayedTime: string, openSubmitBox: boolean): Promise<void> {
+
+ if (openSubmitBox) {
const submitButton = await driver.findElement(By.id("submitButton"));
await submitButton.click();
-
- const sponsorTimeDisplay = await driver.findElement(By.className("sponsorTimeDisplay"));
- await driver.wait(until.elementTextIs(sponsorTimeDisplay, "0:00.000 to 0:10.330"));
- } finally {
- await driver.quit();
}
-}, 100_000); \ No newline at end of file
+
+ let editButton = await driver.findElement(By.id("sponsorTimeEditButtonSubmissionNotice" + index));
+ let sponsorTimeDisplays = await driver.findElements(By.className("sponsorTimeDisplay"));
+ let sponsorTimeDisplay = sponsorTimeDisplays[index];
+ await sponsorTimeDisplay.click();
+ // Ensure edit time appears
+ await driver.findElement(By.id("submittingTime0SubmissionNotice" + index));
+
+ // Try the edit button too
+ await editButton.click();
+ await editButton.click();
+
+ const startTimeBox = await driver.findElement(By.id("submittingTime0SubmissionNotice" + index));
+ expect((await startTimeBox.getAttribute("value"))).toBe(expectedStartTimeBox);
+ await startTimeBox.clear();
+ await startTimeBox.sendKeys(startTime);
+
+ const endTimeBox = await driver.findElement(By.id("submittingTime1SubmissionNotice" + index));
+ expect((await endTimeBox.getAttribute("value"))).toBe(expectedEndTimeBox);
+ await endTimeBox.clear();
+ await endTimeBox.sendKeys(endTime);
+
+ editButton = await driver.findElement(By.id("sponsorTimeEditButtonSubmissionNotice" + index));
+ await editButton.click();
+
+ sponsorTimeDisplays = await driver.findElements(By.className("sponsorTimeDisplay"));
+ sponsorTimeDisplay = sponsorTimeDisplays[index];
+ await driver.wait(until.elementTextIs(sponsorTimeDisplay, expectedDisplayedTime));
+} \ No newline at end of file