-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.test.js
More file actions
66 lines (58 loc) · 2.45 KB
/
index.test.js
File metadata and controls
66 lines (58 loc) · 2.45 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
/*
* 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'
const selectedStore = {
name: 'Test Store',
id: 'test_store',
inventoryId: 'inventory_1'
}
describe('Store Name Rendering', () => {
test('renders "Select Store" if selectedStore does not contain a name field', () => {
renderWithProviders(<StoreAvailabilityText selectedStore={{}} />)
expect(screen.getByText(/Select Store/i)).toBeInTheDocument()
})
test('renders store name if selectedStore contains a name field', () => {
renderWithProviders(<StoreAvailabilityText selectedStore={selectedStore} />)
expect(screen.getByText(selectedStore.name)).toBeInTheDocument()
})
})
describe('Stock Availability Rendering', () => {
test('renders "In Stock" when productInventories is undefined', () => {
renderWithProviders(<StoreAvailabilityText selectedStore={selectedStore} />)
expect(screen.getByText(/In Stock at/i)).toBeInTheDocument()
})
test('renders "In Stock" if orderable is true', () => {
renderWithProviders(
<StoreAvailabilityText
selectedStore={selectedStore}
productInventories={[{id: 'inventory_1', orderable: true}]}
/>
)
expect(screen.getByText(/In Stock at/i)).toBeInTheDocument()
})
test('renders "Out of Stock" if orderable is false', () => {
renderWithProviders(
<StoreAvailabilityText
selectedStore={selectedStore}
productInventories={[{id: 'inventory_1', orderable: false}]}
/>
)
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
})
test('renders "Out of Stock" if selectedStore inventoryId is not in productInventories', () => {
renderWithProviders(
<StoreAvailabilityText
selectedStore={selectedStore}
productInventories={[{id: 'inventory_99', orderable: true}]}
/>
)
expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument()
})
})