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

Add unit, e2e tests for amp-carousel exposed actionTrust #27157

Merged
merged 17 commits into from Mar 30, 2020

Conversation

caroqliu
Copy link
Contributor

@caroqliu caroqliu commented Mar 9, 2020

Continuing prior discussion, renames ampTrust as actionTrust and adds unit and e2e tests regarding this behavior.

cc @zhangsu

@caroqliu caroqliu requested a review from estherkim March 9, 2020 17:07
@caroqliu caroqliu marked this pull request as ready for review March 10, 2020 19:46
@estherkim
Copy link
Collaborator

Can you try merging master?

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@wassgha
Copy link
Contributor

wassgha commented Mar 24, 2020

@googlebot I consent.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Still looks good but thought some feedback might be helpful. 😋

environments: ['single'],
},
async function(env) {
const ActionTrust = {LOW: 1, HIGH: 3};

Choose a reason for hiding this comment

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

I mentioned this earlier but if we ever need to add an enum between low and default, it might be awkward (non-integer).

Copy link
Contributor Author

@caroqliu caroqliu Mar 26, 2020

Choose a reason for hiding this comment

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

This is my understanding of the tradeoffs with either approach, am I missing anything?
Pros for exposing strings:

  • Human-readable and meaningful, especially in debugging
  • Adding intermediary values is straight forward
  • Int values are an implementation detail within AMP, exposing them as such also means making others mimic this implementation.

Pros for exposing integers:

  • Meaningful to compare (trust < high)
  • Not localized to us -- i.e. "low" is in English
  • Faster, esp. if trust is checked often

Choose a reason for hiding this comment

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

Those look good. We could also change the integer enum values to have some breathing room -- I think they originally did before I removed it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What was the reasoning behind removing it?

Choose a reason for hiding this comment

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

Just a whim. :p

This most likely won't be necessary since 4 tiers of "trust" is quite a lot to grok. Just wanted to point out the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG, going to go ahead and merge in this case.

document.removeEventListener('slideChange', forwardEvent);
resolve(e.data.actionTrust);
});
document.querySelector('.amp-carousel-button-next').click();

Choose a reason for hiding this comment

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

Ahh, sorry I just meant to extract this line rather than inline the entire helper. That way the test readers can read the logic of the test naturally like:

  1. Click button
  2. Wait for slideChange event
  3. Assert actionTrust of event is 3

I also wonder if we could set up/tear down the listener in beforeEach/afterEach. If either of those are troublesome, just tweaking the helper a bit would be nice for semantics.

// Before
const actionTrust = await getActionTrustFor('.amp-carousel-button-next');

// After
const event = await slideChangeEventAfterClicking('.amp-carousel-button-next');
expect (event.data.actionTrust).to.equal(3); // ActionTrust.HIGH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like taking and resolving the same event leads to a circular reference, so I had the helper return event.data instead. Also used the once option when adding the event listener, so should be more readable now.

@caroqliu caroqliu merged commit 84f4d6e into ampproject:master Mar 30, 2020
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.

None yet

6 participants