@testing-library/react#getByPlaceholderText TypeScript Examples

The following examples show how to use @testing-library/react#getByPlaceholderText. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateNewElement.test.tsx    From legend-studio with Apache License 2.0 6 votes vote down vote up
addRootPackage = (packagePath: string, result: RenderResult): void => {
  fireEvent.click(result.getByTitle('New Element...', { exact: false }));
  const contextMenu = result.getByRole('menu');
  fireEvent.click(getByText(contextMenu, 'New Package...'));
  const modal = result.getByTestId(LEGEND_STUDIO_TEST_ID.NEW_ELEMENT_MODAL);
  const packageInput = getByPlaceholderText(modal, 'Enter a name', {
    exact: false,
  });
  fireEvent.change(packageInput, { target: { value: packagePath } });
  fireEvent.click(getByText(modal, 'Create'));
}
Example #2
Source File: CreateNewElement.test.tsx    From legend-studio with Apache License 2.0 6 votes vote down vote up
createNewElementOnRootPackage = (
  rootPackage: string,
  elementType: PACKAGEABLE_ELEMENT_TYPE,
  result: RenderResult,
  elementName?: string,
): void => {
  const packageExplorer = result.getByTestId(
    LEGEND_STUDIO_TEST_ID.EXPLORER_TREES,
  );
  const rootPackageDiv = getByText(packageExplorer, rootPackage);
  const rightClick = { button: 2 };
  fireEvent.click(rootPackageDiv, rightClick);
  fireEvent.click(
    result.getByText(`New ${toTitleCase(elementType.toLowerCase())}...`),
  );
  const modal = result.getByTestId(LEGEND_STUDIO_TEST_ID.NEW_ELEMENT_MODAL);
  const elementInput = getByPlaceholderText(modal, 'Enter a name', {
    exact: false,
  });
  const inputValue = elementName ?? `${elementType}Test`;
  fireEvent.change(elementInput, { target: { value: inputValue } });
  fireEvent.click(getByText(modal, 'Create'));
  getByText(packageExplorer, inputValue);
}
Example #3
Source File: ServiceRegistrationTest.test.tsx    From legend-studio with Apache License 2.0 4 votes vote down vote up
test(
  integrationTest(
    'Service Editor basic general and registration functionality for projects without versions',
  ),
  async () => {
    const mockedEditorStore = await setup(
      TEST_DATA__DefaultSDLCInfo.project,
      TEST_DATA__DefaultSDLCInfo.workspace,
    );
    const result = new ServiceRegistrationResult(
      'https://legend.org/exec',
      '/myservice',
      'id1',
    );
    MOBX__enableSpyOrMock();
    jest
      .spyOn(
        mockedEditorStore.graphManagerState.graphManager,
        'registerService',
      )
      .mockResolvedValue(result);
    jest
      .spyOn(
        mockedEditorStore.graphManagerState.graphManager,
        'activateService',
      )
      .mockResolvedValue();
    MOBX__disableSpyOrMock();
    await TEST__openElementFromExplorerTree('test::myService', renderResult);
    const editPanelHeader = await waitFor(() =>
      renderResult.getByTestId(LEGEND_STUDIO_TEST_ID.EDIT_PANEL__HEADER_TABS),
    );
    await waitFor(() => getByText(editPanelHeader, 'myService'));
    const editPanel = await waitFor(() =>
      renderResult.getByTestId(LEGEND_STUDIO_TEST_ID.EDIT_PANEL),
    );
    // labels + values
    await waitFor(() => getByText(editPanel, 'URL Pattern'));
    expect(
      await waitFor(() =>
        editPanel.querySelector(`input[value="/example/myTestUrl/{myParam}"]`),
      ),
    ).toBeTruthy();
    await waitFor(() => getByText(editPanel, 'URL Pattern'));
    await waitFor(() => getByText(editPanel, 'myParam'));
    await waitFor(() => getByText(editPanel, 'Documentation'));
    await waitFor(() => getByText(editPanel, 'Auto Activate Updates'));
    await waitFor(() => getByText(editPanel, 'Owners'));
    await waitFor(() => getByText(editPanel, 'owner1'));
    await waitFor(() => getByText(editPanel, 'owner2'));
    // add owner
    const serviceEditorState =
      mockedEditorStore.getCurrentEditorState(ServiceEditorState);
    const service = serviceEditorState.service;
    expect(service.owners).toHaveLength(2);
    fireEvent.click(getByTitle(editPanel, 'Add owner'));
    const ownerInput = await waitFor(() =>
      getByPlaceholderText(editPanel, 'Enter an owner...'),
    );
    fireEvent.change(ownerInput, { target: { value: 'owner3' } });
    fireEvent.click(getByText(editPanel, 'Save'));
    await waitFor(() => getByText(editPanel, 'owner3'));
    expect(service.owners).toHaveLength(3);
    // registration
    fireEvent.click(getByText(editPanel, 'Registration'));
    const registrationEditor = await waitFor(() =>
      renderResult.getByTestId(
        LEGEND_STUDIO_TEST_ID.SERVICE_REGISTRATION_EDITOR,
      ),
    );
    await waitFor(() =>
      getByText(
        registrationEditor,
        'Only valid for Semi Interactive and Prod service types',
      ),
    );
    await waitFor(() => getByText(registrationEditor, 'Execution Server'));
    await waitFor(() => getByText(registrationEditor, 'Service Type'));
    await waitFor(() => getByText(registrationEditor, 'Project Version'));
    // register
    fireEvent.click(getByTitle(registrationEditor, 'Register Service'));
    const actionAlertDialog = await waitFor(() =>
      renderResult.getByRole('dialog'),
    );
    await waitFor(() => getByText(actionAlertDialog, 'Launch Service'));
    getByText(
      actionAlertDialog,
      'Service with patten /myservice registered and activated',
    );
    fireEvent.click(renderResult.getByText('Close'));
    // check no owners check
    service_deleteOwner(serviceEditorState.service, 0);
    service_deleteOwner(serviceEditorState.service, 0);
    service_deleteOwner(serviceEditorState.service, 0);
    fireEvent.click(getByTitle(registrationEditor, 'Register Service'));
    await waitFor(() =>
      renderResult.getByText(
        'Service needs to have at least 2 owners in order to be registered',
      ),
    );
  },
);