From 575000c9e2ca39fd5a5f541f16426307a7cd1e31 Mon Sep 17 00:00:00 2001 From: Nikkel Mollenhauer <57323886+NikkelM@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:57:15 +0100 Subject: [PATCH] Added test for adding shuffle button to channel header, install extension --- test/compatibility.test.js | 77 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/test/compatibility.test.js b/test/compatibility.test.js index 6f2bdb8d..6a3c9a4d 100644 --- a/test/compatibility.test.js +++ b/test/compatibility.test.js @@ -1,7 +1,13 @@ import expect from "expect.js"; import puppeteer from "puppeteer"; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); describe("compatibility", function () { + this.timeout(15000); + context("YouTube", function () { context("URLs", function () { it("should redirect a watch_videos URL to a temporary playlist URL", async function () { @@ -17,7 +23,6 @@ describe("compatibility", function () { let browser, page; beforeEach(async () => { - // Common setup: launching a browser and opening a new page browser = await puppeteer.launch({ headless: true }); page = await browser.newPage(); @@ -37,7 +42,6 @@ describe("compatibility", function () { }); it("should contain required data in the yt-navigate-finish event for video pages", async function () { - this.timeout(10000); let event = {}; // Create a promise that listens for the "yt-navigate-finish" event @@ -84,7 +88,6 @@ describe("compatibility", function () { }); it("should contain required data in the yt-navigate-finish event for channel pages", async function () { - this.timeout(10000); let event = {}; // Create a promise that listens for the "yt-navigate-finish" event @@ -140,5 +143,73 @@ describe("compatibility", function () { expect(event.channelName).to.be("Rick Astley"); }); }); + + context("DOM elements", function () { + let browser, page; + + beforeEach(async () => { + browser = await puppeteer.launch({ headless: true }); + page = await browser.newPage(); + + // Set the SOCS cookie for YouTube (cookie banner) + await page.setCookie({ + 'name': 'SOCS', + 'value': 'CAESEwgDEgk0ODE3Nzk3MjQaAmVuIAEaBgiA_LyaBg', // base64 encoded value + 'domain': '.youtube.com', + 'path': '/', + 'secure': true, + 'httpOnly': false + }); + }); + + afterEach(async () => { + await browser.close(); + }); + + it("should contain the expected channel header elements to insert the button into", async function () { + }); + }); + + context("shuffle button insertion", function () { + let browser, page; + + beforeEach(async () => { + const extensionPath = join(__dirname, "../dist/chromium"); + + browser = await puppeteer.launch({ + headless: false, // Extensions only work in head-full mode + args: [ + `--disable-extensions-except=${extensionPath}`, + `--load-extension=${extensionPath}` + ] + }); + page = await browser.newPage(); + + // Set the SOCS cookie for YouTube (cookie banner) + await page.setCookie({ + 'name': 'SOCS', + 'value': 'CAESEwgDEgk0ODE3Nzk3MjQaAmVuIAEaBgiA_LyaBg', // base64 encoded value + 'domain': '.youtube.com', + 'path': '/', + 'secure': true, + 'httpOnly': false + }); + // For these tests, we need to install the dist/chromium directory as an extension in the browser + + }); + + afterEach(async () => { + await browser.close(); + }); + + it('should insert the shuffle button into the channel header', async function () { + await page.goto("https://www.youtube.com/@RickAstleyYT"); + + await page.waitForSelector("#youtube-random-video-large-shuffle-button-channel"); + const shuffleButton = await page.$("#youtube-random-video-large-shuffle-button-channel"); + + expect(shuffleButton).to.not.be(null); + }); + }); }); }); \ No newline at end of file