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

🐛 [bento][amp-accordion] Update accordion to dispatch event with correct name #32141

Merged
merged 3 commits into from
Jan 26, 2021

Conversation

krdwan
Copy link
Contributor

@krdwan krdwan commented Jan 22, 2021

Fix a bug in amp-accordion. amp-accordion was dispatching events with the incorrect name causing a bug when attempting to listen for events in bento mode.

Copy link
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

LGTM with one request

// Set up section 1 to trigger expand of section 3 on expand
// and collapse of section 3 on collapse
const api = await element.getApi();
section1.addEventListener('expand', () => api.expand('section3'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably would be nice to just have a test where we check that the event has been delivered.

E.g.

const spy = sandbox.spy();
section1.addEventListener('expand', spy);
// do work
expect(spy).to.be.calledOnce.

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 added spies to this unit test. Do you think it's too convoluted this way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I interpreted the suggestion as to use spies instead of propagating events to an additional section. Or if doing both, separate them as distinct it blocks (one which checks spies, one which copies mimics events onto the other section).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem. I've updated the tests to two separate tests.

@krdwan
Copy link
Contributor Author

krdwan commented Jan 22, 2021

Adding @caroqliu as FYI. Didn't add you at first since the fix seemed trivial. But the tests might be interesting to you.

// Set up section 1 to trigger expand of section 3 on expand
// and collapse of section 3 on collapse
const api = await element.getApi();
section1.addEventListener('expand', () => api.expand('section3'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I interpreted the suggestion as to use spies instead of propagating events to an additional section. Or if doing both, separate them as distinct it blocks (one which checks spies, one which copies mimics events onto the other section).

@krdwan krdwan merged commit 21fb02d into ampproject:master Jan 26, 2021
PetrBlaha pushed a commit to PetrBlaha/amphtml that referenced this pull request Jan 28, 2021
…ect name (ampproject#32141)

* Fix a bug in bento accordion

* Add spy functions

* Separate tests for listening to events
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

4 participants