48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
|
|
// @vitest-environment jsdom
|
||
|
|
import { afterEach, describe, expect, test } from 'vitest';
|
||
|
|
import { cleanup, render, screen } from '@testing-library/react';
|
||
|
|
import CardDetailPurchaseTab, { stalenessBadgeText } from '../../components/card-detail/CardDetailPurchaseTab';
|
||
|
|
|
||
|
|
afterEach(() => cleanup());
|
||
|
|
|
||
|
|
const formatCurrency = (amount) => `$${Number(amount).toFixed(2)}`;
|
||
|
|
|
||
|
|
describe('stalenessBadgeText', () => {
|
||
|
|
test('shows outdated copy when stale', () => {
|
||
|
|
expect(stalenessBadgeText({ stale: true, pricesUpdatedAt: '2026-01-01T00:00:00.000Z' }))
|
||
|
|
.toBe('Prices may be outdated');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('shows updated date when fresh', () => {
|
||
|
|
const text = stalenessBadgeText({ stale: false, pricesUpdatedAt: '2026-01-15T00:00:00.000Z' });
|
||
|
|
expect(text).toContain('Updated');
|
||
|
|
expect(text).toContain('2026');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('<CardDetailPurchaseTab>', () => {
|
||
|
|
test('renders staleness badge text from pricing payload', () => {
|
||
|
|
render(
|
||
|
|
<CardDetailPurchaseTab
|
||
|
|
card={{ name: 'Lightning Bolt', current_price: 1, market_price: 2, game: 'MTG' }}
|
||
|
|
pricing={{
|
||
|
|
prices: { current: 1.25, market: 2.5, currency: 'USD' },
|
||
|
|
pricesUpdatedAt: '2026-01-01T00:00:00.000Z',
|
||
|
|
stale: true,
|
||
|
|
outbound: {
|
||
|
|
tcgplayer: 'https://www.tcgplayer.com/search',
|
||
|
|
ebay: 'https://www.ebay.com/sch',
|
||
|
|
},
|
||
|
|
}}
|
||
|
|
pricingLoading={false}
|
||
|
|
formatCurrency={formatCurrency}
|
||
|
|
/>
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(screen.getByTestId('pricing-staleness-badge').textContent)
|
||
|
|
.toBe('Prices may be outdated');
|
||
|
|
expect(screen.getByText('View on TCGPlayer')).toBeDefined();
|
||
|
|
expect(screen.getByTestId('card-detail-local-stores-slot')).toBeDefined();
|
||
|
|
});
|
||
|
|
});
|