Skip to content

Commit 469ec2c

Browse files
committed
add unit tests
1 parent 48299f6 commit 469ec2c

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

packages/template-retail-react-app/app/components/store-locator-modal/stores-list.test.jsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import React from 'react'
99
import StoresList from '@salesforce/retail-react-app/app/components/store-locator-modal/stores-list'
1010
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
11-
import {waitFor, screen} from '@testing-library/react'
11+
import {waitFor, screen, fireEvent} from '@testing-library/react'
1212
import userEvent from '@testing-library/user-event'
1313
import {Accordion} from '@salesforce/retail-react-app/app/components/shared/ui'
14+
import mockConfig from '@salesforce/retail-react-app/config/mocks/default'
1415

1516
const mockSearchStoresData = [
1617
{
@@ -73,10 +74,9 @@ const mockSearchStoresData = [
7374
distance: 81.1,
7475
distanceUnit: 'km',
7576
id: '00021',
76-
inventoryId: 'inventory_m_store_store13',
7777
latitude: 49.4077,
7878
longitude: 8.6908,
79-
name: 'Heidelberg Tech Mart',
79+
name: 'Store with no inventoryId',
8080
phone: '+49 6221 123456',
8181
posEnabled: false,
8282
postalCode: '69117',
@@ -104,18 +104,26 @@ describe('StoresList', () => {
104104
</Accordion>
105105
)
106106

107+
expect(screen.queryAllByRole('radio')).toHaveLength(mockSearchStoresData.length)
108+
107109
await waitFor(async () => {
108-
const aStoreName = screen.getByText(/Wiesbaden Tech Depot/i)
109-
const aStoreAddress = screen.getByText(/Kirchgasse 12/i)
110-
const aStoreCityAndPostalCode = screen.getByText(/Wiesbaden, 65185/i)
111-
const aStoreDistance = screen.getByText(/0.74 km away/i)
112-
const aStorePhoneNumber = screen.getByText(/49 611 876543/i)
113-
114-
expect(aStoreName).toBeInTheDocument()
115-
expect(aStoreAddress).toBeInTheDocument()
116-
expect(aStoreCityAndPostalCode).toBeInTheDocument()
117-
expect(aStoreDistance).toBeInTheDocument()
118-
expect(aStorePhoneNumber).toBeInTheDocument()
110+
mockSearchStoresData.forEach((store) => {
111+
const storeName = screen.getByText(store.name)
112+
const storeAddress = screen.getByText(store.address1)
113+
const storeCityAndPostalCode = screen.getByText(
114+
`${store.city}, ${store.postalCode}`
115+
)
116+
const storeDistance = screen.getByText(
117+
`${store.distance} ${store.distanceUnit} away`
118+
)
119+
const storePhoneNumber = screen.getByText(`Phone: ${store.phone}`)
120+
121+
expect(storeName).toBeInTheDocument()
122+
expect(storeAddress).toBeInTheDocument()
123+
expect(storeCityAndPostalCode).toBeInTheDocument()
124+
expect(storeDistance).toBeInTheDocument()
125+
expect(storePhoneNumber).toBeInTheDocument()
126+
})
119127
})
120128
})
121129

@@ -169,4 +177,23 @@ describe('StoresList', () => {
169177
expect(positions).toEqual([...positions].sort((a, b) => a - b))
170178
})
171179
})
180+
181+
test('Can select store', async () => {
182+
renderWithProviders(
183+
<Accordion>
184+
<StoresList storesInfo={mockSearchStoresData} />
185+
</Accordion>
186+
)
187+
188+
await waitFor(async () => {
189+
const {id, name, inventoryId} = mockSearchStoresData[1]
190+
const radioButton = screen.getByDisplayValue(id)
191+
fireEvent.click(radioButton)
192+
193+
const expectedStoreInfo = {id, name, inventoryId}
194+
expect(localStorage.getItem(`store_${mockConfig.app.defaultSite}`)).toEqual(
195+
JSON.stringify(expectedStoreInfo)
196+
)
197+
})
198+
})
172199
})

0 commit comments

Comments
 (0)