diff --git a/src/__tests__/interactions-helper.js b/src/__tests__/interactions-helper.js index 90588d4c6d..1e3e3e87b4 100644 --- a/src/__tests__/interactions-helper.js +++ b/src/__tests__/interactions-helper.js @@ -128,8 +128,8 @@ export const waitForElementVisible = getterFunc => { }); }; -export const keyboardMultipleTimes = async (text, times, options = { delay: 70 }) => { - text = text.repeat(times); +export const keyboardMultipleTimes = async (text, count, options = { delay: 70 }) => { + text = text.repeat(count); await userEvent.keyboard(text, options); }; diff --git a/src/components/ColorPicker/__tests__/ColorPicker.interactions.js b/src/components/ColorPicker/__tests__/ColorPicker.interactions.js index b45e92304d..7222e33408 100644 --- a/src/components/ColorPicker/__tests__/ColorPicker.interactions.js +++ b/src/components/ColorPicker/__tests__/ColorPicker.interactions.js @@ -1,7 +1,13 @@ import { userEvent, within } from "@storybook/testing-library"; import { contentColorsByName } from "../../../utils/colors-vars-map"; -import { interactionSuite, keyboardMultipleTimes, resetFocus } from "../../../__tests__/interactions-helper"; +import { + ELEMENT_TYPES, + interactionSuite, + keyboardMultipleTimes, + resetFocus +} from "../../../__tests__/interactions-helper"; import { expect } from "@storybook/jest"; +import { getTestId } from "../../../utils/test-utils"; async function selectAndResetWithKeyboard(canvas) { await clickOnColor(canvas, contentColorsByName.BRIGHT_GREEN); @@ -63,31 +69,31 @@ export const multiSelectionInteractionSuite = interactionSuite({ }); async function clickOnColor(canvas, color) { - const element = await getColorItem(canvas, color); - const toClick = within(element).getByLabelText(color); + const element = await findColorItem(canvas, color); + const toClick = await within(element).findByLabelText(color); await userEvent.click(toClick); } async function expectColorToBeSelected(canvas, color) { - const element = await getColorItem(canvas, color); + const element = await findColorItem(canvas, color); expect(element).toHaveClass("selected-color"); } async function expectColorToBeNotSelected(canvas, color) { - const element = await getColorItem(canvas, color); + const element = await findColorItem(canvas, color); expect(element).not.toHaveClass("selected-color"); } async function expectColorToBeActive(canvas, color) { - const element = await getColorItem(canvas, color); + const element = await findColorItem(canvas, color); expect(element).toHaveClass("active"); } async function expectColorToBeNotActive(canvas, color) { - const element = await getColorItem(canvas, color); + const element = await findColorItem(canvas, color); expect(element).not.toHaveClass("active"); } -async function getColorItem(canvas, color) { - return await canvas.getByTestId(`color-picker-item-${color}`); +async function findColorItem(canvas, color) { + return await canvas.findByTestId(getTestId(ELEMENT_TYPES.COLOR_PICKER_ITEM, color)); } diff --git a/src/components/ColorPicker/__tests__/__snapshots__/colorPicker.jest.js.snap b/src/components/ColorPicker/__tests__/__snapshots__/colorPicker.jest.js.snap index c7b43ab74b..bf95277ad4 100644 --- a/src/components/ColorPicker/__tests__/__snapshots__/colorPicker.jest.js.snap +++ b/src/components/ColorPicker/__tests__/__snapshots__/colorPicker.jest.js.snap @@ -27,7 +27,7 @@ exports[`renders correctly with empty props 1`] = ` >
  • ); })} diff --git a/src/components/ColorPicker/components/ColorPickerItemComponent/ColorPickerItemComponent.jsx b/src/components/ColorPicker/components/ColorPickerItemComponent/ColorPickerItemComponent.jsx index 98e142ec9c..d2cdad19ef 100644 --- a/src/components/ColorPicker/components/ColorPickerItemComponent/ColorPickerItemComponent.jsx +++ b/src/components/ColorPicker/components/ColorPickerItemComponent/ColorPickerItemComponent.jsx @@ -9,6 +9,7 @@ import Icon from "../../../Icon/Icon"; import Tooltip from "../../../Tooltip/Tooltip"; import Clickable from "../../../Clickable/Clickable"; import { COLOR_SHAPES } from "../../ColorPickerConstants"; +import { getTestId } from "../../../../utils/test-utils"; const ColorPickerItemComponent = ({ color, @@ -63,7 +64,7 @@ const ColorPickerItemComponent = ({ active: isActive, circle: colorShape === COLOR_SHAPES.CIRCLE })} - data-testid={dataTestId} + data-testid={dataTestId || getTestId("color-picker-item", color)} >