-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathindex.test.js
More file actions
60 lines (49 loc) · 2.24 KB
/
index.test.js
File metadata and controls
60 lines (49 loc) · 2.24 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
/*
* Copyright (c) 2021, salesforce.com, 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, within} from '@testing-library/react'
import Footer from '@salesforce/retail-react-app/app/components/footer/index'
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
import {useBreakpointValue} from '@chakra-ui/react'
// Mock the Chakra UI hook
jest.mock('@chakra-ui/react', () => ({
...jest.requireActual('@chakra-ui/react'),
useBreakpointValue: jest.fn()
}))
describe('Footer', () => {
beforeEach(() => {
jest.resetAllMocks()
})
test('renders component', () => {
renderWithProviders(<Footer />)
expect(screen.getByRole('link', {name: 'Privacy Policy'})).toBeInTheDocument()
})
test('renders mobile version by default', () => {
renderWithProviders(<Footer />)
// This link is hidden initially, but would be shown for desktop
expect(screen.getByRole('link', {name: 'About Us', hidden: true})).toBeInTheDocument()
})
test('renders desktop version (desktop links visible)', () => {
// Mock for desktop view - force all content to be visible
useBreakpointValue.mockImplementation(() => true)
renderWithProviders(<Footer />)
// Get footer element and search within it
const footer = screen.getByRole('contentinfo')
const orderStatusLink = within(footer).getByText('Order Status')
expect(orderStatusLink).toBeInTheDocument()
expect(orderStatusLink).toHaveAttribute('href', '/uk/en-GB/order-status')
expect(screen.getAllByText(/privacy policy/i)[0]).toBeInTheDocument()
})
test('renders mobile version (only mobile links visible)', () => {
// Mock for mobile view - hide desktop content
useBreakpointValue.mockImplementation(() => false)
renderWithProviders(<Footer />)
// Verify desktop elements are hidden
expect(screen.queryByRole('link', {name: /order status/i})).not.toBeInTheDocument()
expect(screen.getAllByText(/privacy policy/i)[0]).toBeInTheDocument()
})
})