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

[7.4-only][LPS-122499, LPS-122448] Remove dom.delegate usages inside frontend-js/* & improve delegate util #531

Closed

Conversation

kresimir-coko
Copy link
Collaborator

@kresimir-coko kresimir-coko commented Nov 23, 2020

Overview

The goal of this PR is two-fold:

  • [LPS-122448] Improve the delegate utility by expanding it's functionality to include delegateTarget and optimize it slightly since we're already touching it
  • [LPS-122499]Replace usages of dom.delegate with the new delegate utility inside the frontend-js module

delegate utility

When I started removing the usages of dom.delegate we noticed the discrepancy between it and the new delegate utility. The new one didn't provide access to the delegateTarget property. So we had to improve it before we could properly replace the old one, because otherwise we'd have to change a lot more than just the name of the utility that gets called. Since we did all this work on the utility we decided to improve it as well by optimizing the conditions and hoisting checks higher to prevent expensive calls being invoked if unnecessary.

delegate usages

This is the first PR under this JIRA issue that passed the CI test, so we decided to combine these with the delegate utility improvements described above so we can instantly see how well they're working together.

Testing

The delegate utility has it's automated tests defined so I used those to test the functionality and added a new test to it with @wincent's help. Outside of that, CI has been proving useful and doing other kinds of tests. I haven't done any manual testing on these files, I tried but couldn't find their usages in a reasonable amount of time.

@liferay-continuous-integration
Copy link
Collaborator

To conserve resources, the PR Tester does not automatically run for every pull.

If your code changes were already tested in another pull, reference that pull in this pull so the test results can be analyzed.

If your pull was never tested, comment "ci:test" to run the PR Tester for this pull.

@kresimir-coko
Copy link
Collaborator Author

ci:test:relevant

@jbalsas
Copy link

jbalsas commented Nov 23, 2020

Hey @kresimir-coko, could you please close the other delegate PRs as you open new ones so it's easy to keep track of which one should be looked at?

I already see 2 again here which makes it hard to understand which one (if any) is the good one right now.

You can always reopen a closed PR, so there's no harm in closing them if you're trying a different approach ;)

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:stable - 9 out of 9 jobs passed

✔️ ci:test:relevant - 22 out of 23 jobs passed in 11 hours 29 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: e4bdd4a188b4ba711563b325b2f26b7f5539e057

Copied in Private Modules Branch:

Branch Name: master-private
Branch GIT ID: 8d22a791300569a6c92e7b9152e6ae1c6bdc863a

ci:test:stable - 9 out of 9 jobs PASSED
9 Successful Jobs:
ci:test:relevant - 21 out of 23 jobs PASSED
21 Successful Jobs:
For more details click here.

This pull contains no unique failures.


Failures in common with acceptance upstream results at f26d0ce:
  1. test-portal-acceptance-pullrequest-batch(master)/semantic-versioning-jdk8/0
    Job Results:

    0 Tests Passed.
    1 Test Failed.

    1. AXIS_VARIABLE=0,label_exp=!master #418739

      Please fix semantic versioning on kresimir-coko/LPS-122449-frontend

           [exec] 		+   method     findByUuid_C(java.lang.String,long,int,int,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     java.util.List
           [exec] 		+   method     findByUuid_C(java.lang.String,long,int,int,com.liferay.portal.kernel.util.OrderByComparator,boolean)
           [exec] 			+   access     abstract
           [exec] 			+   return     java.util.List
           [exec] 		+   method     findByUuid_C_First(java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_C_Last(java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_C_PrevAndNext(long,java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region[]
           [exec] 		+   method     findByUuid_First(java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_Last(java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_PrevAndNext(long,java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region[]
           [exec] 		+   method     removeByUuid(java.lang.String)
           [exec] 			+   access     abstract
           [exec] 			+   return     void
           [exec] 		+   method     removeByUuid_C(java.lang.String,long)
           [exec] 			+   access     abstract
           [exec] 			+   return     void
           [exec] [Baseline Report] Mode: diff (persisted)
           [exec] Semantic versioning is incorrect while checking /opt/dev/projects/github/liferay-portal/portal-kernel/portal-kernel.jar against /opt/dev/projects/github/liferay-portal/.gradle/caches/modules-2/files-2.1/com.liferay.portal/com.liferay.portal.kernel/9.14.0/26ace10317f060c3623376124ed3fa0ae775cdd4/com.liferay.portal.kernel-9.14.0.jar

@kresimir-coko
Copy link
Collaborator Author

@jbalsas alrighty, seems that CI isn't failing here, finally, do we want to freeze this until I add functionality for event.delegateTarget?

@jbalsas
Copy link

jbalsas commented Nov 23, 2020

@jbalsas alrighty, seems that CI isn't failing here, finally, do we want to freeze this until I add functionality for event.delegateTarget?

Yes, let's see how this PR looks with that change for comparison.

@wincent, do you have any concern with #531 (comment)?

@liferay-continuous-integration
Copy link
Collaborator

@kresimir-coko
Copy link
Collaborator Author

ci:test:relevant

@kresimir-coko
Copy link
Collaborator Author

@wincent I've pushed a commit here with a delegateTarget being added to the event object. Hopefully the location where I assign it is re-computing the delegate target every time an event fires. Initially I had it outside the if check that contains the callback. Took me a while to test this, but it worked in a JSP file I tested in.

@wincent
Copy link

wincent commented Nov 23, 2020

@wincent I've pushed a commit here with a delegateTarget being added to the event object. Hopefully the location where I assign it is re-computing the delegate target every time an event fires. Initially I had it outside the if check that contains the callback. Took me a while to test this, but it worked in a JSP file I tested in.

Changes looks ok to me. We have automated tests for this file, so maybe we should update those as well to document this feature and ensure it keeps working.

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:stable - 9 out of 9 jobs passed

✔️ ci:test:relevant - 22 out of 23 jobs passed in 1 hour 47 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: 5f0804dc889f85ea2116065011d903a63988937d

Copied in Private Modules Branch:

Branch Name: master-private
Branch GIT ID: 8d22a791300569a6c92e7b9152e6ae1c6bdc863a

ci:test:stable - 9 out of 9 jobs PASSED
9 Successful Jobs:
ci:test:relevant - 21 out of 23 jobs PASSED
21 Successful Jobs:
For more details click here.

This pull contains no unique failures.


Failures in common with acceptance upstream results at f26d0ce:
  1. test-portal-acceptance-pullrequest-batch(master)/semantic-versioning-jdk8/0
    Job Results:

    0 Tests Passed.
    1 Test Failed.

    1. AXIS_VARIABLE=0,label_exp=!master #418800

      Please fix semantic versioning on kresimir-coko/LPS-122449-frontend

           [exec] 		+   method     findByUuid_C(java.lang.String,long,int,int,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     java.util.List
           [exec] 		+   method     findByUuid_C(java.lang.String,long,int,int,com.liferay.portal.kernel.util.OrderByComparator,boolean)
           [exec] 			+   access     abstract
           [exec] 			+   return     java.util.List
           [exec] 		+   method     findByUuid_C_First(java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_C_Last(java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_C_PrevAndNext(long,java.lang.String,long,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region[]
           [exec] 		+   method     findByUuid_First(java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_Last(java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region
           [exec] 		+   method     findByUuid_PrevAndNext(long,java.lang.String,com.liferay.portal.kernel.util.OrderByComparator)
           [exec] 			+   access     abstract
           [exec] 			+   return     com.liferay.portal.kernel.model.Region[]
           [exec] 		+   method     removeByUuid(java.lang.String)
           [exec] 			+   access     abstract
           [exec] 			+   return     void
           [exec] 		+   method     removeByUuid_C(java.lang.String,long)
           [exec] 			+   access     abstract
           [exec] 			+   return     void
           [exec] [Baseline Report] Mode: diff (persisted)
           [exec] Semantic versioning is incorrect while checking /opt/dev/projects/github/liferay-portal/portal-kernel/portal-kernel.jar against /opt/dev/projects/github/liferay-portal/.gradle/caches/modules-2/files-2.1/com.liferay.portal/com.liferay.portal.kernel/9.14.0/26ace10317f060c3623376124ed3fa0ae775cdd4/com.liferay.portal.kernel-9.14.0.jar

@liferay-continuous-integration
Copy link
Collaborator

@kresimir-coko
Copy link
Collaborator Author

@wincent

so maybe we should update those as well

I've been playing around this for a bit now and I can't figure out how to test if delegateTarget exists on the event object.

  • I investigated the userEvent object, but it just contains utilities to mock event triggers, not event objects (AFAIK).
  • I looked into expect(listener).toHaveBeenCalledWith(event); but since we never define the event object, that doesn't work.
  • I tried defining a new Event() but that isn't the same event as userEvent so that didn't work either.
it('gives access to delegateTarget inside the callback', () => {
	document.body.innerHTML = `<div class="match" data-testid="match">
			<div>
				<div data-testid="most-inner-match"></div>
			</div>
		</div >`;

	const listener = jest.fn();

	const event = new Event('click');

	event.delegateTarget = getByTestId(
		document,
		'most-inner-match'
	).closest('.match');

	delegate(document, 'click', '.match', listener);

	userEvent.click(getByTestId(document, 'most-inner-match'));

	expect(listener).toHaveBeenCalledWith(event);
});

Not sure if I missed the mark by a lot, so a pointer or two would be helpful, I also looked up if we have any tests that contain test but didn't find any, leading me to a conclusion that we don't manually mock events.

@kresimir-coko
Copy link
Collaborator Author

ci:test:relevant

@kresimir-coko
Copy link
Collaborator Author

ci:test:relevant

@kresimir-coko kresimir-coko marked this pull request as ready for review November 24, 2020 12:54
@kresimir-coko kresimir-coko changed the title LPS-122499 Remove dom.delegate usages inside frontend-js/* [LPS-122499, LPS-122448] Remove dom.delegate usages inside frontend-js/* & improve delegate util Nov 24, 2020
@jbalsas
Copy link

jbalsas commented Nov 24, 2020

@kresimir-coko, as we're getting ready for pushing this forward... would you mind:

  • Adding the [7.4-only] prefix to the title to avoid unwanted backports
  • Updating the description so when we forward it something more specific and aligned with our good practices is sent? 😉

@@ -161,4 +161,24 @@ describe('delegate', () => {

expect(listener).not.toHaveBeenCalled();
});

it('gives access to delegateTarget inside the callback', () => {
Copy link

Choose a reason for hiding this comment

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

Nice!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that was mostly Greg, but he wouldn't have gotten there if I didn't ask him about it!

@kresimir-coko kresimir-coko changed the title [LPS-122499, LPS-122448] Remove dom.delegate usages inside frontend-js/* & improve delegate util [7.4-only][LPS-122499, LPS-122448] Remove dom.delegate usages inside frontend-js/* & improve delegate util Nov 24, 2020
@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:stable - 9 out of 9 jobs passed

✔️ ci:test:relevant - 23 out of 23 jobs passed in 2 hours 13 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: cf5f0b9de37165381f866420408e6e7e7e014939

Copied in Private Modules Branch:

Branch Name: master-private
Branch GIT ID: 8d22a791300569a6c92e7b9152e6ae1c6bdc863a

ci:test:stable - 9 out of 9 jobs PASSED
9 Successful Jobs:
ci:test:relevant - 23 out of 23 jobs PASSED
23 Successful Jobs:
For more details click here.

@jbalsas
Copy link

jbalsas commented Nov 24, 2020

ci:forward

@liferay-continuous-integration
Copy link
Collaborator

CI is automatically triggering the following test suites:

  •     ci:test:relevant
  •     ci:test:sf

The pull request will automatically be forwarded to the user brianchandotcom if the following test suites pass:

  •     ci:test:relevant
  •     ci:test:sf
  •     ci:test:stable

@liferay-continuous-integration
Copy link
Collaborator

Skipping previously passed test suites:
ci:test:relevant
ci:test:sf

@liferay-continuous-integration
Copy link
Collaborator

All required test suite(s) passed.
Forwarding pullrequest to brianchandotcom.

@liferay-continuous-integration
Copy link
Collaborator

Pull request has been successfully forwarded to brianchandotcom#96241

@liferay-continuous-integration
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants