From 6aabe915e891bbbac5cc52658136d87ef21eddfd Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 21 Dec 2021 14:45:09 -0500 Subject: [PATCH 1/7] Added tasts --- .vscode/tasks.json | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000000..ea550d21e7a9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,70 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "amp: Run unit test in this file", + "detail": "amp unit --files=${file} --headless --verbose", + "type": "shell", + "command": "amp", + "args": ["unit", "--files=${file}", "--headless", "--verbose"], + "group": "test", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "amp: Watch unit test in this file", + "detail": "amp unit --files=${file} --headless --verbose --watch", + "type": "shell", + "command": "amp", + "args": ["unit", "--files=${file}", "--headless", "--verbose", "--watch"], + "group": "test", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": true + }, + "isBackground": true + }, + { + "label": "amp: Run unit tests in all changed files", + "detail": "amp unit --local_changes --headless --verbose", + "type": "shell", + "command": "amp", + "args": ["unit", "--local_changes", "--headless", "--verbose"], + "group": "test", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "amp: Check PR", + "detail": "amp pr-check --nobuild", + "type": "shell", + "command": "amp", + "args": ["pr-check", "--nobuild"], + "group": "test", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + ] +} \ No newline at end of file From dc1fa876f8e029a54a7cfd4bf2f70795da071102 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 21 Dec 2021 14:47:32 -0500 Subject: [PATCH 2/7] Undo --- .vscode/tasks.json | 70 ---------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index ea550d21e7a9..000000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "amp: Run unit test in this file", - "detail": "amp unit --files=${file} --headless --verbose", - "type": "shell", - "command": "amp", - "args": ["unit", "--files=${file}", "--headless", "--verbose"], - "group": "test", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - } - }, - { - "label": "amp: Watch unit test in this file", - "detail": "amp unit --files=${file} --headless --verbose --watch", - "type": "shell", - "command": "amp", - "args": ["unit", "--files=${file}", "--headless", "--verbose", "--watch"], - "group": "test", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - }, - "isBackground": true - }, - { - "label": "amp: Run unit tests in all changed files", - "detail": "amp unit --local_changes --headless --verbose", - "type": "shell", - "command": "amp", - "args": ["unit", "--local_changes", "--headless", "--verbose"], - "group": "test", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - } - }, - { - "label": "amp: Check PR", - "detail": "amp pr-check --nobuild", - "type": "shell", - "command": "amp", - "args": ["pr-check", "--nobuild"], - "group": "test", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - } - }, - ] -} \ No newline at end of file From 3ae451f1a88eafac84c59909508bdc35353a9a4a Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 8 Mar 2022 13:23:42 -0500 Subject: [PATCH 3/7] Fixed outlink error --- .../0.1/amp-story-page-attachment.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js index 9fcdc5a28e07..92568d359c34 100644 --- a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js @@ -559,6 +559,10 @@ export class AmpStoryPageAttachment extends DraggableDrawer { const closeButton = this.headerEl.querySelector( '.i-amphtml-story-page-attachment-close-button' ); + // If attachment is outlink, there is no close button. + // if (!closeButton) { + // return; + // } this.mutateElement(() => { if (isActive) { closeButton.removeAttribute('tabindex'); From be1a81f177d750e6a15a6c364f93ae5676f5f80a Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 8 Mar 2022 13:38:57 -0500 Subject: [PATCH 4/7] Remove comment --- .../0.1/amp-story-page-attachment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js index 92568d359c34..9a7b6249ab02 100644 --- a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js @@ -560,9 +560,9 @@ export class AmpStoryPageAttachment extends DraggableDrawer { '.i-amphtml-story-page-attachment-close-button' ); // If attachment is outlink, there is no close button. - // if (!closeButton) { - // return; - // } + if (!closeButton) { + return; + } this.mutateElement(() => { if (isActive) { closeButton.removeAttribute('tabindex'); From 7ba8cfc94df32488cdcc12541a113bd050bf8a08 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 8 Mar 2022 14:19:30 -0500 Subject: [PATCH 5/7] Added test to make sure outlink doesn't break when opened --- .../0.1/amp-story-page-attachment.js | 2 +- .../test/test-amp-story-page-attachment.js | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js index 9a7b6249ab02..ac2f7c80adc8 100644 --- a/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js @@ -454,7 +454,7 @@ export class AmpStoryPageAttachment extends DraggableDrawer { const pageAttachmentChild = this.element.parentElement ?.querySelector('.i-amphtml-story-page-open-attachment-host') - .shadowRoot.querySelector('a.i-amphtml-story-page-open-attachment'); + .shadowRoot?.querySelector('a.i-amphtml-story-page-open-attachment'); if (pageOutlinkChild) { pageOutlinkChild.click(); diff --git a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js index a6dc24d56904..106c6380e8f4 100644 --- a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js @@ -1,10 +1,16 @@ +import {expect} from 'chai'; + import * as Preact from '#core/dom/jsx'; import {Services} from '#service'; import {AmpDocSingle} from '#service/ampdoc-impl'; import {LocalizationService} from '#service/localization'; -import {AmpStoryStoreService} from 'extensions/amp-story/1.0/amp-story-store-service'; +import { + Action, + AmpStoryStoreService, + UIType, +} from 'extensions/amp-story/1.0/amp-story-store-service'; import {registerServiceBuilder} from 'src/service-helpers'; import {StoryAnalyticsService} from '../../../amp-story/1.0/story-analytics'; @@ -15,6 +21,7 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { let attachment; let outlinkEl; let outlink; + let storeService; beforeEach(() => { const {win} = env; @@ -30,7 +37,7 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { return localizationService; }); - const storeService = new AmpStoryStoreService(win); + storeService = new AmpStoryStoreService(win); registerServiceBuilder(win, 'story-store', function () { return storeService; }); @@ -65,6 +72,10 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { outlinkEl.getAmpDoc = () => new AmpDocSingle(win); pageEl.appendChild(outlinkEl); outlink = new AmpStoryPageAttachment(outlinkEl); + + env.sandbox + .stub(outlink, 'mutateElement') + .callsFake((fn) => Promise.resolve(fn())); }); afterEach(() => { @@ -118,4 +129,19 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { expect(closeButtonEl.hasAttribute('tabindex')).to.be.false; }); + + it('should click on anchor when outlink open method is called', async () => { + storeService.dispatch(Action.TOGGLE_UI, UIType.DESKTOP_ONE_PANEL); + const anchorEl = outlinkEl.querySelector('amp-story-page-outlink a'); + anchorEl.setAttribute('target', '_blank'); + + const clickSpy = env.sandbox.spy(anchorEl, 'click'); + + await outlink.buildCallback(); + await outlink.layoutCallback(); + + outlink.open(); + + expect(clickSpy).to.be.called; + }); }); From 3bdabdba26db4ecd347191af1f4291d4ff47cb2f Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 8 Mar 2022 14:24:18 -0500 Subject: [PATCH 6/7] Removed unnecessary attribute --- .../0.1/test/test-amp-story-page-attachment.js | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js index 106c6380e8f4..9d26a6ed6b55 100644 --- a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js @@ -133,7 +133,6 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { it('should click on anchor when outlink open method is called', async () => { storeService.dispatch(Action.TOGGLE_UI, UIType.DESKTOP_ONE_PANEL); const anchorEl = outlinkEl.querySelector('amp-story-page-outlink a'); - anchorEl.setAttribute('target', '_blank'); const clickSpy = env.sandbox.spy(anchorEl, 'click'); From a0807046886bec89f7fe0745f262b3fc74aca0d8 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 8 Mar 2022 14:25:09 -0500 Subject: [PATCH 7/7] calledOnce --- .../0.1/test/test-amp-story-page-attachment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js index 9d26a6ed6b55..209cb1a57c21 100644 --- a/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js +++ b/extensions/amp-story-page-attachment/0.1/test/test-amp-story-page-attachment.js @@ -141,6 +141,6 @@ describes.realWin('amp-story-page-attachment', {amp: true}, (env) => { outlink.open(); - expect(clickSpy).to.be.called; + expect(clickSpy).to.be.calledOnce; }); });