<commit_before>import React from 'react';
import { mount } from 'enzyme';

import { PageCanvasInternal as PageCanvas } from './PageCanvas';

import failingPage from '../../__mocks__/_failing_page';

import { makeAsyncCallback, muteConsole, restoreConsole } from '../../test-utils';

/* eslint-disable comma-dangle */

describe('PageCanvas', () => {
  describe('loading', () => {
    it('calls onRenderError when failed to render canvas', async () => {
      const {
        func: onRenderError, promise: onRenderErrorPromise
      } = makeAsyncCallback();

      muteConsole();

      mount(
        <PageCanvas
          onRenderError={onRenderError}
          page={failingPage}
        />
      );

      expect.assertions(1);
      await expect(onRenderErrorPromise).resolves.toBeInstanceOf(Error);

      restoreConsole();
    });
  });
});
<commit_msg>Add unit test for onRenderSuccess in PageCanvas<commit_after>import React from 'react';
import { mount } from 'enzyme';

import { pdfjs } from '../entry.jest';

import { PageCanvasInternal as PageCanvas } from './PageCanvas';

import failingPage from '../../__mocks__/_failing_page';

import {
  loadPDF, makeAsyncCallback, muteConsole, restoreConsole,
} from '../../test-utils';

const pdfFile = loadPDF('./__mocks__/_pdf.pdf');

/* eslint-disable comma-dangle */

describe('PageCanvas', () => {
  // Loaded page
  let page;

  beforeAll(async () => {
    const pdf = await pdfjs.getDocument({ data: pdfFile.arrayBuffer }).promise;

    page = await pdf.getPage(1);
  });

  describe('loading', () => {
    it('renders a page and calls onRenderSuccess callback properly', async () => {
      const { func: onRenderSuccess, promise: onRenderSuccessPromise } = makeAsyncCallback();

      const pageWithRendererMocked = {
        ...page,
        getAnnotations: () => {},
        getTextContent: () => {},
        getViewport: () => ({
          width: 0,
          height: 0,
        }),
        render: () => ({
          promise: new Promise(resolve => resolve()),
        }),
      };

      mount(
        <PageCanvas
          onRenderSuccess={onRenderSuccess}
          page={pageWithRendererMocked}
        />
      );

      expect.assertions(1);

      await expect(onRenderSuccessPromise).resolves.toMatchObject({});
    });

    it('calls onRenderError when failed to render canvas', async () => {
      const {
        func: onRenderError, promise: onRenderErrorPromise
      } = makeAsyncCallback();

      muteConsole();

      mount(
        <PageCanvas
          onRenderError={onRenderError}
          page={failingPage}
        />
      );

      expect.assertions(1);

      await expect(onRenderErrorPromise).resolves.toBeInstanceOf(Error);

      restoreConsole();
    });
  });
});

{'fraction_non_alphanumeric': 0.14259862468331524, 'fraction_numerical': 0.002171552660152009, 'mean_word_length': 2.675531914893617, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5903453', 'n_tokens_mistral': 786, 'n_tokens_neox': 766, 'n_words': 168}