-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip, adding getByLgId * getError * add comments * wip, starting findBy * test passing * wip, importing from testing-lib-dom * delete test harness from packages * add back test-harness * everything is broken * what did I change to make this work? * clean up * add another test for findbylgid * delete v1 of test harness * remove more of v1 test harness * remove comments * update yarn * remove line * rename to test-harnesses * rename testid.ts to lgid.ts * update export * add description * add queryByLgId * add changesets * wip * wip - added tests for textinput * adds more test * more tests * add getByQuerySelector util * add another test * some more tests * add getByQuerySelector util * wip text area * textArea tests * toggle tests * update text input tests * cleaning up tests * restructure files * clean up comments * more clean up * icon changeset * LGIdProps => LgIdProps * lib changeset * add changeset for inputs * started READMEs * add isOptional * cs for test-harnesses * fix cs * remove ts-expect-error * wip readme * toggle readme * wip, async tests * update tests * fix build error? * testing * rename dir * testing * fix icon * fix changeset * rename findByQuerySelector to queryByQuerySelector * rename inputValue to getInputValue * fix failing tests * remove dom tests * remove dup tests * update toggle readme * text input README * fix README * update READMEs * test * add lgid to `label` and `description`, move `isOptional` to `test-harnessess` * update changelogs * fix test-harnesses version and changeset * include ticket * update tests * add constants for ids * more ids * rename test utils * update READMEs * add more test ids * update constants * remove src * LG-4129: Select test harness (#2275) * wip select test harnesses * wip, adding tests * adding more tests * adding more tests * comment * adds more tests * more tests * update utils tests * wip, tests * select specs * move popover data-lgid * update types * remove folder * add select const * add more ids * readme * update tests * lint * is this it? * update changesets * changesets * caret, readmes * update constants * update changelogs * typography changeset * text input and text area combine utils * update textInput, textArea, and Toggle utils * fix build errors * update getLGSelectTestUtils type * add JSDoc to renderAsyncTest * update util names * remove act from toggle test * queryByQuerySelector -> queryBySelector * fix build error * update LgIdProps type * update select specs * fix test? * small updates * checkbox test utils * with changeset * make changeset the same * typo * solve another problem * update changelog * with Adams feedback * and update the readme * run fix * with button too * with yarn fix * try again r17 * update table tests * with return types * attempt to fix things * change log * responding to PR feedback * tests and docs * add type test * fix tests * compat * a few more tests * responding to PR feedback --------- Co-authored-by: Shaneeza <[email protected]>
- Loading branch information
Showing
26 changed files
with
736 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@leafygreen-ui/table': patch | ||
--- | ||
|
||
Updates internal test suite |
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,10 @@ | ||
--- | ||
'@leafygreen-ui/button': minor | ||
--- | ||
|
||
|
||
- Exports `getTestUtils`, a util to reliably interact with `LG Button` in a product test suite. For more details, check out the [README](https://github.com/mongodb/leafygreen-ui/tree/main/packages/button#test-harnesses) | ||
- Exports the constant, `LGIDS_BUTTON`, which stores `data-lgid` values. | ||
|
||
|
||
|
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,8 @@ | ||
--- | ||
'@leafygreen-ui/checkbox': minor | ||
--- | ||
|
||
- Exports `getTestUtils`, a util to reliably interact with `LG Checkbox` in a product test suite. For more details, check out the [README](https://github.com/mongodb/leafygreen-ui/tree/main/packages/checkbox#test-harnesses) | ||
- Exports the constant, `LGIDS_CHECKBOX`, which stores `data-lgid` values. | ||
- Leverages the `'aria-label'` prop when passed | ||
|
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
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,5 @@ | ||
const LGID_ROOT = 'lg-button'; | ||
|
||
export const LGIDS_BUTTON = { | ||
root: LGID_ROOT, | ||
} as const; |
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,110 @@ | ||
import React from 'react'; | ||
import { renderAsyncTest } from '@lg-tools/test-harnesses'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import Button from '..'; | ||
|
||
import { getTestUtils } from './getTestUtils'; | ||
|
||
const renderButtonAsync = () => | ||
renderAsyncTest(<Button>Click me</Button>, render); | ||
|
||
function renderButton(props = {}) { | ||
render(<Button {...props}>Click me</Button>); | ||
} | ||
|
||
function renderMultipleToggles() { | ||
render( | ||
<> | ||
<Button data-lgid="lg-Button-1">Click me</Button> | ||
<Button data-lgid="lg-Button-2" disabled> | ||
Click me{' '} | ||
</Button> | ||
</>, | ||
); | ||
} | ||
|
||
describe('packages/button/getTestUtils', () => { | ||
describe('renders properly', () => { | ||
test('throws error if LG Button is not found', () => { | ||
render(<Button>Click me</Button>); | ||
|
||
try { | ||
const _utils = getTestUtils(); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error); | ||
expect(error).toHaveProperty( | ||
'message', | ||
expect.stringMatching( | ||
/Unable to find an element by: \[data-lgid="lg-button"\]/, | ||
), | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('single button', () => { | ||
test('getButton', () => { | ||
renderButton(); | ||
const { getButton } = getTestUtils(); | ||
|
||
expect(getButton()).toBeInTheDocument(); | ||
}); | ||
|
||
describe('isDisabled', () => { | ||
test('to be false', () => { | ||
renderButton(); | ||
const { isDisabled } = getTestUtils(); | ||
|
||
expect(isDisabled()).toBe(false); | ||
}); | ||
|
||
test('to be true', () => { | ||
renderButton({ disabled: true }); | ||
const { isDisabled } = getTestUtils(); | ||
|
||
expect(isDisabled()).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('multiple toggles', () => { | ||
test('getButton', () => { | ||
renderMultipleToggles(); | ||
const utilsOne = getTestUtils('lg-Button-1'); | ||
const utilsTwo = getTestUtils('lg-Button-2'); | ||
|
||
expect(utilsOne.getButton()).toBeInTheDocument(); | ||
expect(utilsTwo.getButton()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('async component', () => { | ||
test('find LG Button after awaiting an async component', async () => { | ||
const { openButton, findByTestId, asyncTestComponentId } = | ||
renderButtonAsync(); | ||
|
||
userEvent.click(openButton); | ||
|
||
const asyncComponent = await findByTestId(asyncTestComponentId); | ||
expect(asyncComponent).toBeInTheDocument(); | ||
|
||
// After awaiting asyncComponent, look for button | ||
const { getButton } = getTestUtils(); | ||
expect(getButton()).toBeInTheDocument(); | ||
}); | ||
|
||
test('find LG Button after awaiting getTestUtils', async () => { | ||
const { openButton } = renderButtonAsync(); | ||
|
||
userEvent.click(openButton); | ||
|
||
// awaiting getTestUtils | ||
await waitFor(() => { | ||
const { getButton } = getTestUtils(); | ||
expect(getButton()).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import { getByLgId } from '@lg-tools/test-harnesses'; | ||
|
||
import { LGIDS_BUTTON } from '../constants'; | ||
|
||
import { GetTestUtilsReturnType } from './getTestUtils.types'; | ||
|
||
export const getTestUtils = <T extends HTMLElement = HTMLElement>( | ||
lgId: string = LGIDS_BUTTON.root, | ||
): GetTestUtilsReturnType<T> => { | ||
/** | ||
* Queries the DOM for the element using the `data-lgid` data attribute. | ||
* Will throw if no element is found. | ||
*/ | ||
const element: T = getByLgId!(lgId); | ||
|
||
/** | ||
* Returns the disabled attribute on the input. | ||
*/ | ||
const isButtonDisabled = () => { | ||
return element.getAttribute('aria-disabled') === 'true'; | ||
}; | ||
|
||
return { | ||
getButton: () => element, | ||
isDisabled: () => isButtonDisabled(), | ||
}; | ||
}; |
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,6 @@ | ||
import { FormUtils } from '@lg-tools/test-harnesses'; | ||
|
||
export interface GetTestUtilsReturnType<T extends HTMLElement> { | ||
getButton: () => T; | ||
isDisabled: FormUtils['isDisabled']; | ||
} |
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 @@ | ||
export { getTestUtils } from './getTestUtils'; |
Oops, something went wrong.