This commit is contained in:
lx
2026-07-06 14:01:11 -04:00
commit c4f97d729d
16468 changed files with 935321 additions and 0 deletions
@@ -0,0 +1,33 @@
--[[
Mocks our analytics interface so we can make sure certain thunks
trigger analytics calls without actually calling the real ones.
This mock service has some ad hoc mechanisms to introspect into it,
but we should create an actual spy pattern to use with it in the future
]]
local MockAnalytics = {}
function MockAnalytics.new()
local service = {
reportRobuxUpsellStarted_callCount = 0,
signalPurchaseSuccess_callCount = 0,
}
setmetatable(service, {
__tostring = function()
return "Service(MockAnalytics)"
end,
})
function service.reportRobuxUpsellStarted()
service.reportRobuxUpsellStarted_callCount = service.reportRobuxUpsellStarted_callCount + 1
end
function service.signalPurchaseSuccess(id, infoType, salePrice, result)
service.signalPurchaseSuccess_callCount = service.signalPurchaseSuccess_callCount + 1
end
return service
end
return MockAnalytics
@@ -0,0 +1,29 @@
--[[
Mocks some external settings so we can test the purchase prompt's
behavior under various external circumstances.
]]
local MockExternalSettings = {}
function MockExternalSettings.new(isStudio, isTenFoot, restrictSales, disablePurchases)
local service = {}
function service.isStudio()
return isStudio
end
function service.getFlagRestrictSales2()
return restrictSales
end
function service.getFlagOrder66()
return disablePurchases
end
function service.isTenFootInterface()
return isTenFoot
end
return service
end
return MockExternalSettings
@@ -0,0 +1,91 @@
--[[
Mock network implementation that returns values in the expected
formats, or returns promise rejections if specified
]]
local Promise = require(script.Parent.Parent.Promise)
local function getProductInfo(id, infoType)
return Promise.resolve({
AssetId = 1,
AssetTypeId = 2,
ContentRatingTypeId = 0,
Creator = {
CreatorType = "Group",
CreatorTargetId = 1,
Name = "ROBLOX",
Id = 1,
},
Description = "This item isn't real!",
IconImageAssetId = 1,
IsForSale = true,
IsLimited = false,
IsLimitedUnique = false,
IsNew = false,
IsPublicDomain = false,
MinimumMembershipLevel = 0,
Name = "Test Item",
PriceInRobux = 100,
ProductId = 1,
})
end
local function getPlayerOwns(player, id, infoType)
return Promise.resolve(false)
end
local function performPurchase(infoType, productId, expectedPrice, requestId)
return Promise.resolve({
success = true,
receipt = "fake-receipt-hash",
})
end
local function loadAssetForEquip(assetId)
return Promise.resolve(Instance.new("Tool"))
end
local function getAccountInfo()
return Promise.resolve({
RobuxBalance = 2147483647,
MembershipType = 0,
})
end
local function networkFailure(id, infoType)
return Promise.reject("Failed to access network service")
end
local MockNetwork = {}
MockNetwork.__index = MockNetwork
function MockNetwork.new(shouldFail)
local mockNetworkService
if shouldFail then
mockNetworkService = {
getProductInfo = networkFailure,
getPlayerOwns = networkFailure,
performPurchase = networkFailure,
loadAssetForEquip = networkFailure,
getAccountInfo = networkFailure,
}
else
mockNetworkService = {
getProductInfo = getProductInfo,
getPlayerOwns = getPlayerOwns,
performPurchase = performPurchase,
loadAssetForEquip = loadAssetForEquip,
getAccountInfo = getAccountInfo,
}
end
setmetatable(mockNetworkService, {
__tostring = function()
return "MockService(Network)"
end
})
return mockNetworkService
end
return MockNetwork
@@ -0,0 +1,38 @@
--[[
Mocks calls to certain platform-specific functions so that we can
ensure they're being called properly by our thunks.
This mock service has some ad hoc mechanisms to introspect into it,
but we should create an actual spy pattern to use with it in the future
]]
local MockPlatformInterface = {}
function MockPlatformInterface.new()
local service = {
startRobuxUpsellWeb_callCount = 0,
startBuildersClubUpsellWeb_callCount = 0,
promptNativePurchase_callCount = 0,
}
setmetatable(service, {
__tostring = function()
return "Service(MockPlatformInterface)"
end,
})
function service.startRobuxUpsellWeb()
service.startRobuxUpsellWeb_callCount = service.startRobuxUpsellWeb_callCount + 1
end
function service.startBuildersClubUpsellWeb()
service.startBuildersClubUpsellWeb_callCount = service.startBuildersClubUpsellWeb_callCount + 1
end
function service.promptNativePurchase(player, mobileProductId)
service.promptNativePurchase_callCount = service.promptNativePurchase_callCount + 1
end
return service
end
return MockPlatformInterface
@@ -0,0 +1,55 @@
--[[
Component that wraps its provided children with a store provider,
a LayoutValues object, and a ScreenGui. Convenient for testing!
]]
local CorePackages = game:GetService("CorePackages")
local LocalizationService = game:GetService("LocalizationService")
local Roact = require(CorePackages.Roact)
local Rodux = require(CorePackages.Rodux)
local RoactRodux = require(CorePackages.RoactRodux)
local LayoutValues = require(script.Parent.Parent.Services.LayoutValues)
local LayoutValuesProvider = require(script.Parent.Parent.Components.Connection.LayoutValuesProvider)
local LocalizationContextProvider = require(script.Parent.Parent.Components.Connection.LocalizationContextProvider)
local getLocalizationContext = require(script.Parent.Parent.Localization.getLocalizationContext)
local Reducer = require(script.Parent.Parent.Reducers.Reducer)
local UnitTestContainer = Roact.Component:extend("UnitTestContainer")
function UnitTestContainer:init()
self.layoutValues = LayoutValues.generate(false)
self.store = self.props.overrideStore or Rodux.Store.new(Reducer, {})
local locale = self.props.overrideLocale or LocalizationService.RobloxLocaleId
self.localizationContext = getLocalizationContext(locale)
end
function UnitTestContainer:render()
assert(#self.props[Roact.Children] > 0,
"UnitTestContainer: no children provided, nothing will be tested")
return Roact.createElement(RoactRodux.StoreProvider, {
store = self.store,
}, {
PurchasePrompt = Roact.createElement(LocalizationContextProvider, {
localizationContext = self.localizationContext,
render = function()
return Roact.createElement(LayoutValuesProvider, {
layoutValues = self.layoutValues,
render = function()
return Roact.createElement("ScreenGui", {
AutoLocalize = false,
IgnoreGuiInset = true,
}, self.props[Roact.Children])
end,
})
end,
})
})
end
return UnitTestContainer