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

✨ [amp-carousel]: Expose ampTrust in slideChange event #31487

Closed
wants to merge 12 commits into from
Closed
5 changes: 3 additions & 2 deletions extensions/amp-carousel/0.2/amp-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,15 @@ class AmpCarousel extends AMP.BaseElement {
return;
}

const data = dict({'index': index});
const name = 'slideChange';
const isHighTrust = this.isHighTrustActionSource_(actionSource);
const trust = isHighTrust ? ActionTrust.HIGH : ActionTrust.LOW;
const data = dict({'index': index});
const dataWithActionTrust = dict({'index': index, 'actionTrust': trust});

const action = createCustomEvent(this.win, `slidescroll.${name}`, data);
this.action_.trigger(this.element, name, action, trust);
dispatchCustomEvent(this.element, name, data);
dispatchCustomEvent(this.element, name, dataWithActionTrust);
this.triggerAnalyticsEvent_(prevIndex, index);
}

Expand Down
15 changes: 11 additions & 4 deletions extensions/amp-carousel/0.2/test/test-type-slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,22 @@ describes.realWin(
expect(eventSpy).to.have.not.been.called;
});

it('should dispatch when changing slides', async () => {
const eventSpy = env.sandbox.spy();
container.addEventListener('slideChange', eventSpy);
it('should dispatch event with index and actionTrust when changing slides', async () => {
let event;
let counter = 0;
container.addEventListener('slideChange', (e) => {
counter++;
event = e;
});
const carousel = await getCarousel({loop: false});

carousel.implementation_.interactionNext();

await afterIndexUpdate(carousel);

expect(eventSpy).to.have.been.calledOnce;
expect(counter).to.equal(1);
expect(event.data.index).to.equal(1);
expect(event.data.actionTrust).to.equal(ActionTrust.HIGH);
});
});

Expand Down