Skip to content

Commit

Permalink
feat(temp-language) : added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VanjaPin committed Oct 18, 2023
1 parent a6d5b36 commit 9bfc9d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/source/view/FontManager.bs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace mv
return invalid
end function

function getLanguageCode()
return m.getInstance("languageCode") ?? "en"
end function

public function getFont(name as string, size as integer) as dynamic
if name = invalid or name.trim() = ""
return invalid
Expand All @@ -49,7 +53,7 @@ namespace mv
if font = invalid
font = CreateObject("roSGNode", "Font")
if name.instr(".ttf") <> -1
language = m.getInstance("languageCode") ?? "en"
language = m.getLanguageCode()
if language = "zh"
font.uri = "tmp:" + "/fonts/" + name
else
Expand All @@ -72,4 +76,4 @@ namespace mv
end function

end class
end namespace
end namespace
19 changes: 19 additions & 0 deletions src/source/view/FontManager.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "pkg:/source/tests/ViewBaseTestSuite.spec.bs"
import "pkg:/source/view/FontManager.bs"

namespace tests
@only
@suite("FontManager tests")
class FontManagerTests extends mv.tests.BaseTestSuite

Expand Down Expand Up @@ -30,6 +31,7 @@ namespace tests
@params("HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 30)
function _(name, size)
m.expectOnce(m.manager, "getLanguageCode", [])
'/* cspell:enable *\
font = m.manager.getFont(name, size)
m.assertEqual(font.uri, "pkg:/fonts/" + name)
Expand All @@ -52,7 +54,9 @@ namespace tests
@it("caches font values")
function _()
'/* cspell:disable *\
m.expectOnce(m.manager, "getLanguageCode", [])
m.manager.getFont("HelveticaNeue.ttf", 30)
m.expectOnce(m.manager, "getLanguageCode", [])
m.manager.getFont("HelveticaNeue.ttf", 30)
m.manager.getFont("HelveticaNeue.ttf", 30)
m.manager.getFont("HelveticaNeue.ttf", 30)
Expand All @@ -72,5 +76,20 @@ namespace tests
m.assertSubType(m.manager.getFont("HelveticaNeue.ttf", 40), "Font")
'/* cspell:enable *\
end function

@it("return tmp language path on zh language code")
@params("HelveticaNeue.ttf", 20)
@params("HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 50)
@params("HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 30)
function _(name, size)
m.expectOnce(m.manager, "getLanguageCode", [], "zh")
'/* cspell:enable *\
font = m.manager.getFont(name, size)
m.assertEqual(font.uri, "tmp:/fonts/" + name)
m.assertEqual(font.size, size)
m.assertSubType(font, "Font")
end function
end class
end namespace

0 comments on commit 9bfc9d1

Please sign in to comment.