Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a29155c

Browse files
authoredJun 18, 2024··
Display random prices for visual user (#124)
* Display random prices for visual user * update snapshot --------- Co-authored-by: Benjamin Karran <benjamin.karran@saucelabs.com>
1 parent cd9e149 commit a29155c

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed
 

‎src/pages/Inventory.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const Inventory = ({data}) => {
2828
}
2929
};
3030
const isVisualFailure = isVisualUser();
31+
const randomPrice = () => Math.round(Math.random() * 10000) / 100;
3132

3233
/* istanbul ignore next */
3334
if (isPerformanceGlitchUser()) {
@@ -117,7 +118,7 @@ const Inventory = ({data}) => {
117118
}
118119
name={item.name}
119120
desc={item.desc}
120-
price={item.price}
121+
price={isVisualFailure ? randomPrice() : item.price}
121122
isTextAlignRight={isVisualFailure && i > 1 && i < 4}
122123
missAlignButton={isVisualFailure && i === 5}
123124
/>

‎src/pages/__tests__/Inventory.tests.js

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe("Inventory", () => {
4343
it("should render correctly for a visual user", () => {
4444
const isVisualUserSpy = jest.spyOn(Credentials, "isVisualUser");
4545
isVisualUserSpy.mockReturnValue(true);
46+
47+
const randomSpy = jest.spyOn(Math, "random");
48+
randomSpy.mockReturnValue(0.5);
49+
4650
const wrapper = shallow(<Inventory.WrappedComponent data={InventoryData} />);
4751

4852
expect(wrapper).toMatchSnapshot();

‎src/pages/__tests__/__snapshots__/Inventory.tests.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
299299
key="4"
300300
missAlignButton={false}
301301
name="Sauce Labs Backpack"
302-
price={29.99}
302+
price={50}
303303
/>
304304
<withRouter(InventoryListItem)
305305
desc="A red light isn't the desired state in testing but it sure helps when riding your bike at night. Water-resistant with 3 lighting modes, 1 AAA battery included."
@@ -309,7 +309,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
309309
key="0"
310310
missAlignButton={false}
311311
name="Sauce Labs Bike Light"
312-
price={9.99}
312+
price={50}
313313
/>
314314
<withRouter(InventoryListItem)
315315
desc="Get your testing superhero on with the Sauce Labs bolt T-shirt. From American Apparel, 100% ringspun combed cotton, heather gray with red bolt."
@@ -319,7 +319,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
319319
key="1"
320320
missAlignButton={false}
321321
name="Sauce Labs Bolt T-Shirt"
322-
price={15.99}
322+
price={50}
323323
/>
324324
<withRouter(InventoryListItem)
325325
desc="It's not every day that you come across a midweight quarter-zip fleece jacket capable of handling everything from a relaxing day outdoors to a busy day at the office."
@@ -329,7 +329,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
329329
key="5"
330330
missAlignButton={false}
331331
name="Sauce Labs Fleece Jacket"
332-
price={49.99}
332+
price={50}
333333
/>
334334
<withRouter(InventoryListItem)
335335
desc="Rib snap infant onesie for the junior automation engineer in development. Reinforced 3-snap bottom closure, two-needle hemmed sleeved and bottom won't unravel."
@@ -339,7 +339,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
339339
key="2"
340340
missAlignButton={false}
341341
name="Sauce Labs Onesie"
342-
price={7.99}
342+
price={50}
343343
/>
344344
<withRouter(InventoryListItem)
345345
desc="This classic Sauce Labs t-shirt is perfect to wear when cozying up to your keyboard to automate a few tests. Super-soft and comfy ringspun combed cotton."
@@ -349,7 +349,7 @@ exports[`Inventory should render correctly for a visual user 1`] = `
349349
key="3"
350350
missAlignButton={true}
351351
name="Test.allTheThings() T-Shirt (Red)"
352-
price={15.99}
352+
price={50}
353353
/>
354354
</div>
355355
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.