Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

2.5 KB
Raw Blame
import React from 'react';
import { describe, it, expect, beforeEach } from 'vitest';
import userEvent from '@testing-library/user-event';
import { render, screen, waitFor } from '../../../helpers/render';
import { resetAllStores } from '../../../helpers/store';
import MNotifications from '../../../../src/mobile/screens/notifications/MNotifications';

// FE-MOB-NOTIF-001 onwards

beforeEach(() => {
  resetAllStores();
});

describe('MNotifications', () => {
  it('FE-MOB-NOTIF-001: loads the first page with unread badge and bulk actions', async () => {
    render(<MNotifications />);

    // Default handler: 25 notifications (page of 20), unread_count 5.
    await waitFor(() => {
      expect(screen.getAllByText('notif.title')).toHaveLength(20);
    });
    expect(screen.getByText('5')).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Mark all read' })).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Delete all' })).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
  });

  it('FE-MOB-NOTIF-001b: Delete all asks for confirmation before it clears the list', async () => {
    const user = userEvent.setup();
    render(<MNotifications />);
    await waitFor(() => {
      expect(screen.getAllByText('notif.title')).toHaveLength(20);
    });

    await user.click(screen.getByRole('button', { name: 'Delete all' }));
    expect(screen.getAllByText('notif.title')).toHaveLength(20);

    await user.click(screen.getByRole('button', { name: 'Cancel' }));
    expect(screen.getAllByText('notif.title')).toHaveLength(20);

    await user.click(screen.getByRole('button', { name: 'Delete all' }));
    await user.click(screen.getAllByRole('button', { name: 'Delete all' }).slice(-1)[0]);
    await waitFor(() => {
      expect(screen.queryAllByText('notif.title')).toHaveLength(0);
    });
  });

  it('FE-MOB-NOTIF-002: the unread segment filters out read notifications', async () => {
    const user = userEvent.setup();
    render(<MNotifications />);

    await waitFor(() => {
      expect(screen.getAllByText('notif.title')).toHaveLength(20);
    });

    // First 5 rows of the default handler are unread.
    await user.click(screen.getByRole('tab', { name: 'Unread' }));
    await waitFor(() => {
      expect(screen.getAllByText('notif.title')).toHaveLength(5);
    });

    await user.click(screen.getByRole('tab', { name: 'All' }));
    await waitFor(() => {
      expect(screen.getAllByText('notif.title')).toHaveLength(20);
    });
  });
});