local d=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local i=d.expect local F=d.jest local k=d.beforeEach local b=d.describe local a=d.it local M b("\082\101\097\099\116\070\105\098\101\114\083\117\115\112\101\110\115\101\067\111\109\112\111\110\101\110\116",function()k(function()F.resetModules()M=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\083\117\115\112\101\110\115\101\067\111\109\112\111\110\101\110\116\046\110\101\119\046\108\117\097\117")end)b("\115\104\111\117\108\100\067\097\112\116\117\114\101\083\117\115\112\101\110\115\101",function()local d local F k(function()d=M.shouldCaptureSuspense F={memoizedState=nil,memoizedProps={}}end)local function B(k,b)if b==nil then B(k,true)B(k,false)else local M=string.format("\105\115 \037\115 \105\102 \105\116 \037\115 \105\110\118\105\115\105\098\108\101 \112\097\114\101\110\116",tostring(k),b and"\100\111\101\115 \110\111\116 \104\097\118\101"or"\104\097\115")a(M,function()(i(d(F,b))).toBe(k)end)end end b("\119\105\116\104 \097 \109\101\109\111\105\122\101\100\083\116\097\116\101",function()k(function()F.memoizedState={dehydrated=nil}end)b("\109\101\109\111\105\122\101\100\083\116\097\116\101\046\100\101\104\121\100\114\097\116\101\100 \105\115 \110\111\116 \110\117\108\108",function()k(function()F.memoizedState.dehydrated={}end)B(true)end)b("\109\101\109\111\105\122\101\100\083\116\097\116\101\046\100\101\104\121\100\114\097\116\101\100 \105\115 \110\117\108\108",function()B(false)end)end)b("\119\105\116\104 \110\111 \109\101\109\111\105\122\101\100\083\116\097\116\101",function()b("\119\105\116\104\111\117\116 \102\097\108\108\098\097\099\107 \112\114\111\112",function()B(false)end)b("\119\105\116\104 \102\097\108\108\098\097\099\107 \112\114\111\112",function()k(function()F.memoizedProps.fallback={}end)b("\119\105\116\104\111\117\116 \102\108\097\103 \117\110\115\116\097\098\108\101\095\097\118\111\105\100\084\104\105\115\070\097\108\108\098\097\099\107",function()B(true)end)b("\119\105\116\104 \102\108\097\103 \117\110\115\116\097\098\108\101\095\097\118\111\105\100\084\104\105\115\070\097\108\108\098\097\099\107",function()k(function()F.memoizedProps.unstable_avoidThisFallback=true end)B(false,true)B(true,false)end)end)end)end)end)
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local jest = JestGlobals.jest
local beforeEach = JestGlobals.beforeEach
local describe = JestGlobals.describe
local it = JestGlobals.it

local ReactFiberSuspenseComponent

describe("ReactFiberSuspenseComponent", function()
	beforeEach(function()
		jest.resetModules()

		ReactFiberSuspenseComponent = require("../ReactFiberSuspenseComponent.new.luau")
	end)

	describe("shouldCaptureSuspense", function()
		local shouldCaptureSuspense
		local fiber

		beforeEach(function()
			shouldCaptureSuspense = ReactFiberSuspenseComponent.shouldCaptureSuspense
			fiber = {
				memoizedState = nil,
				memoizedProps = {},
			}
		end)

		local function generateTest(expected, hasInvisibleParent)
			if hasInvisibleParent == nil then
				generateTest(expected, true)
				generateTest(expected, false)
			else
				local testName = string.format(
					"is %s if it %s invisible parent",
					tostring(expected),
					hasInvisibleParent and "does not have" or "has"
				)
				it(testName, function()
					jestExpect(shouldCaptureSuspense(fiber, hasInvisibleParent)).toBe(
						expected
					)
				end)
			end
		end

		describe("with a memoizedState", function()
			beforeEach(function()
				fiber.memoizedState = { dehydrated = nil }
			end)
			describe("memoizedState.dehydrated is not null", function()
				beforeEach(function()
					fiber.memoizedState.dehydrated = {}
				end)
				generateTest(true)
			end)

			describe("memoizedState.dehydrated is null", function()
				generateTest(false)
			end)
		end)

		describe("with no memoizedState", function()
			describe("without fallback prop", function()
				generateTest(false)
			end)

			describe("with fallback prop", function()
				beforeEach(function()
					fiber.memoizedProps.fallback = {}
				end)

				describe("without flag unstable_avoidThisFallback", function()
					generateTest(true)
				end)

				describe("with flag unstable_avoidThisFallback", function()
					beforeEach(function()
						fiber.memoizedProps.unstable_avoidThisFallback = true
					end)
					generateTest(false, true)
					generateTest(true, false)
				end)
			end)
		end)
	end)
end)
