Skip to content

Commit

Permalink
Merge pull request #915 from Ekep-Obasi/test-device-compatiblity-notice
Browse files Browse the repository at this point in the history
[Component Tests] Device Compatibility
  • Loading branch information
Rassl authored Feb 13, 2024
2 parents e063ed2 + 9ead7d9 commit 0ba87ec
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import '@testing-library/jest-dom'
import { fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import { DeviceCompatibilityNotice } from '..'
import * as MobileHook from '../../../../hooks/useIsMobile'

jest.mock('~/hooks/useIsMobile')

const useIsMobileHook = jest.spyOn(MobileHook, 'useIsMobile')

describe('DeviceCompatibilityNotice Component', () => {
beforeEach(() => {
jest.clearAllMocks()
useIsMobileHook.mockReturnValue(true)
})

it('should display message and button correctly', () => {
render(<DeviceCompatibilityNotice />)

expect(screen.getByText('Second Brain is currently')).toBeInTheDocument()
expect(screen.getByText('optimized for Desktop.')).toBeInTheDocument()
expect(screen.getByText('Mobile support coming soon.')).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Got It' })).toBeInTheDocument()
})

it('hides the notice when "Got It" button is clicked', () => {
jest.mock('../', () => jest.fn(() => <div data-testid="device-compatibility-notice" />))

render(<DeviceCompatibilityNotice />)

fireEvent.click(screen.getByRole('button', { name: 'Got It' }))

expect(screen.queryByTestId('device-compatibility-notice')).not.toBeInTheDocument()
})

it('should not render notice when useIsMobile hook returns false.', () => {
useIsMobileHook.mockReturnValue(false)

jest.mock('../', () => jest.fn(() => <div data-testid="device-compatibility-notice" />))

render(<DeviceCompatibilityNotice />)

expect(screen.queryByTestId('device-compatibility-notice')).not.toBeInTheDocument()
})
})

0 comments on commit 0ba87ec

Please sign in to comment.