@@ -32,6 +32,7 @@ jest.mock("contexts/useProxyLatency", () => ({
3232
3333let hardCodedLatencies :Record < string , ProxyLatency . ProxyLatencyReport > = { }
3434
35+ // fakeLatency is a helper function to make a Latency report from just a number.
3536const fakeLatency = ( ms :number ) :ProxyLatency . ProxyLatencyReport => {
3637return {
3738latencyMS :ms ,
@@ -164,12 +165,23 @@ const TestingScreen = () => {
164165}
165166
166167interface ProxyContextSelectionTest {
168+ // Regions is the list of regions to return via the "api" response.
167169regions :Region [ ]
170+ // storageProxy should be the proxy stored in local storage before the
171+ // component is mounted and context is loaded. This simulates opening a
172+ // new window with a selection saved from before.
168173storageProxy :Region | undefined
174+ // latencies is the hard coded latencies to return. If empty, no latencies
175+ // are returned.
169176latencies ?:Record < string , ProxyLatency . ProxyLatencyReport >
177+ // afterLoad are actions to take after loading the component, but before
178+ // assertions. This is useful for simulating user actions.
170179afterLoad ?:( user :typeof userEvent ) => Promise < void >
171180
181+ // Assert these values.
182+ // expProxyID is the proxyID returned to be used.
172183expProxyID :string
184+ // expUserProxyID is the user's stored selection.
173185expUserProxyID ?:string
174186}
175187
@@ -301,6 +313,23 @@ describe("ProxyContextSelection", () => {
301313} ,
302314} ,
303315] ,
316+ [
317+ // Excess proxies we do not have are low latency.
318+ // This will probably never happen in production.
319+ "unknown_regions_low_latency" ,
320+ {
321+ // Default to primary since we have unknowns
322+ expProxyID :MockPrimaryWorkspaceProxy . id ,
323+ regions :MockWorkspaceProxies ,
324+ storageProxy :MockUnhealthyWildWorkspaceProxy ,
325+ expUserProxyID :MockUnhealthyWildWorkspaceProxy . id ,
326+ latencies :{
327+ [ "some" ] :fakeLatency ( 500 ) ,
328+ [ "random" ] :fakeLatency ( 100 ) ,
329+ [ "ids" ] :fakeLatency ( 25 ) ,
330+ } ,
331+ } ,
332+ ] ,
304333] as [ string , ProxyContextSelectionTest ] [ ] ) (
305334`%s` ,
306335async (
@@ -317,12 +346,6 @@ describe("ProxyContextSelection", () => {
317346// Mock the latencies
318347hardCodedLatencies = latencies
319348
320- // jest.mock("contexts/useProxyLatency", () => ({
321- // useProxyLatency: () => {
322- // return latencies
323- // },
324- // }))
325-
326349// Initial selection if present
327350if ( storageProxy ) {
328351saveUserSelectedProxy ( storageProxy )