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.describe local b=d.beforeEach local a=d.it k("\082\101\097\099\116\070\105\098\101\114\072\111\115\116\067\111\110\116\101\120\116",function()local d local k local M b(function()F.resetModules()M=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116")d=require("\046\046")k=require("\046\046\047\082\101\097\099\116\082\111\111\116\084\097\103\115")end)a("\119\111\114\107\115 \119\105\116\104 \110\105\108 \104\111\115\116 \099\111\110\116\101\120\116",function()local F=0 local b=d({prepareForCommit=function()return nil end,resetAfterCommit=function() end;getRootHostContext=function()return nil end,getChildHostContext=function()return nil end,shouldSetTextContent=function()return false end,createInstance=function()F+=1 end;finalizeInitialChildren=function()return nil end,appendInitialChild=function()return nil end;now=function()return 0 end,appendChildToContainer=function()return nil end;clearContainer=function() end,supportsMutation=true})local a=b.createContainer(nil,k,false,nil)b.updateContainer(M.createElement("\097",nil,M.createElement("\098")),a,nil,nil);(i(F)).toBe(2)end)a("\115\104\111\117\108\100 \115\101\110\100 \116\104\101 \099\111\110\116\101\120\116 \116\111 \112\114\101\112\097\114\101\070\111\114\067\111\109\109\105\116 \097\110\100 \114\101\115\101\116\065\102\116\101\114\067\111\109\109\105\116",function()local F={}local b=d({prepareForCommit=function(d)(i(d)).toBe(F)return nil end;resetAfterCommit=function(d)(i(d)).toBe(F)end,getRootHostContext=function()return nil end;getChildHostContext=function()return nil end;shouldSetTextContent=function()return false end,createInstance=function()return nil end,finalizeInitialChildren=function()return nil end;appendInitialChild=function()return nil end,now=function()return 0 end;appendChildToContainer=function()return nil end,clearContainer=function() end;supportsMutation=true})local a=b.createContainer(F,k,false,nil)b.updateContainer(M.createElement("\097",nil,M.createElement("\098")),a,nil,nil)end)end)
-- ROBLOX upstream: https://github.com/facebook/react/blob/ea2af878cc3fb139b0e08cf9bc4b2f4178429d69/packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js
--[[*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @emails react-core
 * @jest-environment node
 ]]

local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local jest = JestGlobals.jest
local describe = JestGlobals.describe
local beforeEach = JestGlobals.beforeEach
local it = JestGlobals.it

describe("ReactFiberHostContext", function()
	local ReactFiberReconciler
	local ConcurrentRoot
	local React

	beforeEach(function()
		jest.resetModules()
		React = require("@pkg/@jsdotlua/react")
		ReactFiberReconciler = require("..")
		ConcurrentRoot = require("../ReactRootTags")
	end)

	it("works with nil host context", function()
		local creates = 0
		local Renderer = ReactFiberReconciler({
			prepareForCommit = function()
				return nil
			end,
			resetAfterCommit = function() end,
			getRootHostContext = function()
				return nil
			end,
			getChildHostContext = function()
				return nil
			end,
			shouldSetTextContent = function()
				return false
			end,
			createInstance = function()
				creates += 1
			end,
			finalizeInitialChildren = function()
				return nil
			end,
			appendInitialChild = function()
				return nil
			end,
			now = function()
				return 0
			end,
			appendChildToContainer = function()
				return nil
			end,
			clearContainer = function() end,
			supportsMutation = true,
		})

		local container = Renderer.createContainer(
			--[[ root: ]]
			nil,
			ConcurrentRoot,
			false,
			nil
		)
		Renderer.updateContainer(
			React.createElement("a", nil, React.createElement("b")),
			container,
			--[[ parentComponent: ]]
			nil,
			--[[ callback: ]]
			nil
		)

		jestExpect(creates).toBe(2)
	end)

	it("should send the context to prepareForCommit and resetAfterCommit", function()
		local rootContext = {}
		local Renderer = ReactFiberReconciler({
			prepareForCommit = function(hostContext)
				jestExpect(hostContext).toBe(rootContext)
				return nil
			end,
			resetAfterCommit = function(hostContext)
				jestExpect(hostContext).toBe(rootContext)
			end,
			getRootHostContext = function()
				return nil
			end,
			getChildHostContext = function()
				return nil
			end,
			shouldSetTextContent = function()
				return false
			end,
			createInstance = function()
				return nil
			end,
			finalizeInitialChildren = function()
				return nil
			end,
			appendInitialChild = function()
				return nil
			end,
			now = function()
				return 0
			end,
			appendChildToContainer = function()
				return nil
			end,
			clearContainer = function() end,
			supportsMutation = true,
		})

		local container =
			Renderer.createContainer(rootContext, ConcurrentRoot, false, nil)
		Renderer.updateContainer(
			React.createElement("a", nil, React.createElement("b")),
			container,
			--[[ parentComponent= ]]
			nil,
			--[[ callback= ]]
			nil
		)
	end)
end)
