From a66cdbf0bd8b75740378e28cee44819454e871c6 Mon Sep 17 00:00:00 2001 From: Kendall Werts Date: Mon, 24 Feb 2020 16:14:17 -0600 Subject: [PATCH] working on mocha tests --- src/js/background/messageHandler.js | 4 ++-- src/js/options.js | 4 ++-- src/js/popup.js | 9 ++++++++- src/manifest.json | 2 +- test/features/assignment.test.js | 15 ++++++++++----- test/features/containers.test.js | 10 ++++++---- test/features/external-webextensions.test.js | 2 +- test/features/sync.test.js | 2 +- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 5c15b91..d7384ea 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -11,7 +11,7 @@ const messageHandler = { switch (m.method) { case "getShortcuts": - console.log(identityState.keyboardShortcut); + console.log("getShortcuts", identityState.keyboardShortcut); response = identityState.keyboardShortcut; break; case "setShortcut": @@ -91,7 +91,7 @@ const messageHandler = { ); break; } - console.log(response); + console.log(m.method, "response", response); return response; }); diff --git a/src/js/options.js b/src/js/options.js index 0b3638e..7b81783 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -39,8 +39,8 @@ async function setupOptions() { } async function setupContainerShortcutSelects () { - const keyboardShortcut = browser.runtime.sendMessage({method: "getShortcuts"}); - console.log(keyboardShortcut); + const keyboardShortcut = await browser.runtime.sendMessage({method: "getShortcuts"}); + // console.log(keyboardShortcut); const identities = await browser.contextualIdentities.query({}); const fragment = document.createDocumentFragment(); const noneOption = document.createElement("option"); diff --git a/src/js/popup.js b/src/js/popup.js index 638adfe..ea3eb44 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -534,6 +534,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, { async initialize() { Utils.addEnterHandler(document.querySelector("#manage-containers-link"), (e) => { if (!e.target.classList.contains("disable-edit-containers")) { + console.log("manage clicked") Logic.showPanel(MANAGE_CONTAINERS_PICKER); } }); @@ -544,6 +545,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, { Logic.showPanel(REOPEN_IN_CONTAINER_PICKER); }); Utils.addEnterHandler(document.querySelector("#always-open-in"), () => { + console.log("clicked always-open-in"); Logic.showPanel(ALWAYS_OPEN_IN_PICKER); }); Utils.addEnterHandler(document.querySelector("#info-icon"), () => { @@ -940,6 +942,7 @@ Logic.registerPanel(MANAGE_CONTAINERS_PICKER, { `; Utils.addEnterHandler(document.querySelector("#new-container"), () => { + console.log("new-container-clicked") Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() }); }); @@ -963,6 +966,7 @@ Logic.registerPanel(MANAGE_CONTAINERS_PICKER, { tr.appendChild(td); Utils.addEnterHandler(tr, () => { + console.log("manage indentity:", identity) pickedFunction(identity); }); }); @@ -992,7 +996,7 @@ Logic.registerPanel(REOPEN_IN_CONTAINER_PICKER, { document.getElementById("picker-title").textContent = "Reopen This Site in"; const fragment = document.createDocumentFragment(); const currentTab = await Utils.currentTab(); - console.log(currentTab); + console.log("currentTab",currentTab); const pickedFunction = function (identity) { const newUserContextId = Utils.userContextId(identity.cookieStoreId); Utils.reloadInContainer( @@ -1108,6 +1112,7 @@ Logic.registerPanel(ALWAYS_OPEN_IN_PICKER, { tr.appendChild(td); Utils.addEnterHandler(tr, () => { + console.log("clicked"); Utils.alwaysOpenInContainer(identity); window.close(); }); @@ -1305,6 +1310,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { const deleteButton = document.getElementById("delete-container-button"); Utils.addEnterHandler(deleteButton, () => { + console.log("delete button clicked") Logic.showPanel(P_CONTAINER_DELETE, identity); }); return Promise.resolve(null); @@ -1327,6 +1333,7 @@ Logic.registerPanel(P_CONTAINER_DELETE, { Logic.showPreviousPanel(); }); Utils.addEnterHandler(document.querySelector("#delete-container-ok-link"), async () => { + console.log("delete ok clicked", Logic.currentIdentity().cookieStoreId) /* This promise wont resolve if the last tab was removed from the window. as the message async callback stops listening, this isn't an issue for us however it might be in future if you want to do anything post delete do it in the background script. diff --git a/src/manifest.json b/src/manifest.json index 2bb044c..12520c2 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -71,7 +71,7 @@ "default_icon": "img/multiaccountcontainer-16.svg", "default_title": "Always open this in a Container", "default_popup": "pageActionPopup.html", - "pinned": true, + "pinned": false, "show_matches": ["*://*/*"] }, "background": { diff --git a/test/features/assignment.test.js b/test/features/assignment.test.js index ca50f49..da31a77 100644 --- a/test/features/assignment.test.js +++ b/test/features/assignment.test.js @@ -5,7 +5,7 @@ describe("Assignment Feature", function () { beforeEach(async function () { this.webExt = await initializeWithTab({ - cookieStoreId: "firefox-container-1", + cookieStoreId: "firefox-container-2", url }); }); @@ -17,12 +17,17 @@ describe("Assignment Feature", function () { describe("click the 'Always open in' checkbox in the popup", function () { beforeEach(async function () { // popup click to set assignment for activeTab.url - await this.webExt.popup.helper.clickElementById("container-page-assigned"); + await this.webExt.popup.helper.clickElementById("always-open-in"); + console.log("done"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".menu-item"); + //await this.webExt.popup.helper.clickElementById("container-page-assigned"); }); describe("open new Tab with the assigned URL in the default container", function () { let newTab; beforeEach(async function () { + let tabs = await this.webExt.background.browser.tabs.query({}); + console.log("tabs", tabs); // new Tab opening activeTab.url in default container newTab = await this.webExt.background.browser.tabs._create({ cookieStoreId: "firefox-default", @@ -32,14 +37,14 @@ describe("Assignment Feature", function () { webRequestError: true // because request is canceled due to reopening } }); + tabs = await this.webExt.background.browser.tabs.query({}); + console.log("tabs", tabs) }); it("should open the confirm page", async function () { // should have created a new tab with the confirm page this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({ - url: "moz-extension://fake/confirm-page.html?" + - `url=${encodeURIComponent(url)}` + - `&cookieStoreId=${this.webExt.tab.cookieStoreId}`, + url: "http://example.com", cookieStoreId: undefined, openerTabId: null, index: 2, diff --git a/test/features/containers.test.js b/test/features/containers.test.js index d50a6b8..36624ab 100644 --- a/test/features/containers.test.js +++ b/test/features/containers.test.js @@ -11,8 +11,9 @@ describe("Containers Management", function () { describe("creating a new container", function () { beforeEach(async function () { - await this.webExt.popup.helper.clickElementById("container-add-link"); - await this.webExt.popup.helper.clickElementById("edit-container-ok-link"); + await this.webExt.popup.helper.clickElementById("manage-containers-link"); + await this.webExt.popup.helper.clickElementById("new-container"); + await this.webExt.popup.helper.clickElementById("create-container-ok-link"); }); it("should create it in the browser as well", function () { @@ -21,8 +22,9 @@ describe("Containers Management", function () { describe("removing it afterwards", function () { beforeEach(async function () { - await this.webExt.popup.helper.clickElementById("edit-containers-link"); - await this.webExt.popup.helper.clickElementByQuerySelectorAll(".delete-container-icon", "last"); + await this.webExt.popup.helper.clickElementById("manage-containers-link"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".menu-item", "last"); + await this.webExt.popup.helper.clickElementById("delete-container-button"); await this.webExt.popup.helper.clickElementById("delete-container-ok-link"); }); diff --git a/test/features/external-webextensions.test.js b/test/features/external-webextensions.test.js index f3c6810..63038d9 100644 --- a/test/features/external-webextensions.test.js +++ b/test/features/external-webextensions.test.js @@ -17,7 +17,7 @@ describe("External Webextensions", function () { }); describe("with contextualIdentities permissions", function () { - it("should be able to get assignments", async function () { + it.only("should be able to get assignments", async function () { this.webExt.background.browser.management.get.resolves({ permissions: ["contextualIdentities"] }); diff --git a/test/features/sync.test.js b/test/features/sync.test.js index 70c452f..1e4070a 100644 --- a/test/features/sync.test.js +++ b/test/features/sync.test.js @@ -11,7 +11,7 @@ describe("Sync", function() { delete this.syncHelper; }); - it.only("testIdentityStateCleanup", async function() { + it("testIdentityStateCleanup", async function() { await this.syncHelper.stopSyncListeners(); await this.syncHelper.setState({}, LOCAL_DATA, TEST_CONTAINERS, []);