From adc7ddccfc7499bf2dc1caa4086187a54c310517 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 12 Mar 2016 13:59:49 -0800 Subject: [PATCH] test: start every test suit with a clean reader setting --- base | 2 +- frontend/apps/reader/modules/readerfooter.lua | 10 +++ spec/unit/commonrequire.lua | 2 + spec/unit/readerfooter_spec.lua | 70 +++++++++++++++---- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/base b/base index 84d7b7a06..897b80992 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 84d7b7a064a6c70a069366b3eb3eb5d9cf4721b9 +Subproject commit 897b809920b8b57c29375c840abec4d2fdf5d2ab diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 531a29856..bd48840d8 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -53,6 +53,16 @@ function ReaderFooter:init() book_time_to_read = true, chapter_time_to_read = true, } + if self.settings.disabled then + self.resetLayout = function() end + self.onCloseDocument = function() end + self.onPageUpdate = function() end + self.onPosUpdate = function() end + self.onUpdatePos = function() end + self.onSetStatusLine = function() end + return + end + self.progress_text = TextWidget:new{ text = '', face = Font:getFace(self.text_font_face, self.text_font_size), diff --git a/spec/unit/commonrequire.lua b/spec/unit/commonrequire.lua index 6f6b2c188..9ebb11204 100644 --- a/spec/unit/commonrequire.lua +++ b/spec/unit/commonrequire.lua @@ -3,6 +3,8 @@ package.path = "?.lua;common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath -- global reader settings +local DataStorage = require("datastorage") +os.remove(DataStorage:getDataDir().."/settings.reader.lua") local DocSettings = require("docsettings") G_reader_settings = DocSettings:open(".reader") diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index 4fac524c8..c945a76cd 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -8,6 +8,22 @@ local purgeDir = require("ffi/util").purgeDir local Screen = require("device").screen describe("Readerfooter module", function() + before_each(function() + G_reader_settings:saveSetting("footer", { + disabled = false, + all_at_once = true, + progress_bar = true, + toc_markers = true, + battery = true, + time = true, + page_progress = true, + pages_left = true, + percentage = true, + book_time_to_read = true, + chapter_time_to_read = true, + }) + end) + it("should setup footer for epub without error", function() local sample_epub = "spec/front/unit/data/juliet.epub" purgeDir(DocSettings:getSidecarDir(sample_epub)) @@ -16,8 +32,6 @@ describe("Readerfooter module", function() local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_epub), } - readerui.view.footer.settings.page_progress = true - readerui.view.footer.settings.all_at_once = true readerui.view.footer:updateFooter() timeinfo = readerui.view.footer:getTimeInfo() -- stats has not been initialized here, so we get na TB and TC @@ -33,8 +47,6 @@ describe("Readerfooter module", function() local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_pdf), } - readerui.view.footer.settings.page_progress = true - readerui.view.footer.settings.all_at_once = true readerui.view.footer:updateFooter() timeinfo = readerui.view.footer:getTimeInfo() assert.are.same('B:0% | '..timeinfo..' | 1 / 2 | => 1 | R:50% | TB: na | TC: na', @@ -50,8 +62,6 @@ describe("Readerfooter module", function() document = DocumentRegistry:openDocument(sample_pdf), } local footer = readerui.view.footer - footer.settings.page_progress = true - footer.settings.all_at_once = true footer:resetLayout() footer:updateFooter() timeinfo = readerui.view.footer:getTimeInfo() @@ -92,15 +102,22 @@ describe("Readerfooter module", function() document = DocumentRegistry:openDocument(sample_pdf), } local footer = readerui.view.footer - footer.settings.page_progress = true - footer.settings.all_at_once = true - footer:resetLayout() - assert.are.same(529, footer.progress_bar.width) + local horizontal_margin = Screen:scaleBySize(10)*2 + footer:updateFooter() + assert.is.same(357, footer.text_width) + assert.is.same(600, footer.progress_bar.width + + footer.text_width + + horizontal_margin) + assert.is.same(223, footer.progress_bar.width) local old_screen_getwidth = Screen.getWidth Screen.getWidth = function() return 900 end footer:resetLayout() - assert.are.same(829, footer.progress_bar.width) + assert.is.same(357, footer.text_width) + assert.is.same(900, footer.progress_bar.width + + footer.text_width + + horizontal_margin) + assert.is.same(523, footer.progress_bar.width) Screen.getWidth = old_screen_getwidth end) @@ -113,8 +130,6 @@ describe("Readerfooter module", function() document = DocumentRegistry:openDocument(sample_epub), } local footer = readerui.view.footer - footer.settings.page_progress = true - footer.settings.all_at_once = true readerui.view.document.info.number_of_pages = 5000 footer:onPageUpdate(1) assert.are.same(207, footer.progress_bar.width) @@ -133,6 +148,10 @@ describe("Readerfooter module", function() UIManager:quit() assert.are.same({}, UIManager._task_queue) + G_reader_settings:saveSetting("footer", { + page_progress = true, + auto_refresh_time = true, + }) local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_epub), } @@ -154,4 +173,29 @@ describe("Readerfooter module", function() end assert.is.same(0, found) end) + + it("should not schedule auto refresh time task if footer is disabled", function() + local sample_epub = "spec/front/unit/data/juliet.epub" + purgeDir(DocSettings:getSidecarDir(sample_epub)) + os.remove(DocSettings:getHistoryPath(sample_epub)) + UIManager:quit() + + assert.are.same({}, UIManager._task_queue) + G_reader_settings:saveSetting("footer", { + disabled = true, + page_progress = true, + auto_refresh_time = true, + }) + local readerui = ReaderUI:new{ + document = DocumentRegistry:openDocument(sample_epub), + } + local footer = readerui.view.footer + local found = 0 + for _,task in ipairs(UIManager._task_queue) do + if task.action == footer.autoRefreshTime then + found = found + 1 + end + end + assert.is.same(0, found) + end) end)