Skip to content

Commit

Permalink
test-jest-helpers2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Dec 11, 2023
1 parent 5d77096 commit 105670b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 235 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-test-jest-helpers2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export * from './src/enzyme_helpers';
export * from './src/rtl_helpers';
216 changes: 0 additions & 216 deletions packages/kbn-test-jest-helpers2/src/enzyme_helpers.tsx

This file was deleted.

19 changes: 19 additions & 0 deletions packages/kbn-test-jest-helpers2/src/rtl_helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { screen, within } from '@testing-library/react';

export const getButtonGroupInputValue = (testId: string) => () => {
const buttonGroup = screen.getByTestId(testId);
const options = within(buttonGroup).getAllByRole('radio');
const checkedOption = options.find((option) => option.getAttribute('checked') === '');
if (checkedOption == null) {
throw new Error(`No checked option found in button group ${testId}`);
}
return checkedOption.nextSibling;
};
6 changes: 1 addition & 5 deletions packages/kbn-test-jest-helpers2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"**/*.ts",
"**/*.tsx",
],
"kbn_references": [
"@kbn/i18n-react",
"@kbn/axe-config",
"@kbn/shared-ux-router",
],
"kbn_references": [],
"exclude": [
"target/**/*",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { getButtonGroupInputValue } from '@kbn/rtl-eui';
import { getButtonGroupInputValue } from '@kbn/test-jest-helpers2';
import { DataTableToolbar } from './toolbar';
import { DatatableVisualizationState } from '../visualization';
import { FramePublicAPI, VisualizationToolbarProps } from '../../../types';
Expand Down Expand Up @@ -55,16 +55,6 @@ describe('datatable toolbar', () => {
userEvent.click(screen.getByRole('button', { name: /visual options/i }));
};

const getButtonGroupInputValue = (testId: string) => () => {
const buttonGroup = screen.getByTestId(testId);
const options = within(buttonGroup).getAllByRole('radio');
const checkedOption = options.find((option) => option.getAttribute('checked') === '');
if (checkedOption == null) {
throw new Error(`No checked option found in button group ${testId}`);
}
return checkedOption.nextSibling;
};

const selectOptionFromButtonGroup = (testId: string) => (optionName: string | RegExp) => {
const buttonGroup = screen.getByTestId(testId);
const option = within(buttonGroup).getByRole('radio', { name: optionName });
Expand All @@ -81,7 +71,6 @@ describe('datatable toolbar', () => {

return {
...rtlRender,

togglePopover,
getRowHeightValue: getButtonGroupInputValue(ROW_HEIGHT_SETTINGS_TEST_ID),
getRowHeightCustomValue: () => getNumberInput(ROW_HEIGHT_SETTINGS_TEST_ID),
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/lens/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"@kbn/shared-ux-button-toolbar",
"@kbn/cell-actions",
"@kbn/calculate-width-from-char-count",
"@kbn/discover-utils"
"@kbn/discover-utils",
"@kbn/test-jest-helpers2"
],
"exclude": [
"target/**/*"
Expand Down

0 comments on commit 105670b

Please sign in to comment.