Skip to content

Commit

Permalink
Added test for adding shuffle button to channel header, install exten…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
NikkelM committed Jul 2, 2024
1 parent 3ae8843 commit 575000c
Showing 1 changed file with 74 additions and 3 deletions.
77 changes: 74 additions & 3 deletions test/compatibility.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
});
});
});

0 comments on commit 575000c

Please sign in to comment.