Skip to content

Commit

Permalink
Merge branch 'master' into users/nirice/typedoc-api-extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasrice authored Jan 21, 2020
2 parents cee4103 + 460d686 commit 94362ec
Show file tree
Hide file tree
Showing 23 changed files with 929 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ describe("auto suggest", (): void => {
expect(rendered.state("isMenuOpen")).toBe(false);
});

test("value prop is applied", (): void => {
const rendered: any = mount(
<AutoSuggest listboxId="listboxId" value="test value">
{itemA}
{itemB}
{itemC}
</AutoSuggest>
);

expect(rendered.state("value")).toBe("test value");
});

test("input region accessibility attributes are set correctly (autocomplete='both', )", (): void => {
const rendered: any = mount(
<AutoSuggest listboxId="listboxId">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class AutoSuggest extends Foundation<
this.props.onValueChange(newValue, isFromSuggestedOption);
}

if (!isNil(this.props.value) || newValue !== this.state.value) {
if (isNil(this.props.value) && newValue !== this.state.value) {
this.toggleMenu(true);
this.setState({
value: newValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,45 @@ describe("viewport positioner", (): void => {
expect(positioner.instance().state.disabled).toBe(true);
});

test("initial state function returns correct initial state", (): void => {
const anchorElement: React.RefObject<HTMLDivElement> = React.createRef<
HTMLDivElement
>();

const rendered: any = mount(
<div>
<div ref={anchorElement} />
<ViewportPositioner
viewport={document.firstElementChild as HTMLElement}
anchor={anchorElement}
managedClasses={managedClasses}
/>
</div>
);

const positioner: any = rendered.find("BaseViewportPositioner");
expect(positioner.instance()["generateInitialState"]()).toEqual({
disabled: true,
noObserverMode: false,
xTransformOrigin: "left",
yTransformOrigin: "top",
xTranslate: 0,
yTranslate: 0,
top: null,
right: null,
bottom: null,
left: null,
currentHorizontalPosition: "undefined",
currentVerticalPosition: "undefined",
defaultHorizontalPosition: "undefined",
defaultVerticalPosition: "bottom",
horizontalSelectedPositionWidth: null,
verticalSelectedPositionHeight: null,
initialLayoutComplete: false,
validRefChecksRemaining: 2,
});
});

test("positioning values applied correctly for specified default position - adjacent + top + left", (): void => {
const anchorElement: React.RefObject<HTMLDivElement> = React.createRef<
HTMLDivElement
Expand Down Expand Up @@ -1606,4 +1645,49 @@ describe("viewport positioner", (): void => {
expect(positionerDimension.width).toBe(110);
expect(positionerDimension.height).toBe(110);
});

test("extractElementFromRef function returns element passed in directly", (): void => {
const anchorElement: React.RefObject<HTMLDivElement> = React.createRef<
HTMLDivElement
>();

const rendered: any = mount(
<div>
<div ref={anchorElement} />
<ViewportPositioner
viewport={document.firstElementChild as HTMLElement}
anchor={anchorElement}
managedClasses={managedClasses}
/>
</div>
);

const positioner: any = rendered.find("BaseViewportPositioner");
const testElement: Element = document.createElement("div");
expect(positioner.instance()["extractElementFromRef"](testElement)).toBe(
testElement
);
});

test("extractElementFromRef function returns element passed in as a ref", (): void => {
const anchorElement: React.RefObject<HTMLDivElement> = React.createRef<
HTMLDivElement
>();

const rendered: any = mount(
<div>
<div ref={anchorElement} />
<ViewportPositioner
viewport={document.firstElementChild as HTMLElement}
anchor={anchorElement}
managedClasses={managedClasses}
/>
</div>
);

const positioner: any = rendered.find("BaseViewportPositioner");
expect(positioner.instance()["extractElementFromRef"](anchorElement)).toBe(
anchorElement.current
);
});
});
Loading

0 comments on commit 94362ec

Please sign in to comment.