@@ -7,35 +7,113 @@ const ReactTestUtils = require("react-dom/test-utils");
77const { test_providedVariables } = require ( "./Test_providedVariables.bs" ) ;
88
99describe ( "Provided variables" , ( ) => {
10- test ( "provided variables work" , async ( ) => {
10+ const providedVariables = {
11+ __relay_internal__pv__ProvidedVariablesBool : true ,
12+ __relay_internal__pv__ProvidedVariablesInputC : {
13+ intStr : "123" ,
14+ recursiveC : {
15+ intStr : "234" ,
16+ } ,
17+ } ,
18+ __relay_internal__pv__ProvidedVariablesInputCArr : [
19+ {
20+ intStr : "123" ,
21+ } ,
22+ ] ,
23+ __relay_internal__pv__ProvidedVariablesIntStr : "456" ,
24+ __relay_internal__pv__ProvidedVariablesIntStrArr : [ "456" ] ,
25+ } ;
26+
27+ const mockProvidedVariablesQuery = ( someRandomArgField ) =>
1128 queryMock . mockQuery ( {
1229 name : "TestProvidedVariablesQuery" ,
13- variables : {
14- __relay_internal__pv__ProvidedVariablesBool : true ,
15- __relay_internal__pv__ProvidedVariablesInputC : {
16- intStr : "123" ,
17- recursiveC : {
18- intStr : "234" ,
19- } ,
20- } ,
21- __relay_internal__pv__ProvidedVariablesInputCArr : [
22- {
23- intStr : "123" ,
24- } ,
25- ] ,
26- __relay_internal__pv__ProvidedVariablesIntStr : "456" ,
27- __relay_internal__pv__ProvidedVariablesIntStrArr : [ "456" ] ,
28- } ,
30+ variables : providedVariables ,
2931 data : {
3032 loggedInUser : {
3133 __typename : "User" ,
3234 id : "user-1" ,
33- someRandomArgField : "hello" ,
35+ someRandomArgField,
3436 } ,
3537 } ,
3638 } ) ;
3739
40+ test ( "provided variables work" , async ( ) => {
41+ mockProvidedVariablesQuery ( "hello" ) ;
42+
43+ t . render ( test_providedVariables ( ) ) ;
44+ await t . screen . findByText ( "hello" ) ;
45+ } ) ;
46+
47+ test ( "loading a no-variable query with provided variables from the raw module works" , async ( ) => {
48+ mockProvidedVariablesQuery ( "hello" ) ;
49+
50+ t . render ( test_providedVariables ( ) ) ;
51+ await t . screen . findByText ( "hello" ) ;
52+
53+ ReactTestUtils . act ( ( ) => {
54+ t . fireEvent . click ( t . screen . getByText ( "Test provided variable raw load" ) ) ;
55+ } ) ;
56+
57+ await t . screen . findByText ( "Preloaded provided variable: hello" ) ;
58+ } ) ;
59+
60+ test ( "loading a no-variable query with provided variables through useLoader works" , async ( ) => {
61+ mockProvidedVariablesQuery ( "hello" ) ;
62+
63+ t . render ( test_providedVariables ( ) ) ;
64+ await t . screen . findByText ( "hello" ) ;
65+
66+ ReactTestUtils . act ( ( ) => {
67+ t . fireEvent . click (
68+ t . screen . getByText ( "Test provided variable query loader" )
69+ ) ;
70+ } ) ;
71+
72+ await t . screen . findByText ( "Preloaded provided variable: hello" ) ;
73+ } ) ;
74+
75+ test ( "fetching a no-variable query with provided variables works" , async ( ) => {
76+ mockProvidedVariablesQuery ( "hello" ) ;
77+
78+ t . render ( test_providedVariables ( ) ) ;
79+ await t . screen . findByText ( "hello" ) ;
80+
81+ mockProvidedVariablesQuery ( "fetch" ) ;
82+
83+ ReactTestUtils . act ( ( ) => {
84+ t . fireEvent . click ( t . screen . getByText ( "Test provided variable fetch" ) ) ;
85+ } ) ;
86+
87+ await t . screen . findByText ( "Provided variable fetch status: fetch" ) ;
88+ } ) ;
89+
90+ test ( "fetching a no-variable query with provided variables as a promise works" , async ( ) => {
91+ mockProvidedVariablesQuery ( "hello" ) ;
92+
3893 t . render ( test_providedVariables ( ) ) ;
3994 await t . screen . findByText ( "hello" ) ;
95+
96+ mockProvidedVariablesQuery ( "fetch promised" ) ;
97+
98+ ReactTestUtils . act ( ( ) => {
99+ t . fireEvent . click (
100+ t . screen . getByText ( "Test provided variable fetch promised" )
101+ ) ;
102+ } ) ;
103+
104+ await t . screen . findByText ( "Provided variable fetch status: fetch promised" ) ;
105+ } ) ;
106+
107+ test ( "retaining a no-variable query with provided variables works" , async ( ) => {
108+ mockProvidedVariablesQuery ( "hello" ) ;
109+
110+ t . render ( test_providedVariables ( ) ) ;
111+ await t . screen . findByText ( "hello" ) ;
112+
113+ ReactTestUtils . act ( ( ) => {
114+ t . fireEvent . click ( t . screen . getByText ( "Test provided variable retain" ) ) ;
115+ } ) ;
116+
117+ await t . screen . findByText ( "Provided variable retain status: retained" ) ;
40118 } ) ;
41119} ) ;
0 commit comments