2016-05-02 02:39:31 +00:00
|
|
|
describe("defaults module", function()
|
2022-09-27 23:10:50 +00:00
|
|
|
local Defaults, DataStorage, lfs, persistent_filename
|
2016-05-02 02:39:31 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
DataStorage = require("datastorage")
|
2022-09-27 23:10:50 +00:00
|
|
|
persistent_filename = DataStorage:getDataDir() .. "/defaults.defaults_spec.lua"
|
|
|
|
Defaults = require("luadefaults"):open(persistent_filename)
|
|
|
|
lfs = require("libs/libkoreader-lfs")
|
2016-05-02 02:39:31 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should load all defaults from defaults.lua", function()
|
2022-09-27 23:10:50 +00:00
|
|
|
assert.is_true(Defaults:has("DHINTCOUNT"))
|
|
|
|
Defaults:close()
|
2016-05-02 02:39:31 +00:00
|
|
|
end)
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
it("should save changes to defaults.custom.lua", function()
|
2016-05-02 02:39:31 +00:00
|
|
|
os.remove(persistent_filename)
|
2022-09-27 23:10:50 +00:00
|
|
|
os.remove(persistent_filename .. ".old")
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
-- This defaults to false
|
|
|
|
Defaults:makeTrue("DSHOWOVERLAP")
|
|
|
|
assert.is_true(Defaults:hasBeenCustomized("DSHOWOVERLAP"))
|
|
|
|
assert.is_true(Defaults:isTrue("DSHOWOVERLAP"))
|
2020-05-03 16:06:58 +00:00
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
Defaults:close()
|
|
|
|
assert.is_true(lfs.attributes(persistent_filename, "mode") == "file")
|
|
|
|
|
|
|
|
Defaults = nil
|
|
|
|
Defaults = require("luadefaults"):open(persistent_filename)
|
|
|
|
assert.is_true(Defaults:hasBeenCustomized("DSHOWOVERLAP"))
|
|
|
|
assert.is_true(Defaults:isTrue("DSHOWOVERLAP"))
|
|
|
|
Defaults:makeFalse("DSHOWOVERLAP")
|
|
|
|
Defaults:close()
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2016-05-26 07:44:42 +00:00
|
|
|
os.remove(persistent_filename)
|
2022-09-27 23:10:50 +00:00
|
|
|
os.remove(persistent_filename .. ".old")
|
2016-05-26 07:44:42 +00:00
|
|
|
end)
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
it("should delete entry from defaults.custom.lua if value is reverted back to default", function()
|
|
|
|
-- This defaults to false
|
|
|
|
Defaults:makeTrue("DSHOWOVERLAP")
|
|
|
|
assert.is_true(Defaults:hasBeenCustomized("DSHOWOVERLAP"))
|
|
|
|
assert.is_true(Defaults:isTrue("DSHOWOVERLAP"))
|
|
|
|
Defaults:makeFalse("DSHOWOVERLAP")
|
|
|
|
assert.is_true(Defaults:hasNotBeenCustomized("DSHOWOVERLAP"))
|
|
|
|
assert.is_true(Defaults:isFalse("DSHOWOVERLAP"))
|
|
|
|
Defaults:close()
|
2016-05-02 02:39:31 +00:00
|
|
|
end)
|
|
|
|
end)
|