local H=script.Parent.Parent.Parent local T=require(H.JestGlobals)local R=T.expect local a=T.test local U=T.jest local h=require(H.React)local t=require(script.Parent.Parent)local G=t.render local n=t.fireEvent local F=t.screen a("\114\101\110\100\101\114 \099\097\108\108\115 \117\115\101\069\102\102\101\099\116 \105\109\109\101\100\105\097\116\101\108\121",function()local H=U.fn()local function T()h.useEffect(H)return nil end G(h.createElement(T,nil));(R(H)).toHaveBeenCalledTimes(1)end)a("\102\105\110\100\066\121\084\101\115\116\073\100 \114\101\116\117\114\110\115 \116\104\101 \101\108\101\109\101\110\116",function()local H=h.createRef()G(h.createElement("\070\114\097\109\101",{ref=H;[h.Tag]="\100\097\116\097-\116\101\115\116\105\100\061\102\111\111"}));(R((F.findByTestId("\102\111\111")):expect())).toBe(H.current)end)a("\102\105\114\101\069\118\101\110\116 \116\114\105\103\103\101\114\115 \117\115\101\069\102\102\101\099\116 \099\097\108\108\115",function()local H=U.fn()local function T()h.useEffect(H)local T,R=h.useState(0)return h.createElement("\084\101\120\116\066\117\116\116\111\110",{Size=UDim2.new(0,100,0,100),[h.Event.Activated]=function()return R(T+1)end;Text=T})end local a=((G(h.createElement(T,nil))).container:GetChildren())[1]task.wait()H:mockClear()n.click(a);(R(a)).toHaveTextContent("\049");(R(H)).toHaveBeenCalledTimes(1)end)return{}
-- ROBLOX upstream: https://github.com/testing-library/react-testing-library/blob/v12.1.5/src/__tests__/act.js
local Packages = script.Parent.Parent.Parent

local JestGlobals = require(Packages.JestGlobals)
local expect = JestGlobals.expect
local test = JestGlobals.test
local jest = JestGlobals.jest

local React = require(Packages.React)
local ParentModule = require(script.Parent.Parent)
local render = ParentModule.render
local fireEvent = ParentModule.fireEvent
local screen = ParentModule.screen

test("render calls useEffect immediately", function()
	local effectCb = jest.fn()
	local function MyUselessComponent()
		React.useEffect(effectCb)
		return nil
	end
	render(React.createElement(MyUselessComponent, nil))
	expect(effectCb).toHaveBeenCalledTimes(1)
end)

test("findByTestId returns the element", function()
	local ref = React.createRef()
	render(React.createElement("Frame", { ref = ref, [React.Tag] = "data-testid=foo" }))
	expect(screen.findByTestId("foo"):expect()).toBe(ref.current)
end)

test("fireEvent triggers useEffect calls", function()
	local effectCb = jest.fn()
	local function Counter()
		React.useEffect(effectCb)
		local count, setCount = React.useState(0)
		return React.createElement("TextButton", {
			Size = UDim2.new(0, 100, 0, 100),
			[React.Event.Activated] = function()
				return setCount(count + 1)
			end,
			Text = count,
		})
	end
	local buttonNode = render(React.createElement(Counter, nil)).container:GetChildren()[1]
	task.wait()
	effectCb:mockClear()
	fireEvent.click(buttonNode)
	expect(buttonNode).toHaveTextContent("1")
	expect(effectCb).toHaveBeenCalledTimes(1)
end)

-- ROBLOX deviation START: hydrate is not supported
-- it("calls to hydrate will run useEffects", function()
-- 	local effectCb = jest.fn()
-- 	local function MyUselessComponent()
-- 		React.useEffect(effectCb)
-- 		return nil
-- 	end
-- 	render(React.createElement(MyUselessComponent, nil), { hydrate = true })
-- 	expect(effectCb).toHaveBeenCalledTimes(1)
-- end)
-- ROBLOX deviation END
return {}
