1
1
/**
2
- * Copyright 2018-2019, Optimizely
2
+ * Copyright 2018-2019, 2023, Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http ://www.apache.org/licenses/LICENSE-2.0
8
+ * https ://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -170,7 +170,7 @@ describe('<OptimizelyExperiment>', () => {
170
170
await waitFor ( ( ) => expect ( screen . getByTestId ( 'variation-key' ) ) . toHaveTextContent ( 'correct variation' ) ) ;
171
171
} ) ;
172
172
173
- it ( 'should render using <OptimizelyVariation default>' , async ( ) => {
173
+ it ( 'should render using <OptimizelyVariation default> in last position ' , async ( ) => {
174
174
const { container } = render (
175
175
< OptimizelyProvider optimizely = { optimizelyMock } >
176
176
< OptimizelyExperiment experiment = "experiment1" >
@@ -196,6 +196,56 @@ describe('<OptimizelyExperiment>', () => {
196
196
await waitFor ( ( ) => expect ( screen . getByTestId ( 'variation-key' ) ) . toHaveTextContent ( 'default variation' ) ) ;
197
197
} ) ;
198
198
199
+ it ( 'should NOT render using <OptimizelyVariation default> in first position when matching variation' , async ( ) => {
200
+ const { container } = render (
201
+ < OptimizelyProvider optimizely = { optimizelyMock } >
202
+ < OptimizelyExperiment experiment = "experiment1" >
203
+ < OptimizelyVariation default >
204
+ < span data-testid = "variation-key" > default variation</ span >
205
+ </ OptimizelyVariation >
206
+ < OptimizelyVariation variation = "variationResult" >
207
+ < span data-testid = "variation-key" > matching variation</ span >
208
+ </ OptimizelyVariation >
209
+ </ OptimizelyExperiment >
210
+ </ OptimizelyProvider >
211
+ ) ;
212
+
213
+ // while it's waiting for onReady()
214
+ expect ( container . innerHTML ) . toBe ( '' ) ;
215
+
216
+ // Simulate client becoming ready
217
+ resolver . resolve ( { success : true } ) ;
218
+
219
+ await optimizelyMock . onReady ( ) ;
220
+
221
+ await waitFor ( ( ) => expect ( screen . getByTestId ( 'variation-key' ) ) . toHaveTextContent ( 'matching variation' ) ) ;
222
+ } ) ;
223
+
224
+ it ( 'should render using <OptimizelyVariation default> in first position when NO matching variation' , async ( ) => {
225
+ const { container } = render (
226
+ < OptimizelyProvider optimizely = { optimizelyMock } >
227
+ < OptimizelyExperiment experiment = "experiment1" >
228
+ < OptimizelyVariation default >
229
+ < span data-testid = "variation-key" > default variation</ span >
230
+ </ OptimizelyVariation >
231
+ < OptimizelyVariation variation = "otherVariation" >
232
+ < span data-testid = "variation-key" > other non-matching variation</ span >
233
+ </ OptimizelyVariation >
234
+ </ OptimizelyExperiment >
235
+ </ OptimizelyProvider >
236
+ ) ;
237
+
238
+ // while it's waiting for onReady()
239
+ expect ( container . innerHTML ) . toBe ( '' ) ;
240
+
241
+ // Simulate client becoming ready
242
+ resolver . resolve ( { success : true } ) ;
243
+
244
+ await optimizelyMock . onReady ( ) ;
245
+
246
+ await waitFor ( ( ) => expect ( screen . getByTestId ( 'variation-key' ) ) . toHaveTextContent ( 'default variation' ) ) ;
247
+ } ) ;
248
+
199
249
it ( 'should render an empty string when no default or matching variation is provided' , async ( ) => {
200
250
const { container } = render (
201
251
< OptimizelyProvider optimizely = { optimizelyMock } >
0 commit comments