Skip to content

Commit

Permalink
test: profile directory for chromium based browser
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jan 14, 2023
1 parent b2224e8 commit f40c08b
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lua/telescope/_extensions/bookmarks/chrome.lua
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ function chrome.collect_bookmarks(state, config)
return parse_bookmarks_data(data)
end

if _TEST then
chrome._get_profile_dir = get_profile_dir
end

return chrome
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profile": {
"info_cache": {
"Default": {
"name": "Default"
},
"Profile1": {
"name": "Astronaut"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"checksum": "",
"roots": {
"bookmark_bar": {
"children": [
{
"children": [
{
"name": "Google",
"type": "url",
"url": "https://google.com/"
},
{
"children": [
{
"name": "DuckDuckGo",
"type": "url",
"url": "https://duckduckgo.com/"
}
],
"name": "nested",
"type": "folder"
}
],
"name": "search",
"type": "folder"
},
{
"name": "ISRO",
"type": "url",
"url": "https://www.isro.gov.in/"
}
],
"name": "Bookmarks Bar",
"type": "folder"
},
"other": {
"children": [],
"name": "Other Bookmarks",
"type": "folder"
},
"synced": {
"children": [],
"name": "Mobile bookmarks",
"type": "folder"
}
},
"version": 1
}
81 changes: 71 additions & 10 deletions spec/unit/chrome_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,89 @@ local chrome = require "telescope._extensions.bookmarks.chrome"
local utils = require "telescope._extensions.bookmarks.utils"

describe("chrome", function()
describe("collect_bookmarks", function()
local match = require "luassert.match"
before_each(function()
stub(utils, "warn")
end)

after_each(function()
utils.warn:revert()
end)

describe("get_profile_dir", function()
it("should warn if OS not supported", function()
local profile_dir = chrome._get_profile_dir(
{ os_name = "random" },
{ selected_browser = "chrome" }
)

before_each(function()
stub(utils, "warn")
assert.is_nil(profile_dir)
assert.stub(utils.warn).was_called(1)
assert
.stub(utils.warn)
.was_called_with(match.matches "Unsupported OS for chrome")
end)

after_each(function()
utils.warn:revert()
it("should warn if state file not found", function()
local profile_dir = chrome._get_profile_dir(
{ os_name = "Darwin", os_homedir = "random" },
{ selected_browser = "chrome", profile_name = "random" }
)

assert.is_nil(profile_dir)
assert.stub(utils.warn).was_called(1)
assert
.stub(utils.warn)
.was_called_with(match.matches "No state file found for chrome at")
end)

it("should warn if OS not supported", function()
local bookmarks = chrome.collect_bookmarks(
{ os_name = "random" },
it("should warn if given profile does not exist", function()
local profile_dir = chrome._get_profile_dir(
{ os_name = "Darwin", os_homedir = "spec/fixtures" },
{ selected_browser = "chrome", profile_name = "random" }
)

assert.is_nil(profile_dir)
assert.stub(utils.warn).was_called(1)
assert
.stub(utils.warn)
.was_called_with(match.matches "Given chrome profile does not exist")
end)

it("should return the default profile if not provided", function()
local profile_dir = chrome._get_profile_dir(
{ os_name = "Darwin", os_homedir = "spec/fixtures" },
{ selected_browser = "chrome" }
)

assert.is_not_nil(profile_dir)
assert.is_true(vim.endswith(profile_dir, "Default"))
end)

it("should return the given profile", function()
local profile_dir = chrome._get_profile_dir(
{ os_name = "Darwin", os_homedir = "spec/fixtures" },
{ selected_browser = "chrome", profile_name = "Astronaut" }
)

assert.is_not_nil(profile_dir)
assert.is_true(vim.endswith(profile_dir, "Profile1"))
end)
end)

describe("collect_bookmarks", function()
local match = require "luassert.match"

it("should return nil if unable to get profile directory", function()
local bookmarks = chrome.collect_bookmarks(
{ os_name = "Darwin", os_homedir = "spec/fixtures" },
{ selected_browser = "chrome", profile_name = "random" }
)

assert.is_nil(bookmarks)
assert.stub(utils.warn).was_called(1)
assert
.stub(utils.warn)
.was_called_with(match.matches "Unsupported OS for chrome")
.was_called_with(match.matches "Given chrome profile does not exist")
end)

it("should warn if file is absent", function()
Expand Down

0 comments on commit f40c08b

Please sign in to comment.