-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.test.js
More file actions
73 lines (63 loc) · 3.32 KB
/
index.test.js
File metadata and controls
73 lines (63 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import {screen} from '@testing-library/react'
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
import StoreAvailabilityText from '@salesforce/retail-react-app/app/components/store-availability-text'
import {StoreLocatorContext} from '@salesforce/retail-react-app/app/components/store-locator-modal'
const selectedStore = {
name: 'Test Store',
id: 'test_store',
inventoryId: 'inventory_1'
}
const renderWithStoreLocatorContextProvider = (selectedStore, productInventories = []) => {
return renderWithProviders(
<StoreLocatorContext.Provider value={{ selectedStore, isStoreSelected: true }}>
<StoreAvailabilityText productInventories={productInventories} />
</StoreLocatorContext.Provider>
)
}
describe('StoreAvailability', () => {
describe('store is not selected', () => {
test('renders "In Stock at Select Store"', () => {
renderWithProviders(
<StoreLocatorContext.Provider value={{ selectedStore: {} }}>
<StoreAvailabilityText />
</StoreLocatorContext.Provider>
)
expect(screen.getByText(/In Stock at/i)).toBeInTheDocument()
expect(screen.getByText(/Select Store/i)).toBeInTheDocument()
})
})
describe('store is selected', () => {
test('renders "Out of Stock at Test Store" when productInventories is undefined', () => {
renderWithStoreLocatorContextProvider(selectedStore)
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
test('renders "Out of Stock at Test Store" when selectedStore does not have an inventoryId', () => {
renderWithStoreLocatorContextProvider({ ...selectedStore, inventoryId: null })
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
test('renders "Out of Stock at Test Store" if selectedStore inventoryId is not in productInventories', () => {
renderWithStoreLocatorContextProvider(selectedStore, [{ id: 'inventory_99', orderable: true }])
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
test('renders "Out of Stock at Test Store" if orderable is false', () => {
renderWithStoreLocatorContextProvider(selectedStore, [{ id: 'inventory_1', orderable: false }])
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
test('renders "In Stock at Test Store" if orderable is true', () => {
renderWithStoreLocatorContextProvider(selectedStore, [{ id: 'inventory_1', orderable: true }])
expect(screen.getByText(/In Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
})
})