2014-11-05 08:58:09 +00:00
|
|
|
describe("FileManager module", function()
|
2016-06-04 05:05:14 +00:00
|
|
|
local FileManager, lfs, docsettings, UIManager, Screen, util
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2016-06-04 05:05:14 +00:00
|
|
|
FileManager = require("apps/filemanager/filemanager")
|
|
|
|
Screen = require("device").screen
|
2017-06-23 17:04:11 +00:00
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
docsettings = require("docsettings")
|
|
|
|
lfs = require("libs/libkoreader-lfs")
|
2016-06-04 05:05:14 +00:00
|
|
|
util = require("ffi/util")
|
|
|
|
end)
|
2014-11-05 08:58:09 +00:00
|
|
|
it("should show file manager", function()
|
2014-11-05 10:06:05 +00:00
|
|
|
UIManager:quit()
|
|
|
|
local filemanager = FileManager:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
root_path = "../../test",
|
|
|
|
}
|
|
|
|
UIManager:show(filemanager)
|
2021-05-18 18:54:54 +00:00
|
|
|
UIManager:scheduleIn(1, function() filemanager:onClose() end)
|
2014-11-05 08:58:09 +00:00
|
|
|
UIManager:run()
|
|
|
|
end)
|
2016-01-07 06:44:07 +00:00
|
|
|
it("should show error on non-existent file", function()
|
|
|
|
local filemanager = FileManager:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
root_path = "../../test",
|
|
|
|
}
|
|
|
|
local old_show = UIManager.show
|
|
|
|
local tmp_fn = "/abc/123/test/foo.bar.baz.tmp.epub.pdf"
|
|
|
|
UIManager.show = function(self, w)
|
2021-04-29 18:26:33 +00:00
|
|
|
assert.Equals(w.text, "File not found:\n"..tmp_fn)
|
2016-01-07 06:44:07 +00:00
|
|
|
end
|
|
|
|
assert.is_nil(lfs.attributes(tmp_fn))
|
2023-12-10 06:05:34 +00:00
|
|
|
filemanager:showDeleteFileDialog(tmp_fn)
|
2016-01-07 06:44:07 +00:00
|
|
|
UIManager.show = old_show
|
2021-05-18 18:54:54 +00:00
|
|
|
filemanager:onClose()
|
2016-01-07 06:44:07 +00:00
|
|
|
end)
|
2023-02-17 21:06:55 +00:00
|
|
|
it("should not delete not empty sidecar folder", function()
|
2016-01-07 06:44:07 +00:00
|
|
|
local filemanager = FileManager:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
root_path = "../../test",
|
|
|
|
}
|
|
|
|
|
2020-02-03 19:08:18 +00:00
|
|
|
local tmp_fn = "../../test/2col.test.tmp.foo"
|
2016-01-07 06:44:07 +00:00
|
|
|
util.copyFile("../../test/2col.pdf", tmp_fn)
|
|
|
|
|
|
|
|
local tmp_sidecar = docsettings:getSidecarDir(util.realpath(tmp_fn))
|
|
|
|
lfs.mkdir(tmp_sidecar)
|
2023-10-31 05:30:39 +00:00
|
|
|
local tmp_sidecar_file = docsettings:getSidecarDir(util.realpath(tmp_fn)).."/"..docsettings.getSidecarFilename(util.realpath(tmp_fn))
|
2023-02-17 21:06:55 +00:00
|
|
|
local tmp_sidecar_file_foo = tmp_sidecar_file .. ".foo" -- non-docsettings file
|
|
|
|
local tmpsf = io.open(tmp_sidecar_file, "w")
|
|
|
|
tmpsf:write("{}")
|
|
|
|
tmpsf:close()
|
|
|
|
util.copyFile(tmp_sidecar_file, tmp_sidecar_file_foo)
|
2016-01-07 06:44:07 +00:00
|
|
|
local old_show = UIManager.show
|
|
|
|
|
|
|
|
-- make sure file exists
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_fn))
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_sidecar))
|
2023-02-17 21:06:55 +00:00
|
|
|
assert.is_not_nil(lfs.attributes(tmp_sidecar_file))
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_sidecar_file_foo))
|
2016-01-07 06:44:07 +00:00
|
|
|
|
|
|
|
UIManager.show = function(self, w)
|
2021-04-29 18:26:33 +00:00
|
|
|
assert.Equals(w.text, "Deleted file:\n"..tmp_fn)
|
2016-01-07 06:44:07 +00:00
|
|
|
end
|
2023-02-17 21:06:55 +00:00
|
|
|
filemanager:deleteFile(tmp_fn, true)
|
2016-01-07 06:44:07 +00:00
|
|
|
UIManager.show = old_show
|
2021-05-18 18:54:54 +00:00
|
|
|
filemanager:onClose()
|
2016-01-07 06:44:07 +00:00
|
|
|
|
2023-02-17 21:06:55 +00:00
|
|
|
-- make sure sdr folder exists
|
2016-01-07 06:44:07 +00:00
|
|
|
assert.is_nil(lfs.attributes(tmp_fn))
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_sidecar))
|
2023-02-17 21:06:55 +00:00
|
|
|
os.remove(tmp_sidecar_file_foo)
|
2016-01-07 06:44:07 +00:00
|
|
|
os.remove(tmp_sidecar)
|
|
|
|
end)
|
|
|
|
it("should delete document with its settings", function()
|
|
|
|
local filemanager = FileManager:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
root_path = "../../test",
|
|
|
|
}
|
|
|
|
|
|
|
|
local tmp_fn = "../../test/2col.test.tmp.pdf"
|
|
|
|
util.copyFile("../../test/2col.pdf", tmp_fn)
|
|
|
|
|
|
|
|
local tmp_sidecar = docsettings:getSidecarDir(util.realpath(tmp_fn))
|
|
|
|
lfs.mkdir(tmp_sidecar)
|
2023-10-31 05:30:39 +00:00
|
|
|
local tmp_sidecar_file = docsettings:getSidecarDir(util.realpath(tmp_fn)).."/"..docsettings.getSidecarFilename(util.realpath(tmp_fn))
|
2023-02-17 21:06:55 +00:00
|
|
|
local tmpsf = io.open(tmp_sidecar_file, "w")
|
|
|
|
tmpsf:write("{}")
|
|
|
|
tmpsf:close()
|
2023-03-02 06:39:09 +00:00
|
|
|
lfs.mkdir(require("datastorage"):getHistoryDir())
|
2016-01-07 06:44:07 +00:00
|
|
|
local tmp_history = docsettings:getHistoryPath(tmp_fn)
|
|
|
|
local tmpfp = io.open(tmp_history, "w")
|
|
|
|
tmpfp:write("{}")
|
|
|
|
tmpfp:close()
|
|
|
|
local old_show = UIManager.show
|
|
|
|
|
|
|
|
-- make sure file exists
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_fn))
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_sidecar))
|
|
|
|
assert.is_not_nil(lfs.attributes(tmp_history))
|
|
|
|
|
|
|
|
UIManager.show = function(self, w)
|
2021-04-29 18:26:33 +00:00
|
|
|
assert.Equals(w.text, "Deleted file:\n"..tmp_fn)
|
2016-01-07 06:44:07 +00:00
|
|
|
end
|
2023-02-17 21:06:55 +00:00
|
|
|
filemanager:deleteFile(tmp_fn, true)
|
2016-01-07 06:44:07 +00:00
|
|
|
UIManager.show = old_show
|
2021-05-18 18:54:54 +00:00
|
|
|
filemanager:onClose()
|
2016-01-07 06:44:07 +00:00
|
|
|
|
|
|
|
assert.is_nil(lfs.attributes(tmp_fn))
|
|
|
|
assert.is_nil(lfs.attributes(tmp_sidecar))
|
|
|
|
assert.is_nil(lfs.attributes(tmp_history))
|
|
|
|
end)
|
2014-11-05 08:58:09 +00:00
|
|
|
end)
|