Skip to content

Commit

Permalink
Merge branch 'master' into timdeschryver-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gpx authored Feb 17, 2020
2 parents 02789f9 + f7e1640 commit 6b8cc8b
Show file tree
Hide file tree
Showing 7 changed files with 3,609 additions and 1,492 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@
"code",
"test"
]
},
{
"login": "jsmapr1",
"name": "Joe Morgan",
"avatar_url": "https://avatars1.githubusercontent.com/u/2388943?v=4",
"profile": "http://thejoemorgan.com",
"contributions": [
"code"
]
}
],
"commitConvention": "none",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ Thanks goes to these wonderful people
<td align="center"><a href="https://lyamkin.com"><img src="https://avatars2.githubusercontent.com/u/3854930?v=4" width="100px;" alt=""/><br /><sub><b>Ilya Lyamkin</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=ilyamkin" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=ilyamkin" title="Tests">⚠️</a></td>
<td align="center"><a href="http://todofullstack.com"><img src="https://avatars2.githubusercontent.com/u/4474353?v=4" width="100px;" alt=""/><br /><sub><b>Kenneth Luján Rosas</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=klujanrosas" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=klujanrosas" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center"><a href="http://thejoemorgan.com"><img src="https://avatars1.githubusercontent.com/u/2388943?v=4" width="100px;" alt=""/><br /><sub><b>Joe Morgan</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=jsmapr1" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
Expand Down
90 changes: 88 additions & 2 deletions __tests__/react/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,92 @@ describe("userEvent.click", () => {
expect(b).toHaveFocus();
});

it("should not blur when mousedown prevents default", () => {
let events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const commonEvents = {
onBlur: eventsHandler,
onMouseOver: eventsHandler,
onMouseMove: eventsHandler,
onMouseDown: eventsHandler,
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler,
onChange: eventsHandler
};

const { getByTestId } = render(
<React.Fragment>
<input data-testid="A" {...commonEvents} />
<input
data-testid="B"
{...commonEvents}
onMouseDown={e => {
e.preventDefault();
eventsHandler(e);
}}
/>
<input data-testid="C" {...commonEvents} />
</React.Fragment>
);

const a = getByTestId("A");
const b = getByTestId("B");
const c = getByTestId("C");

expect(a).not.toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

userEvent.click(a);
expect(a).toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

expect(events).toEqual([
"mouseover",
"mousemove",
"mousedown",
"focus",
"mouseup",
"click"
]);

events = [];

userEvent.click(b);
expect(a).toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

expect(events).toEqual([
"mousemove",
"mouseover",
"mousemove",
"mousedown",
"mouseup",
"click"
]);

events = [];

userEvent.click(c);
expect(a).not.toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).toHaveFocus();

expect(events).toEqual([
"mousemove",
"mouseover",
"mousemove",
"mousedown",
"blur",
"focus",
"mouseup",
"click"
]);
});

it("does not lose focus when click updates focus", () => {
const FocusComponent = () => {
const inputRef = React.useRef();
Expand Down Expand Up @@ -328,9 +414,9 @@ describe("userEvent.click", () => {
const { getByTestId } = render(
React.createElement(type, {
"data-testid": "element",
onMouseDown: (evt) => {
onMouseDown: evt => {
evt.preventDefault();
},
}
})
);

Expand Down
95 changes: 95 additions & 0 deletions __tests__/react/dblclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,99 @@ describe("userEvent.dblClick", () => {
"click"
]);
});

it("should not blur when mousedown prevents default", () => {
let events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const commonEvents = {
onBlur: eventsHandler,
onMouseOver: eventsHandler,
onMouseMove: eventsHandler,
onMouseDown: eventsHandler,
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler,
onChange: eventsHandler
};

const { getByTestId } = render(
<React.Fragment>
<input data-testid="A" {...commonEvents} />
<input
data-testid="B"
{...commonEvents}
onMouseDown={e => {
e.preventDefault();
eventsHandler(e);
}}
/>
<input data-testid="C" {...commonEvents} />
</React.Fragment>
);

const a = getByTestId("A");
const b = getByTestId("B");
const c = getByTestId("C");

expect(a).not.toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

userEvent.dblClick(a);
expect(a).toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

expect(events).toEqual([
"mouseover",
"mousemove",
"mousedown",
"focus",
"mouseup",
"click",
"mousedown",
"mouseup",
"click"
]);

events = [];

userEvent.dblClick(b);
expect(a).toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).not.toHaveFocus();

expect(events).toEqual([
"mousemove",
"mouseover",
"mousemove",
"mousedown",
"mouseup",
"click",
"mousedown",
"mouseup",
"click"
]);

events = [];

userEvent.dblClick(c);
expect(a).not.toHaveFocus();
expect(b).not.toHaveFocus();
expect(c).toHaveFocus();

expect(events).toEqual([
"mousemove",
"mouseover",
"mousemove",
"mousedown",
"blur",
"focus",
"mouseup",
"click",
"mousedown",
"mouseup",
"click"
]);
});
});
Loading

0 comments on commit 6b8cc8b

Please sign in to comment.