local B local L local a local e local z=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 A=z.expect local W=z.describe local S=z.jest local I=z.beforeEach local M=z.afterEach local O=z.it local n=z.xit W("\082\101\097\099\116\068\101\112\114\101\099\097\116\105\111\110\087\097\114\110\105\110\103\115",function()I(function()S.resetModules()B=require("\046\046")L=(require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\104\097\114\101\100")).ReactFeatureFlags a=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116-\110\111\111\112-\114\101\110\100\101\114\101\114")e=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\099\104\101\100\117\108\101\114")L.warnAboutDefaultPropsOnFunctionComponents=true L.warnAboutStringRefs=true end)M(function()L.warnAboutDefaultPropsOnFunctionComponents=false L.warnAboutStringRefs=false end)n("\115\104\111\117\108\100 \119\097\114\110 \119\104\101\110 \103\105\118\101\110 \100\101\102\097\117\108\116\080\114\111\112\115",function()local function L(B)return nil end a.render(B.createElement(L));(A(function()return(A(e)).toFlushWithoutYielding()end)).toErrorDev("\087\097\114\110\105\110\103\058 \070\117\110\099\116\105\111\110\097\108\067\111\109\112\111\110\101\110\116\058 \083\117\112\112\111\114\116 \102\111\114 \100\101\102\097\117\108\116\080\114\111\112\115 \119\105\108\108 \098\101 \114\101\109\111\118\101\100 \102\114\111\109 \102\117\110\099\116\105\111\110 \099\111\109\112\111\110\101\110\116\115 \105\110 \097 \102\117\116\117\114\101 \109\097\106\111\114 \114\101\108\101\097\115\101\046 \085\115\101 \074\097\118\097\083\099\114\105\112\116 \100\101\102\097\117\108\116 \112\097\114\097\109\101\116\101\114\115 \105\110\115\116\101\097\100\046")end)O("\115\104\111\117\108\100 \119\097\114\110 \119\104\101\110 \103\105\118\101\110 \115\116\114\105\110\103 \114\101\102\115",function()local L=B.Component:extend("\082\101\102\067\111\109\112\111\110\101\110\116")function L.render(B)return nil end local z=B.Component:extend("\067\111\109\112\111\110\101\110\116")function z.render(a)return B.createElement(L,{ref="\114\101\102\067\111\109\112\111\110\101\110\116"})end a.render(B.createElement(z))local W=_G.__DEV__ and"\067\111\109\112\111\110\101\110\116"or"\060\101\110\097\098\108\101 \095\095\068\069\086\095\095 \109\111\100\101 \102\111\114 \099\111\109\112\111\110\101\110\116 \110\097\109\101\115\062";(A(function()return(A(e)).toFlushWithoutYielding()end)).toThrow("\067\111\109\112\111\110\101\110\116 \""..(W.."\" \099\111\110\116\097\105\110\115 \116\104\101 \115\116\114\105\110\103 \114\101\102 \"\114\101\102\067\111\109\112\111\110\101\110\116\"\046 \083\117\112\112\111\114\116 \102\111\114 \115\116\114\105\110\103 \114\101\102\115 \104\097\115 \098\101\101\110 \114\101\109\111\118\101\100\046 \087\101 \114\101\099\111\109\109\101\110\100 \117\115\105\110\103 \117\115\101\082\101\102\040\041 \111\114 \099\114\101\097\116\101\082\101\102\040\041 \105\110\115\116\101\097\100\046 \076\101\097\114\110 \109\111\114\101 \097\098\111\117\116 \117\115\105\110\103 \114\101\102\115 \115\097\102\101\108\121 \104\101\114\101\058 \104\116\116\112\115\058\047\047\114\101\097\099\116\106\115\046\111\114\103\047\108\105\110\107\047\115\116\114\105\099\116-\109\111\100\101-\115\116\114\105\110\103-\114\101\102"))end)n("\115\104\111\117\108\100 \110\111\116 \119\097\114\110 \119\104\101\110 \111\119\110\101\114 \097\110\100 \115\101\108\102 \097\114\101 \116\104\101 \115\097\109\101 \102\111\114 \115\116\114\105\110\103 \114\101\102\115",function()L.warnAboutStringRefs=false local z=B.Component:extend("\082\101\102\067\111\109\112\111\110\101\110\116")function z.render(B)return nil end local W=B.Component:extend("")function W.render(L)return B.createElement(z,{ref="\114\101\102\067\111\109\112\111\110\101\110\116",__self=L})end a.renderLegacySyncRoot(B.createElement(W));(A(e)).toFlushWithoutYielding()end)O("\115\104\111\117\108\100 \119\097\114\110 \119\104\101\110 \111\119\110\101\114 \097\110\100 \115\101\108\102 \097\114\101 \100\105\102\102\101\114\101\110\116 \102\111\114 \115\116\114\105\110\103 \114\101\102\115",function()local L=B.Component:extend("\082\101\102\067\111\109\112\111\110\101\110\116")function L.render(B)return nil end local z=B.Component:extend("\067\111\109\112\111\110\101\110\116")function z.render(a)return B.createElement(L,{ref="\114\101\102\067\111\109\112\111\110\101\110\116";__self={}})end a.render(B.createElement(z))local W=_G.__DEV__ and"\067\111\109\112\111\110\101\110\116"or"\060\101\110\097\098\108\101 \095\095\068\069\086\095\095 \109\111\100\101 \102\111\114 \099\111\109\112\111\110\101\110\116 \110\097\109\101\115\062";(A(function()return(A(e)).toFlushWithoutYielding()end)).toThrow("\067\111\109\112\111\110\101\110\116 \""..(W.."\" \099\111\110\116\097\105\110\115 \116\104\101 \115\116\114\105\110\103 \114\101\102 \"\114\101\102\067\111\109\112\111\110\101\110\116\"\046 \083\117\112\112\111\114\116 \102\111\114 \115\116\114\105\110\103 \114\101\102\115 \104\097\115 \098\101\101\110 \114\101\109\111\118\101\100\046 \087\101 \114\101\099\111\109\109\101\110\100 \117\115\105\110\103 \117\115\101\082\101\102\040\041 \111\114 \099\114\101\097\116\101\082\101\102\040\041 \105\110\115\116\101\097\100\046 \076\101\097\114\110 \109\111\114\101 \097\098\111\117\116 \117\115\105\110\103 \114\101\102\115 \115\097\102\101\108\121 \104\101\114\101\058 \104\116\116\112\115\058\047\047\114\101\097\099\116\106\115\046\111\114\103\047\108\105\110\107\047\115\116\114\105\099\116-\109\111\100\101-\115\116\114\105\110\103-\114\101\102"))end)end)
-- ROBLOX upstream: https://github.com/facebook/react/blob/v17.0.1/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js
local React
local ReactFeatureFlags
local ReactNoop
local Scheduler
-- local JSXDEVRuntime
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local describe = JestGlobals.describe
local jest = JestGlobals.jest
local beforeEach = JestGlobals.beforeEach
local afterEach = JestGlobals.afterEach
local it = JestGlobals.it
local xit = JestGlobals.xit

describe("ReactDeprecationWarnings", function()
	beforeEach(function()
		jest.resetModules()
		React = require("..")
		ReactFeatureFlags = require("@pkg/@jsdotlua/shared").ReactFeatureFlags
		ReactNoop = require("@pkg/@jsdotlua/react-noop-renderer")
		Scheduler = require("@pkg/@jsdotlua/scheduler")
		-- if Boolean.toJSBoolean(__DEV__) then
		-- 	JSXDEVRuntime = require("react/jsx-dev-runtime")
		-- end
		ReactFeatureFlags.warnAboutDefaultPropsOnFunctionComponents = true
		ReactFeatureFlags.warnAboutStringRefs = true
	end)
	afterEach(function()
		ReactFeatureFlags.warnAboutDefaultPropsOnFunctionComponents = false
		ReactFeatureFlags.warnAboutStringRefs = false
	end)

	-- ROBLOX deviation: we already don't support defaultProps on function components
	xit("should warn when given defaultProps", function()
		local function FunctionalComponent(_props)
			return nil
		end
		-- FunctionalComponent.defaultProps = { testProp = true }
		ReactNoop.render(React.createElement(FunctionalComponent))
		jestExpect(function()
			return jestExpect(Scheduler).toFlushWithoutYielding()
		end).toErrorDev(
			"Warning: FunctionalComponent: Support for defaultProps "
				.. "will be removed from function components in a future major "
				.. "release. Use JavaScript default parameters instead."
		)
	end)
	it("should warn when given string refs", function()
		local RefComponent = React.Component:extend("RefComponent")
		function RefComponent:render()
			return nil
		end
		local Component = React.Component:extend("Component")
		function Component:render()
			return React.createElement(RefComponent, { ref = "refComponent" })
		end
		ReactNoop.render(React.createElement(Component))
		local expectedName = _G.__DEV__ and "Component"
			or "<enable __DEV__ mode for component names>"
		-- ROBLOX Test Noise: jest setup config makes this hide error
		-- boundary warnings in upstream (scripts/jest/setupTests.js:72)
		-- ROBLOX deviation: we removed string ref support ahead of upstream schedule
		jestExpect(function()
			return jestExpect(Scheduler).toFlushWithoutYielding()
		end).toThrow(
			'Component "'
				.. expectedName
				.. '" contains the string ref "refComponent". '
				.. "Support for string refs has been removed. "
				.. "We recommend using useRef() or createRef() instead. "
				.. "Learn more about using refs safely here: "
				.. "https://reactjs.org/link/strict-mode-string-ref"
			-- ROBLOX deviation: since we throw instead of warn, no stack trace in the message
			-- .. "\n    in Component (at **)"
		)
	end)
	-- ROBLOX deviation: we don't allow string refs under any circumstances
	xit("should not warn when owner and self are the same for string refs", function()
		ReactFeatureFlags.warnAboutStringRefs = false
		local RefComponent = React.Component:extend("RefComponent")
		function RefComponent:render()
			return nil
		end
		local Component = React.Component:extend("")
		function Component:render()
			return React.createElement(
				RefComponent,
				{ ref = "refComponent", __self = self }
			)
		end
		ReactNoop.renderLegacySyncRoot(React.createElement(Component))
		jestExpect(Scheduler).toFlushWithoutYielding()
	end)
	it("should warn when owner and self are different for string refs", function()
		local RefComponent = React.Component:extend("RefComponent")
		function RefComponent:render()
			return nil
		end
		local Component = React.Component:extend("Component")
		function Component:render()
			return React.createElement(
				RefComponent,
				{ ref = "refComponent", __self = {} }
			)
		end
		ReactNoop.render(React.createElement(Component))

		-- ROBLOX deviation: we removed string ref support ahead of upstream schedule
		local expectedName = _G.__DEV__ and "Component"
			or "<enable __DEV__ mode for component names>"
		-- ROBLOX Test Noise: jest setup config makes this hide error
		-- boundary warnings in upstream (scripts/jest/setupTests.js:72)
		jestExpect(function()
			return jestExpect(Scheduler).toFlushWithoutYielding()
		end).toThrow(
			'Component "'
				.. expectedName
				.. '" contains the string ref "refComponent". '
				.. "Support for string refs has been removed. "
				.. "We recommend using useRef() or createRef() instead. "
				.. "Learn more about using refs safely here: "
				.. "https://reactjs.org/link/strict-mode-string-ref"
		)
	end)

	-- ROBLOX TODO: figure out how to do this without JSX internals
	-- if _G.__DEV__ then
	-- 	xit("should warn when owner and self are different for string refs", function()
	-- 		local RefComponent = React.Component:extend("")
	-- 		RefComponent.__index = RefComponent
	-- 		function RefComponent:render()
	-- 			return nil
	-- 		end
	-- 		local Component = React.Component:extend("")
	-- 		Component.__index = Component
	-- 		function Component:render()
	-- 			-- return JSXDEVRuntime:jsxDEV(
	-- 			-- 	RefComponent,
	-- 			-- 	{ ref = "refComponent" },
	-- 			-- 	nil,
	-- 			-- 	false,
	-- 			-- 	{},
	-- 			-- 	{}
	-- 			-- )
	-- 		end
	-- 		ReactNoop.render(React.createElement(Component))
	-- 		jestExpect(function()
	-- 			return jestExpect(Scheduler).toFlushWithoutYielding()
	-- 		end).toErrorDev(
	-- 			'Warning: Component "Component" contains the string ref "refComponent". '
	-- 				.. "Support for string refs will be removed in a future major release. "
	-- 				.. "This case cannot be automatically converted to an arrow function. "
	-- 				.. "We ask you to manually fix this case by using useRef() or createRef() instead. "
	-- 				.. "Learn more about using refs safely here: "
	-- 				.. "https://reactjs.org/link/strict-mode-string-ref"
	-- 		)
	-- 	end)
	-- end
end)
