Skip to content

Commit

Permalink
chore: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Dec 3, 2024
1 parent 7f27cfa commit 8b61186
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
6 changes: 5 additions & 1 deletion clipper/public/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ browser.runtime.onMessage.addListener((request: any, sender, sendResponse) => {
}
});

// Only use this script on appflowy.com
if (window.location.hostname.endsWith('appflowy.com')) {
if (localStorage.token) {
browser.storage.local.get(['auth_flow_active']).then((storage_data) => {
if (storage_data.auth_flow_active) {
browser.storage.local
.set({ token: localStorage.token, auth_flow_active: false })
.set({
token: localStorage.token,
auth_flow_active: false,
})
.then(() => {
console.log('Token saved successfully');
location.href = chrome.runtime.getURL('/index.html#/auth-redirect');
Expand Down
5 changes: 1 addition & 4 deletions clipper/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const puppeteer = require('puppeteer');

const EXTENSION_PATH = '../dist';
const EXTENSION_ID = 'bnhhcpdgpabghbipjeocenbhompjlmll';
const { EXTENSION_PATH, EXTENSION_ID } = require('./util');

let browser;

Expand Down Expand Up @@ -45,5 +43,4 @@ test('popup renders correctly', async () => {
}

await page.close();
await browser.close();
});
39 changes: 39 additions & 0 deletions clipper/tests/side_panel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const puppeteer = require('puppeteer');
const { EXTENSION_PATH, EXTENSION_ID } = require('./util');

let browser;

beforeEach(async () => {
browser = await puppeteer.launch({
headless: false,
args: [
`--disable-extensions-except=${EXTENSION_PATH}`,
`--load-extension=${EXTENSION_PATH}`,
],
});
});

afterEach(async () => {
await browser.close();
browser = undefined;
});

test('test auth redirect correctly', async () => {
const page = await browser.newPage();
await page.goto(`chrome-extension://${EXTENSION_ID}/index.html#/popup`);
await page.waitForSelector('button', { timeout: 5000 });

// Use evaluate to set token in browser.storage.local
await page.evaluate(() => {
chrome.storage.local.set({ auth_flow_active: 'true' });
chrome.storage.local.set({ token: 'mock token' });
});

// Wait for the redirect
await page.waitForFunction(
() => window.location.hash === '#/auth-redirect', // Use hash to check redirect
{ timeout: 10000 }
);

await browser.close();
});
4 changes: 4 additions & 0 deletions clipper/tests/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const EXTENSION_PATH = '../dist';
const EXTENSION_ID = 'bnhhcpdgpabghbipjeocenbhompjlmll';

module.exports = { EXTENSION_PATH, EXTENSION_ID };

0 comments on commit 8b61186

Please sign in to comment.