Skip to content

Commit

Permalink
color picker testids fix (#614)
Browse files Browse the repository at this point in the history
* fix testids and tests
  • Loading branch information
laviomri authored Mar 31, 2022
1 parent 766f144 commit fa100e4
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/interactions-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
24 changes: 15 additions & 9 deletions src/components/ColorPicker/__tests__/ColorPicker.interactions.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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));
}
Loading

0 comments on commit fa100e4

Please sign in to comment.