-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.test.js
More file actions
93 lines (84 loc) · 3.96 KB
/
index.test.js
File metadata and controls
93 lines (84 loc) · 3.96 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* 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 PropTypes from 'prop-types'
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 MockComponent = ({selectedStore, isStoreSelected = true, productInventories}) => {
return (
<StoreLocatorContext.Provider value={{selectedStore, isStoreSelected}}>
<StoreAvailabilityText productInventories={productInventories} />
</StoreLocatorContext.Provider>
)
}
MockComponent.propTypes = {
selectedStore: PropTypes.object,
isStoreSelected: PropTypes.bool,
productInventories: PropTypes.array
}
describe('StoreAvailability', () => {
describe('store is not selected', () => {
test('renders "In Stock at Select Store"', () => {
renderWithProviders(<MockComponent selectedStore={{}} isStoreSelected={false} />)
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', () => {
renderWithProviders(<MockComponent selectedStore={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', () => {
const storeWithNoInventoryId = {...selectedStore, inventoryId: null}
renderWithProviders(<MockComponent selectedStore={storeWithNoInventoryId} />)
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', () => {
const productInventories = [{id: 'inventory_99', orderable: true}]
renderWithProviders(
<MockComponent
selectedStore={selectedStore}
productInventories={productInventories}
/>
)
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', () => {
const productInventories = [{id: 'inventory_1', orderable: false}]
renderWithProviders(
<MockComponent
selectedStore={selectedStore}
productInventories={productInventories}
/>
)
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', () => {
const productInventories = [{id: 'inventory_1', orderable: true}]
renderWithProviders(
<MockComponent
selectedStore={selectedStore}
productInventories={productInventories}
/>
)
expect(screen.getByText(/In Stock at/i)).toBeInTheDocument()
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
})
})