How to use the @testing-library/react.getByText function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awslabs / aws-api-gateway-developer-portal / dev-portal / src / pages / Admin / Accounts / __tests__ / AdminAccounts.jsx View on Github external
it('orders accounts by date promoted', async () => {
    AccountService.fetchAdminAccounts = jest
      .fn()
      .mockResolvedValueOnce(MOCK_ADMINS)

    const page = renderPage()
    await accountsTestUtils.waitForAccountsToLoad(page)

    // Order ascending
    const table = page.getByTestId(AccountsTable.ACCOUNTS_TABLE_TESTID)
    const dateRegisteredHeader = rtl.getByText(table, 'Date promoted')
    rtl.fireEvent.click(dateRegisteredHeader)

    // Check that first page is correct
    _(MOCK_ADMINS)
      .orderBy(['DatePromoted'], ['asc'])
      .take(AccountsTable.DEFAULT_PAGE_SIZE)
      .forEach(({ EmailAddress }) =>
        accountsTestUtils.expectEmailIn(EmailAddress, table),
      )
  })
github syndesisio / syndesis / app / ui-react / packages / ui / __tests__ / Customization / ExtensionDetail.spec.tsx View on Github external
// need to set extensionUses to zero so that the delete button is enabled
    const comp = (
      
        
      
    );
    const { getAllByRole, getByText, queryByRole } = render(comp);
    const deleteButton = getByText(deleteLabel);
    expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled

    // click the delete button so that the delete confirmation dialog opens
    fireEvent.click(deleteButton);

    // click the confirmation dialog cancel button and make sure dialog disappears
    const dialog = getAllByRole('dialog')[0];
    fireEvent.click(getDialogButton(dialog, cancelLabel));
    await wait(() => expect(queryByRole('dialog')).toBeNull());
  });
});
github syndesisio / syndesis / app / ui-react / packages / ui / __tests__ / Customization / ExtensionListItem.spec.tsx View on Github external
// need to set extensionUses to zero so that the delete button is enabled
    const comp = (
      
        
      
    );
    const { getAllByRole, getByText, queryByRole } = render(comp);
    const deleteButton = getByText(deleteText);
    expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled

    // click the delete button so that the delete confirmation dialog opens
    fireEvent.click(deleteButton);

    // click the confirmation dialog cancel button and make sure dialog disappears
    const dialog = getAllByRole('dialog')[0];
    fireEvent.click(getDialogButton(dialog, cancelText));
    await wait(() => expect(queryByRole('dialog')).toBeNull());
  });
});
github Synerise / synerise-design / packages / components / tags / src / __specs__ / Tags.spec.tsx View on Github external
addButtonLabel: ADD_TAG_BUTTON,
          searchPlaceholder: SEARCH_PLACEHOLDER,
        }}
        addable
        creatable
      />
    );

    // ACT
    fireEvent.click(getByText(ADD_TAG_BUTTON));
    fireEvent.change(getByPlaceholderText(SEARCH_PLACEHOLDER), { target: { value: tagOne.name.slice(0, -1) } });
    fireEvent.click(getByText(CREATE_TAG_BUTTON));

    // ASSERT
    const dropdown = getByTestId(DROPDOWN_TESTID);
    const foundTag = globalGetByText(dropdown, tagOne.name);

    expect(onCreate).toHaveBeenCalled();
    expect(foundTag).toBeTruthy();
  });
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / pages / Admin / Accounts / __tests__ / RegisteredAccounts.jsx View on Github external
it('promotes an account', async () => {
    const targetAccountEmail = '2@example.com'
    const targetAccountUserId = 'userId2'

    AccountService.fetchRegisteredAccounts = jest
      .fn()
      .mockResolvedValueOnce(MOCK_ACCOUNTS)
    AccountService.promoteAccountByUserId = jest
      .fn()
      .mockResolvedValueOnce(undefined)

    const page = renderPage()
    await accountsTestUtils.waitForAccountsToLoad(page)
    const table = page.getByTestId('accountsTable')
    const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
    const promoteButton = page.getByText('Promote to Admin')

    expect(promoteButton.disabled === true)
    rtl.fireEvent.click(targetAccountEmailCell)
    expect(promoteButton.disabled === false)
    rtl.fireEvent.click(promoteButton)

    const modal = rtl.getByText(document, 'Confirm promotion').closest('.modal')
    const confirmPromoteButton = rtl.getByText(modal, 'Promote')
    rtl.getByText(modal, targetAccountEmail)
    rtl.fireEvent.click(confirmPromoteButton)

    await accountsTestUtils.waitForAccountsToLoad(page)
    expect(rtl.queryByText(document, 'Confirm promotion')).toBeNull()
    expect(AccountService.promoteAccountByUserId.mock.calls).toHaveLength(1)
    expect(AccountService.promoteAccountByUserId.mock.calls[0][0]).toEqual(
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / pages / Admin / Accounts / __tests__ / RegisteredAccounts.jsx View on Github external
AccountService.fetchRegisteredAccounts = jest
      .fn()
      .mockResolvedValueOnce(MOCK_ACCOUNTS)
    AccountService.deleteAccountByUserId = jest
      .fn()
      .mockImplementation(() => Promise.reject(new Error(errorMessage)))

    const page = renderPage()
    await accountsTestUtils.waitForAccountsToLoad(page)
    const table = page.getByTestId('accountsTable')
    const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
    const deleteButton = page.getByText('Delete')
    rtl.fireEvent.click(targetAccountEmailCell)
    rtl.fireEvent.click(deleteButton)

    const modal = rtl.getByText(document, 'Confirm deletion').closest('.modal')
    const confirmDeleteButton = rtl.getByText(modal, 'Delete')
    rtl.getByText(modal, targetAccountEmail)
    rtl.fireEvent.click(confirmDeleteButton)

    await accountsTestUtils.waitForAccountsToLoad(page)
    await rtl.wait(() =>
      expect(page.getByText(/Failed to delete account/)).toBeInTheDocument(),
    )
    expect(rtl.getByText(table, targetAccountEmail)).toBeInTheDocument()
  })
})
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / pages / Admin / Accounts / __tests__ / RegisteredAccounts.jsx View on Github external
const table = page.getByTestId('accountsTable')
    const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
    const deleteButton = page.getByText('Delete')
    rtl.fireEvent.click(targetAccountEmailCell)
    rtl.fireEvent.click(deleteButton)

    const modal = rtl.getByText(document, 'Confirm deletion').closest('.modal')
    const confirmDeleteButton = rtl.getByText(modal, 'Delete')
    rtl.getByText(modal, targetAccountEmail)
    rtl.fireEvent.click(confirmDeleteButton)

    await accountsTestUtils.waitForAccountsToLoad(page)
    await rtl.wait(() =>
      expect(page.getByText(/Failed to delete account/)).toBeInTheDocument(),
    )
    expect(rtl.getByText(table, targetAccountEmail)).toBeInTheDocument()
  })
})
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / pages / Admin / Accounts / __tests__ / PendingInvites.jsx View on Github external
const createModal = await rtl.waitForElement(() =>
      rtl.getByText(document, 'Create invite').closest('.modal'),
    )
github openfun / marsha / src / frontend / components / DashboardTimedTextPane / index.spec.tsx View on Github external
id: '144',
        is_ready_to_show: true,
        language: 'fr',
        mode: timedTextMode.CLOSED_CAPTIONING,
        upload_state: uploadState.READY,
        url: 'https://example.com/ttt/144',
        video: '43',
      },
    ]);

    render(wrapInIntlProvider(wrapInRouter()));

    const closedCaptions = await screen.findByText('Closed captions');
    getByTextInContainer(closedCaptions.parentElement!, 'French');
    const subtitles = screen.getByText('Subtitles');
    getByTextInContainer(subtitles.parentElement!, 'English');
    screen.getByText('Transcripts');
  });