Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.9 kB
1
Indexable
Never
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import TopPages from '../../../src/components/ui/feed/TopPages';

describe('TopPages', () => {
  const report = {
    data: {
      score: {
        web: 'reportback.com',
      },
      analytics: {
        pagesUsersVisit: [
          {
            name: '/',
            sessions: 100,
          },
          {
            name: '/googleAnalytics',
            sessions: 50,
          },
          {
            name: '/Change',
            sessions: 100,
          },
          {
            name: '/HomePage',
            sessions: 50,
          },
          {
            name: '//History',
            sessions: 100,
          },
          {
            name: '/googleAnalytics/History',
            sessions: 50,
          },
          {
            name: '/Change/Users',
            sessions: 100,
          },
          {
            name: '/googleAnalytics/Change/USERS',
            sessions: 50,
          },
          {
            name: '/googleAnalytics/Change/users',
            sessions: 50,
          },


        ],
        pagesPageViews: [
          {
            name: '/',
            sessions: 200,
          },
          {
            name: '/googleAnalytics',
            sessions: 150,
          },
          {
            name: '/Change',
            sessions: 200,
          },
          {
            name: '/googleAnalytics/Change',
            sessions: 150,
          },
          {
            name: '/Analytics',
            sessions: 150,
          },
          {
            name: '/googleAnalytics/Users',
            sessions: 150,
          },
          {
            name: '/Change/Users',
            sessions: 200,
          },
          {
            name: '/googleAnalytics/Change/Users',
            sessions: 150,
          },
          {
            name: '/googleAnalytics/Users',
            sessions: 150,
          },
          {
            name: '/Users',
            sessions: 150,
          },
        ],

      },
    },
  };
  const report1 = {
    data: {
      analytics: {
        pagesPageViews: {

        },
        pagesUsersVisit: {

        }

      }
    }
  };
  const report2 = {
    data: {
      score: {
        web: 'reportback.com',
      },
      analytics: {
        pagesUsersVisit: [
        ],
        pagesPageViews: [
          {
            name: '/',
            sessions: 200,
          },
          {
            name: '/googleAnalytics',
            sessions: 150,
          },
          {
            name: '/Change',
            sessions: 200,
          },
          {
            name: '/googleAnalytics/Change',
            sessions: 150,
          },
          {
            name: '/Analytics',
            sessions: 150,
          },
          {
            name: '/googleAnalytics/Users',
            sessions: 150,
          },
          {
            name: '/Change/Users',
            sessions: 200,
          },
          {
            name: '/googleAnalytics/Change/Users',
            sessions: 150,
          },
          {
            name: '/googleAnalytics/Users',
            sessions: 150,
          },
          {
            name: '/Users',
            sessions: 150,
          },
        ],

      },
    },
  };
  it('renders without error', () => {
    render(<TopPages report={report} />);
  });
  it('renders with', () => {
    render(<TopPages report={!report} />);
  })
  it('renders with', () => {
    render(<TopPages report={report1} />);
  })
  it('renders the top pages correctly', () => {
    const { getByText } = render(<TopPages report={report} />);

    expect(getByText('Homepage')).toBeTruthy();
    expect(getByText('https://reportback.com/Change')).toBeTruthy();
  });
  it('is no data', () => {
    const pagesEmptyPagesUsers = true;
    const isEmptyPagesPageViews = true;
    const { getByText } = render(<TopPages report={report} />);
  });
  it('opens the link when a page is clicked', () => {
    const { getByText } = render(<TopPages report={report} />);
    const homepageLink = getByText('Homepage');
    const googleAnalyticsLink = getByText('https://reportback.com/Change');

    fireEvent.press(homepageLink);
    fireEvent.press(googleAnalyticsLink);

  });

  test('renders top pages correctly', () => {
    const { getByText } = render(<TopPages report={report} />);

    expect(getByText('reportback.com/Change')).toBeTruthy();
    expect(getByText('Users')).toBeTruthy();
    expect(getByText('100')).toBeTruthy();
    expect(getByText('Last Week')).toBeTruthy();
    expect(getByText('Page Views')).toBeTruthy();
    expect(getByText('1000')).toBeTruthy();
  });

  test('clicking on a page should open the corresponding URL', () => {
    const { getByText } = render(<TopPages report={report} />);
    const pageLink = getByText('reportback.com/Change');

    fireEvent.press(pageLink);
  });
  it('opens the link when a page is clicked', () => {
    const { getByText } = render(<TopPages report={report1} />);
    const homepageLink = getByText('Homepage');
    const googleAnalyticsLink = getByText('https://reportback.com/HomePage');

    fireEvent.press(homepageLink);
    fireEvent.press(googleAnalyticsLink);

  });
  test('renders top pages correctly', () => {
    const { getByText } = render(<TopPages report={report1} />);

    expect(getByText('reportback.com/Change')).toBeTruthy();
    expect(getByText('Users')).toBeTruthy();
    expect(getByText('100')).toBeTruthy();
    expect(getByText('Last Week')).toBeTruthy();
    expect(getByText('Page Views')).toBeTruthy();
    expect(getByText('1000')).toBeTruthy();
  });

  test('clicking on a page should open the corresponding URL', () => {
    const { getByText } = render(<TopPages report={report1} />);
    const pageLink = getByText('reportback.com/Change');

    fireEvent.press(pageLink);
  });
  
});