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=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\046\110\101\119\046\108\117\097\117")local B b("\082\101\097\099\116\070\105\098\101\114\083\117\115\112\101\110\115\101\067\111\110\116\101\120\116",function()k(function()F.resetModules()B=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\083\117\115\112\101\110\115\101\067\111\110\116\101\120\116\046\110\101\119\046\108\117\097\117")end)b("\115\117\115\112\101\110\115\101 \099\111\110\116\101\120\116 \115\116\097\099\107",function()local d local F local b k(function()d=8 F=M.createFiberFromText("",0,0)b=B.suspenseStackCursor end)a("\112\117\115\104\101\115 \116\104\101 \099\111\110\116\101\120\116 \097\110\100 \097\115\115\105\103\110\115 \116\104\101 \118\097\108\117\101 \116\111 \116\104\101 \099\117\114\115\111\114",function()B.pushSuspenseContext(F,d);(i(b)).toEqual({current=d})end)a("\112\117\115\104\101\115 \097\110\100 \112\111\112\115 \097\110\100 \115\101\116\115 \116\104\101 \099\117\114\115\111\114 \116\111 \105\116\115 \105\110\105\116\105\097\108 \118\097\108\117\101",function()local k=b.current B.pushSuspenseContext(F,d)B.popSuspenseContext(F);(i(b)).toEqual({current=k})end)end)b("\104\097\115\083\117\115\112\101\110\115\101\067\111\110\116\101\120\116",function()a("\105\115 \116\114\117\101 \102\111\114 \112\097\114\101\110\116 \099\111\110\116\101\120\116 \097\110\100 \105\116\115 \115\117\098\116\114\101\101 \099\111\110\116\101\120\116",function()local d=8 local F=B.addSubtreeSuspenseContext(10000,d);(i(B.hasSuspenseContext(F,d))).toBe(true)end)a("\105\115 \102\097\108\115\101 \102\111\114 \116\119\111 \100\105\102\102\101\114\101\110\116 \099\111\110\116\101\120\116",function()(i(B.hasSuspenseContext(8,16))).toBe(false)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 ReactFiber = require("../ReactFiber.new.luau")

local ReactFiberSuspenseContext

describe("ReactFiberSuspenseContext", function()
	beforeEach(function()
		jest.resetModules()
		ReactFiberSuspenseContext = require("../ReactFiberSuspenseContext.new.luau")
	end)

	describe("suspense context stack", function()
		local someContext
		local fiber
		local suspenseStackCursor

		beforeEach(function()
			someContext = 0b1000
			fiber = ReactFiber.createFiberFromText("", 0, 0)
			suspenseStackCursor = ReactFiberSuspenseContext.suspenseStackCursor
		end)

		it("pushes the context and assigns the value to the cursor", function()
			ReactFiberSuspenseContext.pushSuspenseContext(fiber, someContext)
			jestExpect(suspenseStackCursor).toEqual({ current = someContext })
		end)

		it("pushes and pops and sets the cursor to its initial value", function()
			local initialValue = suspenseStackCursor.current

			ReactFiberSuspenseContext.pushSuspenseContext(fiber, someContext)
			ReactFiberSuspenseContext.popSuspenseContext(fiber)
			jestExpect(suspenseStackCursor).toEqual({ current = initialValue })
		end)
	end)

	describe("hasSuspenseContext", function()
		it("is true for parent context and its subtree context", function()
			local subtree = 0b1000
			local parent =
				ReactFiberSuspenseContext.addSubtreeSuspenseContext(10000, subtree)

			jestExpect(ReactFiberSuspenseContext.hasSuspenseContext(parent, subtree)).toBe(
				true
			)
		end)

		it("is false for two different context", function()
			jestExpect(ReactFiberSuspenseContext.hasSuspenseContext(0b1000, 0b10000)).toBe(
				false
			)
		end)
	end)
end)
