This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
26,196 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
src/sidebar/dist | ||
src/test/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import TabCenter from "./tabcenter.js"; | ||
|
||
// Start-it up! | ||
const tabCenter = new TabCenter(); | ||
tabCenter.init(); | ||
|
||
// For testing! | ||
window.tabCenter = tabCenter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env mocha */ | ||
function loadScript(src) { | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement("script"); | ||
script.src = src; | ||
script.onload = resolve; | ||
script.onerror = reject; | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
|
||
(async () => { | ||
await Promise.all([ | ||
loadScript("../test/vendor/mocha.js"), | ||
loadScript("../test/vendor/chai.js") | ||
]); | ||
mocha.setup({ui: "tdd", timeout: 10000}).reporter("spec"); | ||
|
||
await loadScript("../test/tabs-position.test.js"); | ||
|
||
mocha.run(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* eslint-env mocha */ | ||
/* global chai, tabCenter */ | ||
|
||
suite("tabs positions and indexes", () => { | ||
const {assert} = chai; | ||
|
||
function assertDOMOrderCorrect(ffTabs) { | ||
const ffTabsIds = ffTabs.map(t => t.id); | ||
const domTabsIds = [...document.querySelectorAll(".tab")] | ||
.map(e => parseInt(e.getAttribute("data-tab-id"))); | ||
assert.deepEqual(domTabsIds, ffTabsIds, "Order of tabs in the DOM is correct."); | ||
} | ||
|
||
function assertIndexesCorrect(ffTabs) { | ||
const tcTabs = tabCenter._tabList._tabs; | ||
assert.equal(tcTabs.size, ffTabs.length, "TabList number of tabs is correct."); | ||
|
||
for (const ffTab of ffTabs) { | ||
const tcTab = tcTabs.get(ffTab.id); | ||
assert.ok(tcTab, "found the TC tab"); | ||
assert.equal(tcTab.index, ffTab.index, "Tab index is correct."); | ||
} | ||
} | ||
|
||
async function assertOrderAndIndexes() { | ||
const ffTabs = await browser.tabs.query({windowId: ourWindowId}); | ||
assertDOMOrderCorrect(ffTabs); | ||
assertIndexesCorrect(ffTabs); | ||
} | ||
|
||
let ourWindowId; | ||
suiteSetup(async () => { | ||
const ourWindow = await browser.windows.getCurrent(); | ||
ourWindowId = ourWindow.id; | ||
}); | ||
|
||
async function cleanState() { | ||
const windows = await browser.windows.getAll(); | ||
for (const win of windows) { | ||
if (win.id !== ourWindowId) { | ||
await browser.windows.remove(win.id); | ||
} | ||
} | ||
const tabs = (await browser.tabs.query({windowId: ourWindowId})).map(t => t.id); | ||
await browser.tabs.create({windowId: ourWindowId}); | ||
await browser.tabs.remove(tabs); | ||
} | ||
|
||
setup(() => cleanState()); | ||
suiteTeardown(() => cleanState()); | ||
|
||
test("sanity check", async () => { | ||
const ffTabs = await browser.tabs.query({windowId: ourWindowId}); | ||
assertDOMOrderCorrect(ffTabs); | ||
assertIndexesCorrect(ffTabs); | ||
}); | ||
test("insertions/deletions", async () => { | ||
await browser.tabs.create({}); | ||
const {id: tabID1} = await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.remove(tabID1); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.create({index: 1}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.create({}); | ||
await assertOrderAndIndexes(); | ||
}); | ||
test("moves", async () => { | ||
await browser.tabs.create({}); | ||
const {id: tabID1} = await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
await browser.tabs.move(tabID1, {index: 3}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.move(tabID1, {index: -1}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.move(tabID1, {index: 0}); | ||
await assertOrderAndIndexes(); | ||
}); | ||
test("attach from other window", async () => { | ||
await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
const {id: otherWindowId} = await browser.windows.create(); | ||
await assertOrderAndIndexes(); | ||
const {id: otherTabId1} = (await browser.tabs.query({windowId: otherWindowId}))[0]; | ||
const {id: otherTabId2} = await browser.tabs.create({windowId: otherWindowId}); | ||
const {id: otherTabId3} = await browser.tabs.create({windowId: otherWindowId}); | ||
|
||
await browser.tabs.move(otherTabId1, {windowId: ourWindowId, index: -1}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.move(otherTabId2, {windowId: ourWindowId, index: 0}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.move(otherTabId3, {windowId: ourWindowId, index: 2}); | ||
await assertOrderAndIndexes(); | ||
}); | ||
test("detach to other window", async () => { | ||
const {id: tabID1} = await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
const {id: tabID3} = await browser.tabs.create({}); | ||
await browser.tabs.create({}); | ||
const {id: otherWindowId} = await browser.windows.create({tabId: tabID3}); | ||
await assertOrderAndIndexes(); | ||
await browser.tabs.move(tabID1, {windowId: otherWindowId, index: -1}); | ||
await assertOrderAndIndexes(); | ||
}); | ||
}); |
Oops, something went wrong.