-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from satoryu/show-count-of-selected-tabs
Show the count of selected tabs on the button
- Loading branch information
Showing
7 changed files
with
99 additions
and
40 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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
function createLinkForTab(tab) { | ||
async function createLinkForTab(tab) { | ||
const title = tab.title.replaceAll(/[\[\]]/g, '').replaceAll(/`(.*)`/g, '$1') | ||
|
||
return `[${tab.url} ${title}]` | ||
} | ||
|
||
function createLinksForTabs(tabs) { | ||
return tabs.map(createLinkForTab).map((link) => (` ${link}`)).join("\n") | ||
async function createLinksForTabs(tabs) { | ||
return Promise.all(tabs.map(createLinkForTab)) | ||
.then((links) => (links.map((link) => (` ${link}`)).join("\n"))) | ||
} | ||
|
||
export { createLinksForTabs, createLinkForTab } |
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,51 @@ | ||
import { findTabs, getCurrentTab, getSelectedTabs, getAllTabsOnCurrentWindow } from '../src/chrome.js' | ||
|
||
global.chrome = { | ||
tabs: { | ||
query: jest.fn(options => (options)) | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
chrome.tabs.query.mockClear() | ||
}) | ||
|
||
describe("findTabs", () => { | ||
it("passes given options to chrome.tabs.query()", async () => { | ||
const expectedOptions = { active: true, currentWindow: true } | ||
|
||
await findTabs(expectedOptions) | ||
|
||
expect(chrome.tabs.query.mock.calls[0][0]).toEqual(expectedOptions) | ||
}) | ||
}) | ||
|
||
describe("getCurrentTab", () => { | ||
it("passes a specific option to findTabs to get the current tab", async () => { | ||
const expectedOptions = { active: true, currentWindow: true } | ||
|
||
await getCurrentTab() | ||
|
||
expect(chrome.tabs.query.mock.calls[0][0]).toEqual(expectedOptions) | ||
}) | ||
}) | ||
|
||
describe("getSelectedTabs", () => { | ||
it("passes a specific option to findTabs to get the selected tabs", async () => { | ||
const expectedOptions = { highlighted: true, currentWindow: true } | ||
|
||
await getSelectedTabs() | ||
|
||
expect(chrome.tabs.query.mock.calls[0][0]).toEqual(expectedOptions) | ||
}) | ||
}) | ||
|
||
describe("getAllTabsOnCurrentWindow", () => { | ||
it("passes a specific option to findTabs to get the selected tabs", async () => { | ||
const expectedOptions = { currentWindow: true } | ||
|
||
await getAllTabsOnCurrentWindow() | ||
|
||
expect(chrome.tabs.query.mock.calls[0][0]).toEqual(expectedOptions) | ||
}) | ||
}) |
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