freshyo/apps/user-ui/tests/components/static-chrome.test.tsx
2026-10-18 21:51:01 +05:30

171 lines
7.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Catalogue section 24 — "Static / chrome" (`tests/components/static-chrome.test.tsx`).
*
* - STATIC-01..05 TabLayoutWrapper, TestingPhaseNote, TermsAndConditionsContent,
* the tab icon set (focused/unfocused) and icon prop pass-through
* - TERMS-04..05 the shared `TermsAndConditionsContent` props (showTitle / compact)
*
* The icons intentionally exercise the `react-native-svg` shim so a broken icon
* (missing render) fails here instead of surfacing on a page test.
*/
import * as React from 'react'
import { Text } from 'react-native'
import { render, within } from '@testing-library/react-native'
import Svg, { Path } from 'react-native-svg'
import { resetAllMocks } from '../helpers/reset'
import { renderWithProviders } from '../helpers/test-utils'
import TabLayoutWrapper from '@/components/TabLayoutWrapper'
import TestingPhaseNote from '@/components/TestingPhaseNote'
import { TermsAndConditionsContent } from '@/components/TermsAndConditions'
import HomeIcon from '@/components/icons/HomeIcon'
import StoresIcon from '@/components/icons/StoresIcon'
import CartIcon from '@/components/icons/CartIcon'
import OffersIcon from '@/components/icons/OffersIcon'
import MeIcon from '@/components/icons/MeIcon'
describe('Static / chrome', () => {
beforeEach(() => resetAllMocks())
/** Deep-merge a (possibly nested, possibly falsy) RN style prop. */
const flatStyle = (style: any): Record<string, any> => {
if (!style) return {}
if (Array.isArray(style)) return Object.assign({}, ...style.map(flatStyle))
if (typeof style === 'object') return style
return {}
}
it('STATIC-01: TabLayoutWrapper renders children inside the top safe area', () => {
const { getByTestId, getByText } = renderWithProviders(
<TabLayoutWrapper style={{ backgroundColor: '#FFFFFF' }}>
<Text>tab-child</Text>
</TabLayoutWrapper>,
{ auth: false }
)
const wrapper = getByTestId('tab-layout-wrapper')
expect(getByText('tab-child')).toBeTruthy()
// Base `flex-1 bg-white` merged with the caller style.
const merged = flatStyle(wrapper.props.style)
expect(merged.backgroundColor).toBe('#FFFFFF')
expect(merged.flexGrow).toBe(1)
})
it('STATIC-02: TestingPhaseNote shows the title and four bullets', () => {
const { getByTestId } = renderWithProviders(<TestingPhaseNote />, { auth: false })
const note = within(getByTestId('testing-phase-note'))
expect(note.getByText('Testing Phase')).toBeTruthy()
expect(note.getByText('• This app is in testing phase until Jan 23, 2026')).toBeTruthy()
expect(note.getByText('• Actual delivery service has not started yet')).toBeTruthy()
expect(note.getByText('• Prices shown are not real')).toBeTruthy()
expect(
note.getByText('• Any feedback or issues found? WhatsApp on +91 9676651496')
).toBeTruthy()
})
it('STATIC-03: TermsAndConditionsContent renders the full policy', () => {
const { getByTestId } = renderWithProviders(<TermsAndConditionsContent />, { auth: false })
const terms = within(getByTestId('terms-content'))
expect(terms.getByText('FRESHYO – Legal Policies')).toBeTruthy()
// Sections A–E.
expect(terms.getByText('A. TERMS & CONDITIONS')).toBeTruthy()
expect(terms.getByText('B. PRIVACY POLICY')).toBeTruthy()
expect(terms.getByText('C. REFUND & CANCELLATION POLICY')).toBeTruthy()
expect(terms.getByText('D. CONTACT INFORMATION')).toBeTruthy()
expect(terms.getByText('E. ACCEPTANCE')).toBeTruthy()
// COD-only + privacy + refunds + contact.
expect(
terms.getByText(
'Prices are displayed in INR and include applicable taxes unless stated otherwise. Only Cash on Delivery (COD) is accepted. Full payment must be made at the time of delivery. Failure to pay may result in order cancellation and account restrictions.'
)
).toBeTruthy()
expect(
terms.getByText('FRESHYO respects your privacy and is committed to protecting your data.')
).toBeTruthy()
expect(
terms.getByText(
"Since payments are Cash on Delivery, refunds (if applicable) will be handled via: cash adjustment, replacement, or store credit (at FRESHYO's discretion)."
)
).toBeTruthy()
expect(terms.getByText('📧 Email: support@freshyo.in')).toBeTruthy()
expect(terms.getByText('📞 Customer Support: 8688182552')).toBeTruthy()
})
it('STATIC-04: every tab icon renders one SVG per focused/unfocused state', () => {
const { UNSAFE_getAllByType } = render(
<>
<HomeIcon focused size={24} color="#111111" />
<HomeIcon focused={false} size={24} color="#111111" />
<StoresIcon focused size={24} color="#111111" />
<StoresIcon focused={false} size={24} color="#111111" />
<CartIcon focused size={24} color="#111111" />
<CartIcon focused={false} size={24} color="#111111" />
<OffersIcon focused size={24} color="#111111" />
<OffersIcon focused={false} size={24} color="#111111" />
<MeIcon focused size={24} color="#111111" />
<MeIcon focused={false} size={24} color="#111111" />
</>
)
expect(UNSAFE_getAllByType(Svg)).toHaveLength(10)
})
it('STATIC-05: icon size and color are passed through to the SVG props', () => {
const { UNSAFE_getAllByType, UNSAFE_getByType } = render(
<HomeIcon focused size={40} color="#123456" />
)
const svg = UNSAFE_getByType(Svg)
expect(svg.props.width).toBe(40)
expect(svg.props.height).toBe(40)
const paths = UNSAFE_getAllByType(Path)
expect(paths.length).toBeGreaterThan(0)
paths.forEach((path: any) => expect(path.props.fill).toBe('#123456'))
})
it('TERMS-04: showTitle=false hides the title but keeps the sections', () => {
const { getByTestId, queryByText } = renderWithProviders(
<TermsAndConditionsContent showTitle={false} />,
{ auth: false }
)
expect(queryByText('FRESHYO – Legal Policies')).toBeNull()
expect(queryByText('Last Updated: [Add Date]')).toBeNull()
const terms = within(getByTestId('terms-content'))
expect(terms.getByText('A. TERMS & CONDITIONS')).toBeTruthy()
expect(terms.getByText('E. ACCEPTANCE')).toBeTruthy()
})
it('TERMS-05: compact applies the smaller text styles', () => {
const regular = renderWithProviders(<TermsAndConditionsContent showTitle={false} />, {
auth: false,
})
const compact = renderWithProviders(
<TermsAndConditionsContent showTitle={false} compact />,
{ auth: false }
)
const styleOf = (result: any, text: string) => flatStyle(result.getByText(text).props.style)
const regularHeading = styleOf(regular, 'A. TERMS & CONDITIONS')
const compactHeading = styleOf(compact, 'A. TERMS & CONDITIONS')
expect(compactHeading.fontSize).toBeLessThan(regularHeading.fontSize)
const regularBody = styleOf(
regular,
'FRESHYO is a grocery and fresh meat delivery application serving customers only within Mahabubnagar Town, Telangana, India.'
)
const compactBody = styleOf(
compact,
'FRESHYO is a grocery and fresh meat delivery application serving customers only within Mahabubnagar Town, Telangana, India.'
)
expect(compactBody.fontSize).toBeLessThan(regularBody.fontSize)
})
})