-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Interaction tests * Interaction tests * Interaction tests * Interaction tests - test failure * Interaction tests
- Loading branch information
1 parent
468f3fd
commit caaf9b4
Showing
12 changed files
with
25,416 additions
and
24,729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { within, userEvent } from "@storybook/testing-library"; | ||
import { getTestId, ELEMENT_TYPES as types } from "../utils/test-utils"; | ||
|
||
export const ELEMENT_TYPES = types; | ||
|
||
function getWithin(canvasOrValidTestElement) { | ||
if (canvasOrValidTestElement.getByRole) return canvasOrValidTestElement; | ||
return within(canvasOrValidTestElement); | ||
} | ||
|
||
export const testFunctionWrapper = testFunc => { | ||
return async ({ canvasElement }) => { | ||
// Starts querying the component from its root element | ||
const canvas = getWithin(canvasElement); | ||
return testFunc(canvas); | ||
}; | ||
}; | ||
|
||
export const getByTestId = (rootElement, elementType, id = "") => { | ||
const dataTestId = getTestId(elementType, id); | ||
return getWithin(rootElement).getByTestId(dataTestId); | ||
}; | ||
|
||
export const getByText = (rootElement, text) => { | ||
return getWithin(rootElement).getByText(text); | ||
}; | ||
|
||
export const getByPlaceholderText = (rootElement, text) => { | ||
return getWithin(rootElement).getByPlaceholderText(text); | ||
}; | ||
|
||
export const getByClassName = className => { | ||
return document.getElementsByClassName(className)[0]; | ||
}; | ||
|
||
export const getByRole = (rootElement, role) => { | ||
return getWithin(rootElement).getByRole(role); | ||
}; | ||
|
||
export const getByLabelText = (rootElement, text) => { | ||
return getWithin(rootElement).getByLabelText(text); | ||
}; | ||
|
||
export const clickElement = element => { | ||
return userEvent.click(element); | ||
}; | ||
|
||
export const typeText = async (element, text, waitForDebounceMs = 250) => { | ||
let promise = userEvent.type(element, text, { | ||
delay: 50 | ||
}); | ||
const result = await promise; | ||
await delay(waitForDebounceMs); | ||
return result; | ||
}; | ||
|
||
function delay(timeout) { | ||
return new Promise(resolve => { | ||
if (!timeout) return resolve(); | ||
setTimeout(resolve, timeout); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from "@storybook/jest"; | ||
import { | ||
ELEMENT_TYPES, | ||
getByLabelText, | ||
getByTestId, | ||
getByText, | ||
clickElement, | ||
testFunctionWrapper, | ||
typeText | ||
} from "../../../__tests__/interactions-helper"; | ||
|
||
export const onSelectClearsFilterTest = testFunctionWrapper(async canvas => { | ||
const comboboxElement = await getByTestId(canvas, ELEMENT_TYPES.COMBOBOX); | ||
const filterInput = await getByLabelText(comboboxElement, "Search for content"); | ||
await typeText(filterInput, "Option"); | ||
const optionToClick = getByText(comboboxElement, "Option 1"); | ||
await clickElement(optionToClick); | ||
expect(filterInput).toHaveValue(""); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.