<NME> readerlink_spec.lua
<BEF> describe("ReaderLink module", function()
    local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event, Screen

    setup(function()
        require("commonrequire")
        package.unloadAll()
        require("document/canvascontext"):init(require("device"))
        DocumentRegistry = require("document/documentregistry")
        Event = require("ui/event")
        ReaderUI = require("apps/reader/readerui")
        UIManager = require("ui/uimanager")
        Screen = require("device").screen
        sample_epub = "spec/front/unit/data/leaves.epub"
        sample_pdf = "spec/front/unit/data/paper.pdf"
    end)

    it("should jump to links in epub #nocov", function()
        }
        readerui.rolling:onGotoPage(4)
        readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
        assert.is.same(36, readerui.rolling.current_page)
    end)

    it("should jump to links in pdf page mode", function()
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should jump to links in pdf page mode", function()
        UIManager:quit()
        UIManager._exit_code = nil
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_pdf),
        }
        readerui:handleEvent(Event:new("SetScrollMode", false))
        readerui:handleEvent(Event:new("SetZoomMode", "page"))
        readerui.paging:onGotoPage(1)
        readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
        UIManager:run()
        assert.is.same(22, readerui.paging.current_page)
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should jump to links in pdf scroll mode", function()
        UIManager:quit()
        UIManager._exit_code = nil
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_pdf),
        }
        readerui:handleEvent(Event:new("SetScrollMode", true))
        readerui:handleEvent(Event:new("SetZoomMode", "page"))
        }
        readerui.rolling:onGotoPage(4)
        readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
        assert.is.same(36, readerui.rolling.current_page)
        readerui.link:onGoBackLink()
        assert.is.same(4, readerui.rolling.current_page)
    end)
            or readerui.paging.current_page == 20)
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should be able to go back after link jump in epub #nocov", function()
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_epub),
        }
        readerui.rolling:onGotoPage(5)
        readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
        assert.is.same(37, readerui.rolling.current_page)
        readerui.link:onGoBackLink()
        assert.is.same(5, readerui.rolling.current_page)
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should be able to go back after link jump in pdf page mode", function()
        UIManager:quit()
        UIManager._exit_code = nil
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_pdf),
        }
        readerui:handleEvent(Event:new("SetScrollMode", false))
        readerui:handleEvent(Event:new("SetZoomMode", "page"))
        readerui.paging:onGotoPage(1)
        readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
        UIManager:run()
        assert.is.same(22, readerui.paging.current_page)
        readerui.link:onGoBackLink()
        assert.is.same(1, readerui.paging.current_page)
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should be able to go back after link jump in pdf scroll mode", function()
        UIManager:quit()
        UIManager._exit_code = nil
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_pdf),
        }
        readerui:handleEvent(Event:new("SetScrollMode", true))
        readerui:handleEvent(Event:new("SetZoomMode", "page"))
        readerui.paging:onGotoPage(1)
        assert.is.same(1, readerui.paging.current_page)
        readerui.link:onTap(nil, {pos = {x = 228, y = 534}})
        UIManager:run()
        assert.truthy(readerui.paging.current_page == 21
            or readerui.paging.current_page == 20)
        readerui.link:onGoBackLink()
        assert.is.same(1, readerui.paging.current_page)
        readerui:closeDocument()
        readerui:onClose()
    end)

    it("should be able to go back to the same position after link jump in pdf scroll mode", function()
        UIManager:quit()
        UIManager._exit_code = nil
        local expected_page_states = {
            {
                gamma = 1,
                offset = {x = 0, y = 0},
                page = 3,
                page_area = {
                  x = 0, y = 0,
                  h = 800, w = 566,
                },
                rotation = 0,
                visible_area = {
                  x = 0, y = 694,
                  h = 106, w = 566,
                },
                zoom = 0.95032191328269044472,
           },
           {
                gamma = 1,
                offset = {x = 0, y = 0},
                page = 4,
                page_area = {
                  h = 800, w = 566,
                  x = 0, y = 0,
                },
                rotation = 0,
                visible_area = {
                  h = 686, w = 566,
                  x = 0, y = 0,
                },
                zoom = 0.95032191328269044472,
            },
        }
        -- disable footer
        G_reader_settings:saveSetting("reader_footer_mode", 0)
        require("docsettings"):open(sample_pdf):purge()
        local readerui = ReaderUI:new{
            dimen = Screen:getSize(),
            document = DocumentRegistry:openDocument(sample_pdf),
        }
        readerui:handleEvent(Event:new("SetZoomMode", "page"))
        assert.is.falsy(readerui.view.footer_visible)
        readerui.paging:onGotoPage(1)
        assert.is.same(1, readerui.paging.current_page)
        readerui.view:onSetScrollMode(true)
        assert.is.same(true, readerui.view.page_scroll)
        assert.is.same(1, readerui.paging.current_page)

        readerui.paging:onGotoViewRel(1)
        assert.is.same(2, readerui.paging.current_page)

        readerui.paging:onGotoViewRel(-1)
        assert.is.same(1, readerui.paging.current_page)

        readerui.paging:onGotoViewRel(1)
        readerui.paging:onGotoViewRel(1)
        assert.is.same(3, readerui.paging.current_page)

        readerui.paging:onGotoViewRel(-1)
        assert.is.same(2, readerui.paging.current_page)

        readerui.paging:onGotoViewRel(1)
        readerui.paging:onGotoViewRel(1)
        assert.is.same(4, readerui.paging.current_page)
        assert.are.same(expected_page_states, readerui.view.page_states)

        readerui.link:onTap(nil, {pos = {x = 164, y = 366}})
        UIManager:run()
        assert.is.same(22, readerui.paging.current_page)
        readerui.link:onGoBackLink()
        assert.is.same(3, readerui.paging.current_page)
        assert.are.same(expected_page_states, readerui.view.page_states)
        readerui:closeDocument()
        readerui:onClose()
    end)
end)

<MSG> Bump base: crengine update (#2985)

* crengine: return description and keywords metadata
  Only available for EPUB documents for now. @poire-z
* crengine: css related improvements, fix crash, better handling of gif @frankyifei
<DFF> @@ -18,7 +18,7 @@ describe("ReaderLink module", function()
         }
         readerui.rolling:onGotoPage(4)
         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
-        assert.is.same(36, readerui.rolling.current_page)
+        assert.is.same(37, readerui.rolling.current_page)
     end)
 
     it("should jump to links in pdf page mode", function()
@@ -55,7 +55,7 @@ describe("ReaderLink module", function()
         }
         readerui.rolling:onGotoPage(4)
         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
-        assert.is.same(36, readerui.rolling.current_page)
+        assert.is.same(37, readerui.rolling.current_page)
         readerui.link:onGoBackLink()
         assert.is.same(4, readerui.rolling.current_page)
     end)

{'commit': 'diff --git a/base b/base\nindex 4cecbeff..c6c1bd51 160000\n--- a/base\n+++ b/base\n@@ -1 +1 @@\n-Subproject commit 4cecbeffc5089972fb7410d952bd8035c1b6007d\n+Subproject commit c6c1bd512dfaf22bdf10c9f8a1a74665b27b78e0\ndiff --git a/spec/unit/readerlink_spec.lua b/spec/unit/readerlink_spec.lua\nindex 473014e4..b2105563 100644\n--- a/spec/unit/readerlink_spec.lua\n+++ b/spec/unit/readerlink_spec.lua\n@@ -18,7 +18,7 @@ describe("ReaderLink module", function()\n         }\n         readerui.rolling:onGotoPage(4)\n         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n-        assert.is.same(36, readerui.rolling.current_page)\n+        assert.is.same(37, readerui.rolling.current_page)\n     end)\n \n     it("should jump to links in pdf page mode", function()\n@@ -55,7 +55,7 @@ describe("ReaderLink module", function()\n         }\n         readerui.rolling:onGotoPage(4)\n         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n-        assert.is.same(36, readerui.rolling.current_page)\n+        assert.is.same(37, readerui.rolling.current_page)\n         readerui.link:onGoBackLink()\n         assert.is.same(4, readerui.rolling.current_page)\n     end)\n', 'commit_subject': 'Bump base: crengine update (#2985)', 'repo_name': 'koreader/koreader', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1498631964', 'tz_offset': '120', 'date': {'seconds': '1498631964'}}, 'commit_tree': 'f7f13f48f8efff32a24872720d2924701357566a', 'commit_message': 'Bump base: crengine update (#2985)\n\n* crengine: return description and keywords metadata\r\n  Only available for EPUB documents for now. @poire-z\r\n* crengine: css related improvements, fix crash, better handling of gif @frankyifei', 'language_name': 'Python', 'license': 'agpl-3.0', 'hunks': '@@ -18,7 +18,7 @@ describe("ReaderLink module", function()\n         }\n         readerui.rolling:onGotoPage(4)\n         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n-        assert.is.same(36, readerui.rolling.current_page)\n+        assert.is.same(37, readerui.rolling.current_page)\n     end)\n \n     it("should jump to links in pdf page mode", function()\n@@ -55,7 +55,7 @@ describe("ReaderLink module", function()\n         }\n         readerui.rolling:onGotoPage(4)\n         readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n-        assert.is.same(36, readerui.rolling.current_page)\n+        assert.is.same(37, readerui.rolling.current_page)\n         readerui.link:onGoBackLink()\n         assert.is.same(4, readerui.rolling.current_page)\n     end)\n', 'addition_count': 2, 'deletion_count': 2, 'src_file': 'a/spec/unit/readerlink_spec.lua', 'tgt_file': 'b/spec/unit/readerlink_spec.lua', 'file_extension': '.lua', 'before_file': 'describe("ReaderLink module", function()\n    local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event, Screen\n\n    setup(function()\n        require("commonrequire")\n        package.unloadAll()\n        require("document/canvascontext"):init(require("device"))\n        DocumentRegistry = require("document/documentregistry")\n        Event = require("ui/event")\n        ReaderUI = require("apps/reader/readerui")\n        UIManager = require("ui/uimanager")\n        Screen = require("device").screen\n        sample_epub = "spec/front/unit/data/leaves.epub"\n        sample_pdf = "spec/front/unit/data/paper.pdf"\n    end)\n\n    it("should jump to links in epub #nocov", function()\n        }\n        readerui.rolling:onGotoPage(4)\n        readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n        assert.is.same(36, readerui.rolling.current_page)\n    end)\n\n    it("should jump to links in pdf page mode", function()\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should jump to links in pdf page mode", function()\n        UIManager:quit()\n        UIManager._exit_code = nil\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_pdf),\n        }\n        readerui:handleEvent(Event:new("SetScrollMode", false))\n        readerui:handleEvent(Event:new("SetZoomMode", "page"))\n        readerui.paging:onGotoPage(1)\n        readerui.link:onTap(nil, {pos = {x = 363, y = 565}})\n        UIManager:run()\n        assert.is.same(22, readerui.paging.current_page)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should jump to links in pdf scroll mode", function()\n        UIManager:quit()\n        UIManager._exit_code = nil\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_pdf),\n        }\n        readerui:handleEvent(Event:new("SetScrollMode", true))\n        readerui:handleEvent(Event:new("SetZoomMode", "page"))\n        }\n        readerui.rolling:onGotoPage(4)\n        readerui.link:onTap(nil, {pos = {x = 336, y = 668}})\n        assert.is.same(36, readerui.rolling.current_page)\n        readerui.link:onGoBackLink()\n        assert.is.same(4, readerui.rolling.current_page)\n    end)\n            or readerui.paging.current_page == 20)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should be able to go back after link jump in epub #nocov", function()\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_epub),\n        }\n        readerui.rolling:onGotoPage(5)\n        readerui.link:onTap(nil, {pos = {x = 320, y = 190}})\n        assert.is.same(37, readerui.rolling.current_page)\n        readerui.link:onGoBackLink()\n        assert.is.same(5, readerui.rolling.current_page)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should be able to go back after link jump in pdf page mode", function()\n        UIManager:quit()\n        UIManager._exit_code = nil\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_pdf),\n        }\n        readerui:handleEvent(Event:new("SetScrollMode", false))\n        readerui:handleEvent(Event:new("SetZoomMode", "page"))\n        readerui.paging:onGotoPage(1)\n        readerui.link:onTap(nil, {pos = {x = 363, y = 565}})\n        UIManager:run()\n        assert.is.same(22, readerui.paging.current_page)\n        readerui.link:onGoBackLink()\n        assert.is.same(1, readerui.paging.current_page)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should be able to go back after link jump in pdf scroll mode", function()\n        UIManager:quit()\n        UIManager._exit_code = nil\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_pdf),\n        }\n        readerui:handleEvent(Event:new("SetScrollMode", true))\n        readerui:handleEvent(Event:new("SetZoomMode", "page"))\n        readerui.paging:onGotoPage(1)\n        assert.is.same(1, readerui.paging.current_page)\n        readerui.link:onTap(nil, {pos = {x = 228, y = 534}})\n        UIManager:run()\n        assert.truthy(readerui.paging.current_page == 21\n            or readerui.paging.current_page == 20)\n        readerui.link:onGoBackLink()\n        assert.is.same(1, readerui.paging.current_page)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\n\n    it("should be able to go back to the same position after link jump in pdf scroll mode", function()\n        UIManager:quit()\n        UIManager._exit_code = nil\n        local expected_page_states = {\n            {\n                gamma = 1,\n                offset = {x = 0, y = 0},\n                page = 3,\n                page_area = {\n                  x = 0, y = 0,\n                  h = 800, w = 566,\n                },\n                rotation = 0,\n                visible_area = {\n                  x = 0, y = 694,\n                  h = 106, w = 566,\n                },\n                zoom = 0.95032191328269044472,\n           },\n           {\n                gamma = 1,\n                offset = {x = 0, y = 0},\n                page = 4,\n                page_area = {\n                  h = 800, w = 566,\n                  x = 0, y = 0,\n                },\n                rotation = 0,\n                visible_area = {\n                  h = 686, w = 566,\n                  x = 0, y = 0,\n                },\n                zoom = 0.95032191328269044472,\n            },\n        }\n        -- disable footer\n        G_reader_settings:saveSetting("reader_footer_mode", 0)\n        require("docsettings"):open(sample_pdf):purge()\n        local readerui = ReaderUI:new{\n            dimen = Screen:getSize(),\n            document = DocumentRegistry:openDocument(sample_pdf),\n        }\n        readerui:handleEvent(Event:new("SetZoomMode", "page"))\n        assert.is.falsy(readerui.view.footer_visible)\n        readerui.paging:onGotoPage(1)\n        assert.is.same(1, readerui.paging.current_page)\n        readerui.view:onSetScrollMode(true)\n        assert.is.same(true, readerui.view.page_scroll)\n        assert.is.same(1, readerui.paging.current_page)\n\n        readerui.paging:onGotoViewRel(1)\n        assert.is.same(2, readerui.paging.current_page)\n\n        readerui.paging:onGotoViewRel(-1)\n        assert.is.same(1, readerui.paging.current_page)\n\n        readerui.paging:onGotoViewRel(1)\n        readerui.paging:onGotoViewRel(1)\n        assert.is.same(3, readerui.paging.current_page)\n\n        readerui.paging:onGotoViewRel(-1)\n        assert.is.same(2, readerui.paging.current_page)\n\n        readerui.paging:onGotoViewRel(1)\n        readerui.paging:onGotoViewRel(1)\n        assert.is.same(4, readerui.paging.current_page)\n        assert.are.same(expected_page_states, readerui.view.page_states)\n\n        readerui.link:onTap(nil, {pos = {x = 164, y = 366}})\n        UIManager:run()\n        assert.is.same(22, readerui.paging.current_page)\n        readerui.link:onGoBackLink()\n        assert.is.same(3, readerui.paging.current_page)\n        assert.are.same(expected_page_states, readerui.view.page_states)\n        readerui:closeDocument()\n        readerui:onClose()\n    end)\nend)\n', 'message': 'Bump base: crengine update (#2985)\n\n* crengine: return description and keywords metadata\r\n  Only available for EPUB documents for now. @poire-z\r\n* crengine: css related improvements, fix crash, better handling of gif @frankyifei', 'author_name': 'GitHub', 'lang': 'lua'}