Last Modified: 2023-06-13

Unit Test

  1. components/editor/index.lua

    local unitTestOn = true
    
  2. components/editor/tests/index.lua

    require "extlib.lunatest"
    local M = {
      run = function (props)
        print("============ lunatest =============")
        lunatest.suite("components.editor.tests.suite_controller")
        lunatest.suite("components.editor.tests.suite_selector", props)
        lunatest.run()
        print("============   end    =============")
      end
    }
    return M
    

Examples

cmponents/editor/tests/suite_controller.lua

it tests editor/controller/index.lua

module(..., package.seeall)

function suite_setup()
  controller = require "components.editor.controller.index"
  files = {}
  updatedScene = nil
end

function setup()
  book = "bookFree"
  page = "page1"
  tool = "interaction"
  layer = "butWhite"  -- Update scenes.components.layers.butWhite with the props
  class = "button"
  props = {name="helloBTN", class="button", kind="tap", actionName = "onClick", over="helloOver", btaps = 1, mask=""}
  scene = {
    name = "canvas",
    components = {
      layers = {
          {  back={
                            } },
          {  butBlue={ class={"button"}, {A={}}, {B={}}
                            } },
          {  butWhite={
                            } },
      },
      audios = {  },
      groups = {  },
      timers = {  },
      variables = {  },
      others = {  }
    },
    commands = { "blueBTN" },
    onInit = function(scene) print("onInit") end
  }
end

function teardown()
end

function test_render()
  local dst = controller:render(book, page, layer, tool, class, props)
  assert_string(dst, "fail")
  --
  local path = system.pathForFile(dst, system.TemporaryDirectory )
  local file = io.open( path, "r" )
  assert_userdata(file, "fail")
  files[#files + 1] = dst
end

cmponents/editor/tests/suite_selector.lua

automatically it loads eventOne.json in page1

 local M = {}

 local selectors
 local UI
 local bookTable
 local pageTable

 function M.init(props)
   selectors = props.selectors
   UI        = props.UI
   bookTable = props.bookTable
   pageTable = props.pageTable
 end

 function M.suite_setup()
   selectors.projectPageSelector:show()
   selectors.projectPageSelector:onClick(true)
   --
   UI.scene.app:dispatchEvent {
     name = "editor.selector.selectApp",
     UI = UI
   }
   -- appFolder = system.pathForFile("App", system.ResourceDirectory) -- default
   -- useTinyfiledialogs = false -- default
   ---
   bookTable:commandHandler({book="bookFree"}, nil,  true)
   pageTable:commandHandler({page="page1"},nil,  true)
 end

 function M.setup()
 end

 function M.teardown()
 end

 -- function M.test_component()
 --     selectors.projectPageSelector:show()
 -- end

 function M.test_action()
   selectors.componentSelector:show()
   selectors.componentSelector:onClick(true,  "actionTable")
   UI.editor.currentAction  = "eventOne"
   UI.scene.app:dispatchEvent {
     name = "editor.action.selectAction",
     UI = UI
   }
 end

 return M