Skip to content

Commit

Permalink
Port new test to Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
vocksel committed Apr 7, 2024
1 parent d4ed2b9 commit 15688aa
Showing 1 changed file with 64 additions and 63 deletions.
127 changes: 64 additions & 63 deletions src/Explorer/filterComponentTreeNode.spec.lua
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
local flipbook = script:FindFirstAncestor("flipbook")

local JestGlobals = require(flipbook.Packages.Dev.JestGlobals)
local types = require(flipbook.Explorer.types)
local filterComponentTreeNode = require(script.Parent.filterComponentTreeNode)

return function()
local filterComponentTreeNode = require(script.Parent.filterComponentTreeNode)
local expect = JestGlobals.expect
local test = JestGlobals.test

it("should return true when the query does not match the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "other"
test("return true when the query does not match the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "other"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(true)
end)
local result = filterComponentTreeNode(target, query)
expect(result).toBe(true)
end)

it("should return false the query matches the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "tes"
test("return false the query matches the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "tes"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(false)
end)
local result = filterComponentTreeNode(target, query)
expect(result).toBe(false)
end)

it("should return true when the filter does not match any of node in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
{
children = {},
name = "folder",
icon = "folder",
},
test("return true when the filter does not match any of node in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
name = "storybook",
icon = "storybook",
}
local query = "other"
{
children = {},
name = "folder",
icon = "folder",
},
},
name = "storybook",
icon = "storybook",
}
local query = "other"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(true)
end)
local result = filterComponentTreeNode(target, query)
expect(result).toBe(true)
end)

it("should return false when a filter match at least one of nodes in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
{
children = {},
name = "folder",
icon = "folder",
},
test("return false when a filter match at least one of nodes in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
{
children = {},
name = "folder",
icon = "folder",
},
name = "storybook",
icon = "storybook",
}
local query = "tes"
},
name = "storybook",
icon = "storybook",
}
local query = "tes"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(false)
end)
end
local result = filterComponentTreeNode(target, query)
expect(result).toBe(false)
end)

0 comments on commit 15688aa

Please sign in to comment.