2021-08-30 07:11:23 +00:00
|
|
|
describe("Exporter plugin module", function()
|
2022-05-06 20:44:28 +00:00
|
|
|
local readerui
|
2020-01-25 16:28:13 +00:00
|
|
|
local sample_clippings, sample_epub
|
2020-07-01 20:17:41 +00:00
|
|
|
local DocumentRegistry, Screen
|
2020-01-25 16:28:13 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2020-01-25 16:28:13 +00:00
|
|
|
sample_epub = "spec/front/unit/data/juliet.epub"
|
2022-05-06 20:44:28 +00:00
|
|
|
readerui = ReaderUI:new {
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2020-01-25 16:28:13 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
|
|
|
|
|
|
|
sample_clippings = {
|
|
|
|
["Title1"] = {
|
|
|
|
[1] = {
|
|
|
|
[1] = {
|
|
|
|
["page"] = 6,
|
|
|
|
["time"] = 1578946897,
|
|
|
|
["sort"] = "highlight",
|
2022-05-06 20:44:28 +00:00
|
|
|
["text"] = "Some important stuff 1",
|
|
|
|
["drawer"] = "lighten"
|
2020-01-25 16:28:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
[1] = {
|
|
|
|
["page"] = 13,
|
|
|
|
["time"] = 1578946903,
|
|
|
|
["sort"] = "highlight",
|
2022-05-06 20:44:28 +00:00
|
|
|
["text"] = "Some important stuff 2",
|
|
|
|
["drawer"] = "lighten"
|
2020-01-25 16:28:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
["file"] = "path/to/title1",
|
|
|
|
["exported"] = {
|
|
|
|
["txt"] = true,
|
|
|
|
["html"] = true,
|
|
|
|
},
|
|
|
|
["title"] = "Title1"
|
|
|
|
},
|
|
|
|
["Title2"] = {
|
|
|
|
[1] = {
|
|
|
|
[1] = {
|
|
|
|
["page"] = 233,
|
|
|
|
["time"] = 1578946918,
|
|
|
|
["sort"] = "highlight",
|
2022-05-06 20:44:28 +00:00
|
|
|
["text"] = "Some important stuff 3",
|
|
|
|
["drawer"] = "lighten"
|
2020-01-25 16:28:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
[1] = {
|
|
|
|
["page"] = 237,
|
|
|
|
["time"] = 1578947501,
|
|
|
|
["sort"] = "highlight",
|
|
|
|
["text"] = "",
|
2022-05-06 20:44:28 +00:00
|
|
|
["drawer"] = "lighten",
|
2020-01-25 16:28:13 +00:00
|
|
|
["image"] = {
|
|
|
|
["hash"] = "cb7b40a63afc89f0aa452f2b655877e6",
|
|
|
|
["png"] = "Binary Encoding of image"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
["file"] = "path/to/title2",
|
|
|
|
["exported"] = {
|
2022-05-06 20:44:28 +00:00
|
|
|
},
|
2020-01-25 16:28:13 +00:00
|
|
|
["title"] = "Title2"
|
|
|
|
},
|
2022-05-06 20:44:28 +00:00
|
|
|
}
|
2020-01-25 16:28:13 +00:00
|
|
|
|
|
|
|
end)
|
2020-12-19 04:32:23 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2020-01-25 16:28:13 +00:00
|
|
|
|
2022-05-06 20:44:28 +00:00
|
|
|
it("should write clippings to a timestamped txt file", function()
|
|
|
|
local timestamp = os.time()
|
|
|
|
readerui.exporter.targets["text"].timestamp = timestamp
|
|
|
|
local exportable = { sample_clippings.Title1 }
|
|
|
|
local file_path = readerui.exporter.targets["text"]:getFilePath(exportable)
|
|
|
|
readerui.exporter.targets["text"]:export(exportable)
|
|
|
|
local f = io.open(file_path, "r")
|
|
|
|
assert.is.truthy(string.find(f:read("*all"), "Some important stuff 1"))
|
|
|
|
f:close()
|
|
|
|
os.remove(file_path)
|
2020-01-25 16:28:13 +00:00
|
|
|
end)
|
|
|
|
|
2022-05-06 20:44:28 +00:00
|
|
|
it("should fail to export to non configured targets", function()
|
|
|
|
local ok = readerui.exporter.targets["joplin"]:export(sample_clippings)
|
|
|
|
assert.not_truthy(ok)
|
|
|
|
ok = readerui.exporter.targets["readwise"]:export(sample_clippings)
|
|
|
|
assert.not_truthy(ok)
|
2020-01-25 16:28:13 +00:00
|
|
|
end)
|
2020-12-19 04:32:23 +00:00
|
|
|
end)
|