2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/spec/unit/defaults_spec.lua

123 lines
3.6 KiB
Lua
Raw Normal View History

describe("defaults module", function()
local Defaults, DataStorage
setup(function()
require("commonrequire")
Defaults = require("apps/filemanager/filemanagersetdefaults")
DataStorage = require("datastorage")
end)
it("should load all defaults from defaults.lua", function()
Defaults:init()
assert.is_same(113, #Defaults.defaults_name)
assert.is_same("DFULL_SCREEN", Defaults.defaults_name[57])
end)
it("should save changes to defaults.persistent.lua", function()
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
os.remove(persistent_filename)
-- not in persistent but checked in defaults
Defaults.changed[21] = true
Defaults.changed[48] = true
Defaults.changed[57] = true
Defaults.changed[92] = true
Defaults.changed[108] = true
2016-07-17 05:46:17 +00:00
Defaults:saveSettings()
assert.is_same(113, #Defaults.defaults_name)
assert.is_same("DFULL_SCREEN", Defaults.defaults_name[57])
assert.is_same("SEARCH_LIBRARY_PATH", Defaults.defaults_name[108])
assert.is_same("DTAP_ZONE_BACKWARD", Defaults.defaults_name[92])
assert.is_same("DCREREADER_CONFIG_WORD_GAP_LARGE", Defaults.defaults_name[48])
assert.is_same("DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE", Defaults.defaults_name[21])
local fd = io.open(persistent_filename, "r")
assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_LIBRARY_PATH = ""
DTAP_ZONE_BACKWARD = {
["y"] = 0,
["x"] = 0,
["h"] = 1,
["w"] = 0.25
}
DCREREADER_CONFIG_WORD_GAP_LARGE = 100
DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE = {
[1] = 50,
[2] = 50
}
DFULL_SCREEN = 1
]],
fd:read("*a"))
fd:close()
-- in persistent
Defaults:init()
Defaults.changed[57] = true
Defaults.defaults_value[57] = 2
Defaults.changed[92] = true
Defaults.defaults_value[92] = {
y = 10,
x = 10.125,
h = 20.25,
w = 20.75
}
2016-07-17 05:46:17 +00:00
Defaults:saveSettings()
fd = io.open(persistent_filename)
assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_LIBRARY_PATH = ""
DTAP_ZONE_BACKWARD = {
["y"] = 10,
["x"] = 10.125,
["h"] = 20.25,
["w"] = 20.75
}
DCREREADER_CONFIG_WORD_GAP_LARGE = 100
DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE = {
[2] = 50,
[1] = 50
}
DFULL_SCREEN = 2
]],
fd:read("*a"))
fd:close()
os.remove(persistent_filename)
end)
it("should delete entry from defaults.persistent.lua if value is reverted back to default", function()
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
local fd = io.open(persistent_filename, "w")
fd:write(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE = {
[1] = 15,
[2] = 15
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 2
]])
fd:close()
-- in persistent
Defaults:init()
Defaults.changed[57] = true
Defaults.defaults_value[57] = 1
2016-07-17 05:46:17 +00:00
Defaults:saveSettings()
fd = io.open(persistent_filename)
assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE = {
[2] = 15,
[1] = 15
}
DHINTCOUNT = 2
DFULL_SCREEN = 1
DCREREADER_VIEW_MODE = "page"
]],
fd:read("*a"))
fd:close()
os.remove(persistent_filename)
end)
end)