2016-05-02 02:39:31 +00:00
|
|
|
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()
|
2016-06-14 18:52:53 +00:00
|
|
|
assert.is_same(#Defaults.defaults_name, 77)
|
|
|
|
assert.is_same(Defaults.defaults_name[28], 'DHINTCOUNT')
|
2016-05-02 02:39:31 +00:00
|
|
|
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[14] = true
|
|
|
|
Defaults.changed[19] = true
|
2016-06-14 18:52:53 +00:00
|
|
|
Defaults.changed[28] = true
|
|
|
|
Defaults.changed[63] = true
|
|
|
|
Defaults.changed[77] = true
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2016-06-14 18:52:53 +00:00
|
|
|
assert.is_same(#Defaults.defaults_name, 77)
|
|
|
|
assert.is_same(Defaults.defaults_name[28], 'DHINTCOUNT')
|
|
|
|
assert.is_same(Defaults.defaults_name[77], 'SEARCH_TITLE')
|
|
|
|
assert.is_same(Defaults.defaults_name[63], 'DTAP_ZONE_MENU')
|
2016-05-02 02:39:31 +00:00
|
|
|
assert.is_same(Defaults.defaults_name[19], 'DCREREADER_VIEW_MODE')
|
|
|
|
assert.is_same(Defaults.defaults_name[14],
|
|
|
|
'DCREREADER_CONFIG_MARGIN_SIZES_LARGE')
|
|
|
|
local fd = io.open(persistent_filename, "r")
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
|
|
|
SEARCH_TITLE = true
|
|
|
|
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
|
|
|
|
[1] = 20,
|
|
|
|
[2] = 20,
|
|
|
|
[3] = 20,
|
|
|
|
[4] = 20
|
|
|
|
}
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
|
|
|
DHINTCOUNT = 1
|
|
|
|
DTAP_ZONE_MENU = {
|
|
|
|
["y"] = 0,
|
|
|
|
["x"] = 0.125,
|
2017-04-24 06:33:12 +00:00
|
|
|
["h"] = 0.125,
|
2016-05-02 02:39:31 +00:00
|
|
|
["w"] = 0.75
|
|
|
|
}
|
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
-- in persistent
|
|
|
|
Defaults:init()
|
2016-06-14 18:52:53 +00:00
|
|
|
Defaults.changed[28] = true
|
|
|
|
Defaults.defaults_value[28] = 2
|
|
|
|
Defaults.changed[63] = true
|
|
|
|
Defaults.defaults_value[63] = {
|
2016-05-02 02:39:31 +00:00
|
|
|
y = 10,
|
|
|
|
x = 10.125,
|
|
|
|
h = 20.25,
|
|
|
|
w = 20.75
|
|
|
|
}
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2016-05-02 02:39:31 +00:00
|
|
|
fd = io.open(persistent_filename)
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
|
|
|
SEARCH_TITLE = true
|
|
|
|
DHINTCOUNT = 2
|
|
|
|
DTAP_ZONE_MENU = {
|
|
|
|
["y"] = 10,
|
|
|
|
["x"] = 10.125,
|
|
|
|
["h"] = 20.25,
|
|
|
|
["w"] = 20.75
|
|
|
|
}
|
|
|
|
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
|
|
|
|
[1] = 20,
|
|
|
|
[2] = 20,
|
|
|
|
[3] = 20,
|
|
|
|
[4] = 20
|
|
|
|
}
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
2016-05-26 07:44:42 +00:00
|
|
|
]],
|
|
|
|
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_MARGIN_SIZES_LARGE = {
|
|
|
|
[1] = 20,
|
|
|
|
[2] = 20,
|
|
|
|
[3] = 20,
|
|
|
|
[4] = 20
|
|
|
|
}
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
|
|
|
DHINTCOUNT = 2
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
-- in persistent
|
|
|
|
Defaults:init()
|
2016-06-14 18:52:53 +00:00
|
|
|
Defaults.changed[28] = true
|
|
|
|
Defaults.defaults_value[28] = 1
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2016-05-26 07:44:42 +00:00
|
|
|
fd = io.open(persistent_filename)
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
|
|
|
SEARCH_TITLE = true
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
|
|
|
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
|
|
|
|
[1] = 20,
|
|
|
|
[2] = 20,
|
|
|
|
[3] = 20,
|
|
|
|
[4] = 20
|
|
|
|
}
|
2016-05-02 02:39:31 +00:00
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
os.remove(persistent_filename)
|
|
|
|
end)
|
|
|
|
end)
|