<commit_before>import * as React from 'react';
import { parseISO } from 'date-fns';
import { createClientRender, createMount, fireEvent, screen } from 'test/utils';
import { queryHelpers, Matcher, MatcherOptions } from '@testing-library/react/pure';
import { TransitionProps } from '@material-ui/core/transitions';
import AdapterDateFns from '@material-ui/lab/AdapterDateFns';
import LocalizationProvider from '@material-ui/lab/LocalizationProvider';

// TODO make possible to pass here any utils using cli
/**
 * Wrapper around `@date-io/date-fns` that resolves https://github.com/dmtrKovalenko/date-io/issues/479.
 * We're not using `adapter.date` in the implementation which means the implementation is safe.
 * But we do use it in tests where usage of ISO dates without timezone is problematic
 */
export class AdapterClassToUse extends AdapterDateFns {
  date(value?: any): Date {
    if (typeof value === 'string') {
      return parseISO(value);
    }
    return super.date(value);
  }
}
export const adapterToUse = new AdapterClassToUse();

export const FakeTransitionComponent = React.forwardRef<HTMLDivElement, TransitionProps>(
  function FakeTransitionComponent({ children }, ref) {
    // set tabIndex in case it is used as a child of <TrapFocus />
    return (
      <div ref={ref} tabIndex={-1}>
        {children}
      </div>
    );
  },
);

interface PickerRenderOptions {
  // object for date-fns, string for other adapters
  locale?: string | object;
}

export function createPickerMount(options: { strict?: boolean } = {}) {
  const mount = createMount(options);

  return (node: React.ReactNode) =>
    mount(<LocalizationProvider dateAdapter={AdapterClassToUse}>{node}</LocalizationProvider>);
}

export function createPickerRender({
  locale,
  ...renderOptions
}: PickerRenderOptions & import('test/utils').RenderOptions = {}) {
  const clientRender = createClientRender(renderOptions);

  return (node: React.ReactNode) =>
    clientRender(
      <LocalizationProvider locale={locale} dateAdapter={AdapterClassToUse}>
        {node}
      </LocalizationProvider>,
    );
}

export const queryByMuiTest = queryHelpers.queryByAttribute.bind(null, 'data-mui-test');
export const queryAllByMuiTest = queryHelpers.queryAllByAttribute.bind(null, 'data-mui-test');

export function getAllByMuiTest(
  id: Matcher,
  container: HTMLElement = document.body,
  options?: MatcherOptions,
): Element[] {
  const els = queryAllByMuiTest(container, id, options);
  if (!els.length) {
    throw queryHelpers.getElementError(
      `Unable to find an element by: [data-mui-test="${id}"]`,
      container,
    );
  }
  return els;
}

export function getByMuiTest(...args: Parameters<typeof getAllByMuiTest>): Element {<commit_msg>[test] setProps from createPickerRender should set props on the rendered element (#26405)<commit_after>import * as React from 'react';
import { parseISO } from 'date-fns';
import { createClientRender, createMount, fireEvent, screen } from 'test/utils';
import { queryHelpers, Matcher, MatcherOptions } from '@testing-library/react/pure';
import { TransitionProps } from '@material-ui/core/transitions';
import AdapterDateFns from '@material-ui/lab/AdapterDateFns';
import LocalizationProvider from '@material-ui/lab/LocalizationProvider';

// TODO make possible to pass here any utils using cli
/**
 * Wrapper around `@date-io/date-fns` that resolves https://github.com/dmtrKovalenko/date-io/issues/479.
 * We're not using `adapter.date` in the implementation which means the implementation is safe.
 * But we do use it in tests where usage of ISO dates without timezone is problematic
 */
export class AdapterClassToUse extends AdapterDateFns {
  date(value?: any): Date {
    if (typeof value === 'string') {
      return parseISO(value);
    }
    return super.date(value);
  }
}
export const adapterToUse = new AdapterClassToUse();

export const FakeTransitionComponent = React.forwardRef<HTMLDivElement, TransitionProps>(
  function FakeTransitionComponent({ children }, ref) {
    // set tabIndex in case it is used as a child of <TrapFocus />
    return (
      <div ref={ref} tabIndex={-1}>
        {children}
      </div>
    );
  },
);

interface PickerRenderOptions {
  // object for date-fns, string for other adapters
  locale?: string | object;
}

export function createPickerMount(options: { strict?: boolean } = {}) {
  const mount = createMount(options);

  return (node: React.ReactNode) =>
    mount(<LocalizationProvider dateAdapter={AdapterClassToUse}>{node}</LocalizationProvider>);
}

export function createPickerRender({
  locale,
  ...renderOptions
}: PickerRenderOptions & import('test/utils').RenderOptions = {}) {
  const clientRender = createClientRender(renderOptions);

  function Wrapper({ children }: { children?: React.ReactNode }) {
    return (
      <LocalizationProvider locale={locale} dateAdapter={AdapterClassToUse}>
        {children}
      </LocalizationProvider>
    );
  }

  return (node: React.ReactElement) => clientRender(node, { wrapper: Wrapper });
}

export const queryByMuiTest = queryHelpers.queryByAttribute.bind(null, 'data-mui-test');
export const queryAllByMuiTest = queryHelpers.queryAllByAttribute.bind(null, 'data-mui-test');

export function getAllByMuiTest(
  id: Matcher,
  container: HTMLElement = document.body,
  options?: MatcherOptions,
): Element[] {
  const els = queryAllByMuiTest(container, id, options);
  if (!els.length) {
    throw queryHelpers.getElementError(
      `Unable to find an element by: [data-mui-test="${id}"]`,
      container,
    );
  }
  return els;
}

export function getByMuiTest(...args: Parameters<typeof getAllByMuiTest>): Element {
{'fraction_non_alphanumeric': 0.11937929818374185, 'fraction_numerical': 0.0022923646623170518, 'mean_word_length': 4.474903474903475, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '530169', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1653, 'n_words': 453}