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

DO NOT SUBMIT: Fix more tests #40215

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/amp-ad-exit/0.1/test-e2e/test-amp-ad-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describes.endtoend(
});

// TODO(#40214): fix flaky test.
it.skip('product2 ad opened', async () => {
it('product2 ad opened', async () => {
const adDiv = await controller.findElement('#product2');
await setTime(Number.MAX_VALUE);
await controller.click(adDiv);
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-lightbox/0.1/test/test-amp-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describes.realWin(
const setupCloseSpy = env.sandbox.spy(impl, 'close');

await impl.open_({caller: sourceElement});
impl.closeWatcher_.signalClosed();
impl.closeWatcher_.requestClose();
expect(setupCloseSpy).to.be.called;
});

Expand Down
8 changes: 4 additions & 4 deletions src/utils/close-watcher-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@

/**
* Signals to the close watcher to close the modal.
* See `CloseWatcher.signalClosed`.
* See `CloseWatcher.requestClose`.
*/
signalClosed() {
requestClose() {
if (this.watcher_) {
this.watcher_.signalClosed();
this.watcher_.requestClose();
} else if (this.handler_) {
const handler = this.handler_;
handler();
Expand Down Expand Up @@ -106,7 +106,7 @@
closeOnEscape_(event) {
if (event.key == Keys_Enum.ESCAPE) {
event.preventDefault();
this.signalClosed();
this.requestClose();

Check warning on line 109 in src/utils/close-watcher-impl.js

View check run for this annotation

Codecov / codecov/patch

src/utils/close-watcher-impl.js#L109

Added line #L109 was not covered by tests
}
}
}
2 changes: 1 addition & 1 deletion src/utils/close-watcher.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function CloseWatcher() {}

CloseWatcher.prototype.destroy = function () {};

CloseWatcher.prototype.signalClosed = function () {};
CloseWatcher.prototype.requestClose = function () {};

/** @type {?function(!Event)} */
CloseWatcher.prototype.onclose;
Expand Down
90 changes: 51 additions & 39 deletions test/unit/utils/test-close-watcher-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,58 @@ describes.realWin('#CloseWatcherImpl', {amp: true}, (env) => {
historyMock.verify();
});

// TODO(#40214): fix flaky test.
it.skip('should push and pop history state', async () => {
historyMock.expects('push').resolves('H1').once();
historyMock.expects('pop').withArgs('H1').once();
const watcher = new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');
watcher.signalClosed();
expect(handler).to.be.calledOnce;
});
it.configure()
.ifChrome()
.run('should call the handler on requestClose', async () => {
const watcher = new CloseWatcherImpl(ampdoc, handler);
watcher.requestClose();
expect(handler).to.be.calledOnce;
});

// TODO(#40214): fix flaky test.
it.skip('should trigger on history pop', async () => {
let popHandler;
historyMock
.expects('push')
.withArgs(
env.sandbox.match((a) => {
popHandler = a;
return true;
})
)
.resolves('H1')
.once();
new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');
expect(popHandler).to.exist;
popHandler();
expect(handler).to.be.calledOnce;
});
// NOTE: Chrome supports the CloseWatcher API so we no longer use the History API.
it.configure()
.skipChrome()
.run('should push and pop history state', async () => {
historyMock.expects('push').resolves('H1').once();
historyMock.expects('pop').withArgs('H1').once();
const watcher = new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');
watcher.requestClose();
expect(handler).to.be.calledOnce;
});

// TODO(#40214): fix flaky test.
it.skip('should trigger on ESC key', async () => {
historyMock.expects('push').resolves('H1').once();
historyMock.expects('pop').withArgs('H1').once();
new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');
it.configure()
.skipChrome()
.run('should trigger on history pop', async () => {
let popHandler;
historyMock
.expects('push')
.withArgs(
env.sandbox.match((a) => {
popHandler = a;
return true;
})
)
.resolves('H1')
.once();
new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');
expect(popHandler).to.exist;
popHandler();
expect(handler).to.be.calledOnce;
});

doc.documentElement.dispatchEvent(
new KeyboardEvent('keydown', {key: Keys_Enum.ESCAPE})
);
expect(handler).to.be.calledOnce;
});
it.configure()
.skipChrome()
.run('should trigger on ESC key', async () => {
historyMock.expects('push').resolves('H1').once();
historyMock.expects('pop').withArgs('H1').once();
new CloseWatcherImpl(ampdoc, handler);
await Promise.resolve('H1');

doc.documentElement.dispatchEvent(
new KeyboardEvent('keydown', {key: Keys_Enum.ESCAPE})
);
expect(handler).to.be.calledOnce;
});
});
Loading