Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mock-doc): dispatch blur and focus events #3449

Merged

Conversation

marlon-ionic
Copy link
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Unit tests (npm test) were run locally and passed
  • E2E Tests (npm run test.karma.prod) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

For mock-doc, blur() and focus() methods will now dispatch an event. Created MockFocusEvent which extends a new MockUIEvent, which extends the existing MockEvent.

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The blur and focus methods are empty.

What is the new behavior?

The methods now dispatch an event (similar to how click() works) via theMockFocusEvent class with a type property of 'blur' or 'focus'

Does this introduce a breaking change?

  • Yes
  • No

Testing

Added tests for verify new MockFocusEvent instantiation

Other information

@marlon-ionic marlon-ionic requested a review from a team July 1, 2022 19:41
Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few questions and comments after reading through

src/mock-doc/event.ts Outdated Show resolved Hide resolved
export class MockFocusEvent extends MockUIEvent {
relatedTarget: EventTarget | null = null;

constructor(type: string, focusEventInitDic?: FocusEventInit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not crucial, but could we type type here as "blur" | "focus" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just waiting on this change, and then it looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry I missed that one! Just committed

}).toThrow();
});

it('FocusEvent(type)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for completion's sake, what would you think about parameterizing this test across "blur", "focus"? something like this perhaps:

Suggested change
it('FocusEvent(type)', () => {
it.each(["blur", "focus"])('creates a %s-type MockFocusEvent', (focusType) => {

const eventInitDict = {
bubbles: true,
composed: true,
relatedTarget: null as EventTarget | null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to have a test where we pass a legit value through for this field, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by legit value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry should have been more explicit! just something that matches the EventTarget interface — not a super essential test though!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked into this and it doesn't look like any of the Mock elements (MockInputElement, etc) inherit from EventTarget currently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok no worries, let's leave it as-is then

export class MockFocusEvent extends MockUIEvent {
relatedTarget: EventTarget | null = null;

constructor(type: string, focusEventInitDic?: FocusEventInit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just waiting on this change, and then it looks good!

Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@rwaskiewicz
Copy link
Contributor

Going to merge this as an admin - "Tech Debt Burndown / Download error files and report (pull_request)" is failing (we'll fix this next sprint) for external contributors, but the report itself is being generated/reporting no new unused exports/strict null check violations

@rwaskiewicz rwaskiewicz merged commit 15520b7 into ionic-team:main Jul 18, 2022
@rwaskiewicz rwaskiewicz added the Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants