From c8cd1d67f513a6708d8c4366a80ddfa862d89398 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 12 Mar 2016 01:00:40 -0800 Subject: [PATCH] test: more readerfooter tests --- spec/unit/readerfooter_spec.lua | 120 +++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index a0da5500d..4fac524c8 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -2,8 +2,10 @@ require("commonrequire") local DocumentRegistry = require("document/documentregistry") local ReaderUI = require("apps/reader/readerui") local DocSettings = require("docsettings") +local UIManager = require("ui/uimanager") local DEBUG = require("dbg") local purgeDir = require("ffi/util").purgeDir +local Screen = require("device").screen describe("Readerfooter module", function() it("should setup footer for epub without error", function() @@ -16,7 +18,7 @@ describe("Readerfooter module", function() } readerui.view.footer.settings.page_progress = true readerui.view.footer.settings.all_at_once = true - readerui.view.footer:updateFooterPage() + readerui.view.footer:updateFooter() timeinfo = readerui.view.footer:getTimeInfo() -- stats has not been initialized here, so we get na TB and TC assert.are.same('B:0% | '..timeinfo..' | 1 / 1 | => 0 | R:100% | TB: na | TC: na', @@ -33,9 +35,123 @@ describe("Readerfooter module", function() } readerui.view.footer.settings.page_progress = true readerui.view.footer.settings.all_at_once = true - readerui.view.footer:updateFooterPage() + readerui.view.footer:updateFooter() timeinfo = readerui.view.footer:getTimeInfo() assert.are.same('B:0% | '..timeinfo..' | 1 / 2 | => 1 | R:50% | TB: na | TC: na', readerui.view.footer.progress_text.text) end) + + it("should switch between different modes", function() + local sample_pdf = "spec/front/unit/data/2col.pdf" + purgeDir(DocSettings:getSidecarDir(sample_pdf)) + os.remove(DocSettings:getHistoryPath(sample_pdf)) + + local readerui = ReaderUI:new{ + 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() + assert.are.same('B:0% | '..timeinfo..' | 1 / 2 | => 1 | R:50% | TB: na | TC: na', + footer.progress_text.text) + footer.mode = 1 + footer.settings.all_at_once = false + footer:updateFooter() + assert.are.same('1 / 2', footer.progress_text.text) + + footer.mode = 3 + footer:updateFooter() + assert.are.same('=> 1', footer.progress_text.text) + + footer.mode = 4 + footer:updateFooter() + assert.are.same('B:0%', footer.progress_text.text) + + footer.mode = 5 + footer:updateFooter() + assert.are.same('R:50%', footer.progress_text.text) + + footer.mode = 6 + footer:updateFooter() + assert.are.same('TB: na', footer.progress_text.text) + + footer.mode = 7 + footer:updateFooter() + assert.are.same('TC: na', footer.progress_text.text) + end) + + it("should pick up screen resize in resetLayout", function() + local sample_pdf = "spec/front/unit/data/2col.pdf" + purgeDir(DocSettings:getSidecarDir(sample_pdf)) + os.remove(DocSettings:getHistoryPath(sample_pdf)) + + local readerui = ReaderUI:new{ + 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 old_screen_getwidth = Screen.getWidth + Screen.getWidth = function() return 900 end + footer:resetLayout() + assert.are.same(829, footer.progress_bar.width) + Screen.getWidth = old_screen_getwidth + end) + + it("should update width on PosUpdate event", function() + local sample_epub = "spec/front/unit/data/juliet.epub" + purgeDir(DocSettings:getSidecarDir(sample_epub)) + os.remove(DocSettings:getHistoryPath(sample_epub)) + + local readerui = ReaderUI:new{ + 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) + assert.are.same(373, footer.text_width) + + footer:onPageUpdate(1000) + assert.are.same(151, footer.progress_bar.width) + assert.are.same(429, footer.text_width) + end) + + + it("should schedule/unschedule auto refresh time task", 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) + 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(1, found) + + footer:onCloseDocument() + 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)