All files / src/web/components/__tests__ test-utils.ts

95.83% Statements 46/48
80% Branches 4/5
100% Functions 2/2
95.83% Lines 46/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x   1x 10x 10x 10x   10x 6x 6x       6x 6x 6x 10x   10x   10x 10x 10x 10x 10x 10x 10x  
import { NewsletterWithRelations } from '@common/types';
 
export const createMockNewsletter = (id: string, overrides: Partial<NewsletterWithRelations> = {}): NewsletterWithRelations => ({
  id,
  title: `Test Newsletter ${id}`,
  content: `Content for newsletter ${id}`,
  summary: `Summary for newsletter ${id}`,
  received_at: new Date(Date.now() - (parseInt(id) * 24 * 60 * 60 * 1000)).toISOString(),
  updated_at: new Date().toISOString(),
  is_read: false,
  is_liked: false,
  is_archived: false,
  user_id: 'user-1',
  newsletter_source_id: `source-${id}`,
  source_id: `source-${id}`,
  source: {
    id: `source-${id}`,
    name: `Test Source ${id}`,
    from: `test${id}@example.com`,
    user_id: 'user-1',
    created_at: new Date().toISOString(),
    updated_at: new Date().toISOString(),
    is_archived: false,
  },
  tags: [],
  word_count: 100,
  estimated_read_time: 1,
  ...overrides,
});
 
export const setupIntersectionObserverMock = () => {
  const mockUnobserve = vi.fn();
  const mockDisconnect = vi.fn();
  const mockObserve = vi.fn();
 
  const IntersectionObserverMock = vi.fn((callback) => ({
    observe: mockObserve.mockImplementation((element) => {
      if (element?.dataset?.testid === 'loading-sentinel') {
        // Simulate intersection
        callback([{ isIntersecting: true, target: element }], { disconnect: mockDisconnect });
      }
    }),
    unobserve: mockUnobserve,
    disconnect: mockDisconnect,
  }));
 
  global.IntersectionObserver = IntersectionObserverMock;
 
  return {
    mockObserve,
    mockUnobserve,
    mockDisconnect,
    IntersectionObserverMock,
  };
};