Skip to content

Commit 37ffbde

Browse files
erwinmombayrenovate[bot]danielrozenberg
authored
Fix: Rename CloseWatcher.signalClose to CloseWatched.requestClose (#40213)
* 📦 Update dependency chromedriver to v131 * switch to realWin to resolve scheme-less url to the correct hostname something changed recently with Url Parsing in Chrome or something in the FakeWin implementation is causign it to not resolve properly. Quick fix seems to be to switch it to a real window * try out the disable feature * rename to requestClose * undo skip to test which tests are still failing * add back skip * try w/o closewatcher * Update test/unit/utils/test-close-watcher-impl.js Co-authored-by: Daniel Rozenberg <[email protected]> * Update test/unit/utils/test-close-watcher-impl.js Co-authored-by: Daniel Rozenberg <[email protected]> * Update test/unit/utils/test-close-watcher-impl.js Co-authored-by: Daniel Rozenberg <[email protected]> * Update test/unit/utils/test-close-watcher-impl.js Co-authored-by: Daniel Rozenberg <[email protected]> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Daniel Rozenberg <[email protected]>
1 parent 585c0da commit 37ffbde

File tree

4 files changed

+56
-45
lines changed

4 files changed

+56
-45
lines changed

extensions/amp-lightbox/0.1/test/test-amp-lightbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describes.realWin(
114114
const setupCloseSpy = env.sandbox.spy(impl, 'close');
115115

116116
await impl.open_({caller: sourceElement});
117-
impl.closeWatcher_.signalClosed();
117+
impl.closeWatcher_.requestClose();
118118
expect(setupCloseSpy).to.be.called;
119119
});
120120

src/utils/close-watcher-impl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export class CloseWatcherImpl {
6767

6868
/**
6969
* Signals to the close watcher to close the modal.
70-
* See `CloseWatcher.signalClosed`.
70+
* See `CloseWatcher.requestClose`.
7171
*/
72-
signalClosed() {
72+
requestClose() {
7373
if (this.watcher_) {
74-
this.watcher_.signalClosed();
74+
this.watcher_.requestClose();
7575
} else if (this.handler_) {
7676
const handler = this.handler_;
7777
handler();
@@ -106,7 +106,7 @@ export class CloseWatcherImpl {
106106
closeOnEscape_(event) {
107107
if (event.key == Keys_Enum.ESCAPE) {
108108
event.preventDefault();
109-
this.signalClosed();
109+
this.requestClose();
110110
}
111111
}
112112
}

src/utils/close-watcher.extern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function CloseWatcher() {}
1212

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

15-
CloseWatcher.prototype.signalClosed = function () {};
15+
CloseWatcher.prototype.requestClose = function () {};
1616

1717
/** @type {?function(!Event)} */
1818
CloseWatcher.prototype.onclose;

test/unit/utils/test-close-watcher-impl.js

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,57 @@ describes.realWin('#CloseWatcherImpl', {amp: true}, (env) => {
2424
historyMock.verify();
2525
});
2626

27-
// TODO(#40214): fix flaky test.
28-
it.skip('should push and pop history state', async () => {
29-
historyMock.expects('push').resolves('H1').once();
30-
historyMock.expects('pop').withArgs('H1').once();
31-
const watcher = new CloseWatcherImpl(ampdoc, handler);
32-
await Promise.resolve('H1');
33-
watcher.signalClosed();
34-
expect(handler).to.be.calledOnce;
35-
});
27+
it.configure()
28+
.if(() => 'CloseWatcher' in window)
29+
.run('should call the handler on requestClose', async () => {
30+
const watcher = new CloseWatcherImpl(ampdoc, handler);
31+
watcher.requestClose();
32+
expect(handler).to.be.calledOnce;
33+
});
3634

37-
// TODO(#40214): fix flaky test.
38-
it.skip('should trigger on history pop', async () => {
39-
let popHandler;
40-
historyMock
41-
.expects('push')
42-
.withArgs(
43-
env.sandbox.match((a) => {
44-
popHandler = a;
45-
return true;
46-
})
47-
)
48-
.resolves('H1')
49-
.once();
50-
new CloseWatcherImpl(ampdoc, handler);
51-
await Promise.resolve('H1');
52-
expect(popHandler).to.exist;
53-
popHandler();
54-
expect(handler).to.be.calledOnce;
55-
});
35+
it.configure()
36+
.if(() => !('CloseWatcher' in window))
37+
.run('should push and pop history state', async () => {
38+
historyMock.expects('push').resolves('H1').once();
39+
historyMock.expects('pop').withArgs('H1').once();
40+
const watcher = new CloseWatcherImpl(ampdoc, handler);
41+
await Promise.resolve('H1');
42+
watcher.requestClose();
43+
expect(handler).to.be.calledOnce;
44+
});
5645

57-
// TODO(#40214): fix flaky test.
58-
it.skip('should trigger on ESC key', async () => {
59-
historyMock.expects('push').resolves('H1').once();
60-
historyMock.expects('pop').withArgs('H1').once();
61-
new CloseWatcherImpl(ampdoc, handler);
62-
await Promise.resolve('H1');
46+
it.configure()
47+
.if(() => !('CloseWatcher' in window))
48+
.run('should trigger on history pop', async () => {
49+
let popHandler;
50+
historyMock
51+
.expects('push')
52+
.withArgs(
53+
env.sandbox.match((a) => {
54+
popHandler = a;
55+
return true;
56+
})
57+
)
58+
.resolves('H1')
59+
.once();
60+
new CloseWatcherImpl(ampdoc, handler);
61+
await Promise.resolve('H1');
62+
expect(popHandler).to.exist;
63+
popHandler();
64+
expect(handler).to.be.calledOnce;
65+
});
6366

64-
doc.documentElement.dispatchEvent(
65-
new KeyboardEvent('keydown', {key: Keys_Enum.ESCAPE})
66-
);
67-
expect(handler).to.be.calledOnce;
68-
});
67+
it.configure()
68+
.if(() => !('CloseWatcher' in window))
69+
.run('should trigger on ESC key', async () => {
70+
historyMock.expects('push').resolves('H1').once();
71+
historyMock.expects('pop').withArgs('H1').once();
72+
new CloseWatcherImpl(ampdoc, handler);
73+
await Promise.resolve('H1');
74+
75+
doc.documentElement.dispatchEvent(
76+
new KeyboardEvent('keydown', {key: Keys_Enum.ESCAPE})
77+
);
78+
expect(handler).to.be.calledOnce;
79+
});
6980
});

0 commit comments

Comments
 (0)