local h=script.Parent.Parent.Parent.Parent local t=h.Parent local e=require(t.Dev.JestGlobals)local M=e.describe local H=e.afterEach local N=e.expect local q=e.it local n=require(t.React)local g=require(t.Dev.ReactTestingLibrary)local r=g.render local x=g.cleanup local Z=require(h.jsutils.invariant)local V=Z.InvariantError local W=(require(h.core)).ApolloClient local i=(require(script.Parent.Parent.Parent.Parent.link.core)).ApolloLink local l=require(h.react.context)local d=l.ApolloProvider local K=l.resetApolloContext local o=(require(script.Parent.Parent.Parent.Parent.cache)).InMemoryCache local O=(require(h.react.hooks)).useApolloClient M("\117\115\101\065\112\111\108\108\111\067\108\105\101\110\116 \072\111\111\107",function()H(function()x()K()end)q("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \099\108\105\101\110\116 \105\110\115\116\097\110\099\101 \102\114\111\109 \116\104\101 \099\111\110\116\101\120\116 \105\102 \097\118\097\105\108\097\098\108\101",function()local h=W.new({cache=o.new(),link=i.empty()})local function t()(N(O())).toEqual(h)return nil end r(n.createElement(d,{client=h},n.createElement(t,nil)))end)q("\115\104\111\117\108\100 \101\114\114\111\114 \105\102 \097 \099\108\105\101\110\116 \105\110\115\116\097\110\099\101 \099\097\110\'\116 \098\101 \102\111\117\110\100 \105\110 \116\104\101 \099\111\110\116\101\120\116",function()local function h()(N(function()return O()end)).toThrow(V)return nil end r(n.createElement(h,nil))end)end)return{}
--[[
 * Copyright (c) 2021 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
]]
-- ROBLOX upstream: https://github.com/apollographql/apollo-client/blob/v3.4.2/src/react/hooks/__tests__/useApolloClient.test.tsx

local srcWorkspace = script.Parent.Parent.Parent.Parent
local rootWorkspace = srcWorkspace.Parent

local JestGlobals = require(rootWorkspace.Dev.JestGlobals)
local describe = JestGlobals.describe
local afterEach = JestGlobals.afterEach
local expect = JestGlobals.expect
local it = JestGlobals.it

local React = require(rootWorkspace.React)
local testingLibrary = require(rootWorkspace.Dev.ReactTestingLibrary)
local render = testingLibrary.render
local cleanup = testingLibrary.cleanup
local invariantModule = require(srcWorkspace.jsutils.invariant)
local InvariantError = invariantModule.InvariantError

local ApolloClient = require(srcWorkspace.core).ApolloClient
local ApolloLink = require(script.Parent.Parent.Parent.Parent.link.core).ApolloLink
local contextModule = require(srcWorkspace.react.context)
local ApolloProvider = contextModule.ApolloProvider
local resetApolloContext = contextModule.resetApolloContext
local InMemoryCache = require(script.Parent.Parent.Parent.Parent.cache).InMemoryCache
local useApolloClient = require(srcWorkspace.react.hooks).useApolloClient

describe("useApolloClient Hook", function()
	afterEach(function()
		cleanup()
		resetApolloContext()
	end)

	it("should return a client instance from the context if available", function()
		local client = ApolloClient.new({ cache = InMemoryCache.new(), link = ApolloLink.empty() })
		local function App()
			expect(useApolloClient()).toEqual(client)
			return nil
		end
		render(React.createElement(ApolloProvider, { client = client }, React.createElement(App, nil)))
	end)

	it("should error if a client instance can't be found in the context", function()
		local function App()
			expect(function()
				return useApolloClient()
			end).toThrow(InvariantError)
			return nil
		end
		render(React.createElement(App, nil))
	end)
end)

return {}
