From f5ba242d40036c2589bd488fabec487af5906c58 Mon Sep 17 00:00:00 2001 From: silas Date: Wed, 10 Oct 2018 20:05:53 +0200 Subject: [PATCH] bugfixes --- public/js/app.js | 10 ++++---- src/js/lib/pwa-lib.js | 10 ++++---- test/test.testcafe.js | 55 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 09bc0df..9bf3249 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -2966,12 +2966,11 @@ ShareButton.TYPE_ALL = ShareButton.TYPE_DESKTOP+ShareButton.TYPE_MOBILE; class MultipleShareButton extends ShareButton{ constructor(deviceType, icon, callbacks, shouldLoadImg) { - console.log(Array.isArray(deviceType), deviceType[0] instanceof ShareButton); if (Array.isArray(deviceType) && deviceType[0] instanceof ShareButton){ let btn = deviceType[0]; + callbacks = deviceType; deviceType = btn._deviceType; icon = btn._icon; - callbacks = deviceType; shouldLoadImg = Helper.nonNull(shouldLoadImg, icon); } @@ -2984,6 +2983,7 @@ class MultipleShareButton extends ShareButton{ callbacks[i].getCallback()(link, element, event); } else { + console.log(callbacks, i); callbacks[i](link, element, event); } } @@ -3074,7 +3074,7 @@ class SmsShareButton extends ShareButton else { linkToOpen = "sms:?body=" + encodeURIComponent(link); } - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } @@ -3083,7 +3083,7 @@ class TelegramShareButton extends ShareButton { constructor(icon, shouldLoadImg) { super(ShareButton.TYPE_ALL, icon, function (link) { let linkToOpen = "https://t.me/share/url?url="+encodeURIComponent(link); - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } @@ -3098,7 +3098,7 @@ class WhatsappShareButton extends ShareButton { else { linkToOpen = "whatsapp://send?text=" + encodeURIComponent(link); } - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } diff --git a/src/js/lib/pwa-lib.js b/src/js/lib/pwa-lib.js index 8d99d5f..45c2b8d 100755 --- a/src/js/lib/pwa-lib.js +++ b/src/js/lib/pwa-lib.js @@ -3726,12 +3726,11 @@ class CopyShareButton extends ShareButton class MultipleShareButton extends ShareButton{ constructor(deviceType, icon, callbacks, shouldLoadImg) { - console.log(Array.isArray(deviceType), deviceType[0] instanceof ShareButton); if (Array.isArray(deviceType) && deviceType[0] instanceof ShareButton){ let btn = deviceType[0]; + callbacks = deviceType; deviceType = btn._deviceType; icon = btn._icon; - callbacks = deviceType; shouldLoadImg = Helper.nonNull(shouldLoadImg, icon); } @@ -3744,6 +3743,7 @@ class MultipleShareButton extends ShareButton{ callbacks[i].getCallback()(link, element, event); } else { + console.log(callbacks, i); callbacks[i](link, element, event); } } @@ -3834,7 +3834,7 @@ class SmsShareButton extends ShareButton else { linkToOpen = "sms:?body=" + encodeURIComponent(link); } - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } @@ -3843,7 +3843,7 @@ class TelegramShareButton extends ShareButton { constructor(icon, shouldLoadImg) { super(ShareButton.TYPE_ALL, icon, function (link) { let linkToOpen = "https://t.me/share/url?url="+encodeURIComponent(link); - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } @@ -3858,7 +3858,7 @@ class WhatsappShareButton extends ShareButton { else { linkToOpen = "whatsapp://send?text=" + encodeURIComponent(link); } - window.open(linkToOpen, '_blank'); + window.open(linkToOpen, '_blank', "noopener"); }, shouldLoadImg); } } diff --git a/test/test.testcafe.js b/test/test.testcafe.js index f0d8ba7..e3b120f 100644 --- a/test/test.testcafe.js +++ b/test/test.testcafe.js @@ -91,7 +91,7 @@ test('Play', async t => { await waitForMainMenu(t); await t //Main Menu - .click(Selector('#play-button')) + .click(Selector('#play-button')).wait(500) //firstTutorial .expect(Selector('.tutorial-text .step-1').visible).eql(true) @@ -201,15 +201,15 @@ test('Play', async t => { .expect(Selector('.segment-parent').nth(SEGMENT.THREE).textContent).eql("INCK") .expect(Selector('.segment-parent').nth(SEGMENT.FOUR).textContent).eql("PHRE") .expect(Selector('.segment-parent').nth(SEGMENT.FIVE).textContent).eql("YSSI") - .expect(Selector('.segment-parent').nth(SEGMENT.SIX).textContent).eql("BEHE") - .expect(Selector('.segment-parent').nth(SEGMENT.SEVEN).textContent).eql("RARZ") + .expect(Selector('.segment-parent').nth(SEGMENT.SIX).textContent).eql("BEKO") + .expect(Selector('.segment-parent').nth(SEGMENT.SEVEN).textContent).eql("RACH") .expect(Selector('.segment-parent').nth(SEGMENT.EIGHT).textContent).eql("GUFA") .expect(Selector('.segment-parent').nth(SEGMENT.NINE).textContent).eql("SSLL") - .expect(Selector('.segment-parent').nth(SEGMENT.TEN).textContent).eql("IKDEERNZTULANGND") + .expect(Selector('.segment-parent').nth(SEGMENT.TEN).textContent).eql("IKDEERNZTUTONGPF") .expect(Selector('.segment-parent').nth(SEGMENT.ELEVEN).textContent).eql("IKDE") .expect(Selector('.segment-parent').nth(SEGMENT.TWELVE).textContent).eql("ERNZ") - .expect(Selector('.segment-parent').nth(SEGMENT.THIRTEEN).textContent).eql("TULA") - .expect(Selector('.segment-parent').nth(SEGMENT.FOURTEEN).textContent).eql("NGND") + .expect(Selector('.segment-parent').nth(SEGMENT.THIRTEEN).textContent).eql("TUTO") + .expect(Selector('.segment-parent').nth(SEGMENT.FOURTEEN).textContent).eql("NGPF") .drag(Selector('.segment-parent').nth(SEGMENT.TEN), dragDimen, 4, { offsetX: 54, offsetY: 17 @@ -381,7 +381,7 @@ test('Play', async t => { }); test('LoadLastLevel', async t => { await waitForMainMenu(t); - await t.click(Selector('#play-button')) + await t.click(Selector('#play-button')).wait(500) .expect(Selector('.segment-parent').nth(SEGMENT.ONE).hasClass('locked')).ok() .expect(Selector('.segment-parent').nth(SEGMENT.ONE).getStyleProperty('transform')).eql("matrix(1, 0, 0, 1, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.TWO).getStyleProperty('transform')).eql("matrix(1, 0, 0, 1, 0, 0)") @@ -395,13 +395,13 @@ test('LevelRotation', async t => { .click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE)) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") - .wait(3500) + .wait(3700) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)") .click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.FOUR)) .click(Selector('.segment-parent').nth(SEGMENT.FOUR)) - .click(Selector('.segment-parent').nth(SEGMENT.FOUR)) + .click(Selector('.segment-parent').nth(SEGMENT.FOUR)).wait(500) .expect(Selector('.segment-parent').nth(SEGMENT.ONE).textContent).eql("AHAU") .expect(Selector('.segment-parent').nth(SEGMENT.TWO).textContent).eql("NUSB") .expect(Selector('.segment-parent').nth(SEGMENT.THREE).textContent).eql("NGAU"); @@ -411,7 +411,7 @@ test('LevelRotation', async t => { .click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE)) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") - .wait(3500) + .wait(3700) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)") .click(Selector('.segment-parent').nth(SEGMENT.THREE)) @@ -476,4 +476,39 @@ test('Themes', async t => { .expect(Selector("body.green").visible).ok() }).before(async t => { await testLocalStorageSet("currentTheme", "dark"); +}); + +test('Sharing', async t => { + + let overrideWindowOpener = ClientFunction(() => { + window.open = (url, blank, noopener) => { + window.lastWindowOpened = [url, blank, noopener]; + } + }); + + let getLastWindowOpened = ClientFunction(() => { + return window.lastWindowOpened; + }); + + await waitForMainMenu(t); + await overrideWindowOpener(); + + await t + .expect(Selector(".share-icon").nth(0).exists).eql(false) + .expect(Selector(".share-icon").nth(1).exists).eql(false) + .click(Selector("#share-button")) + .expect(Selector(".share-icon").nth(0).visible).ok() + .expect(Selector(".share-icon").nth(1).visible).ok() + .click(Selector(".share-icon").nth(0)) + .expect(Selector(".share-icon").nth(0).exists).eql(false) + .expect(Selector(".share-icon").nth(1).exists).eql(false); + await t.expect(await getLastWindowOpened()).eql(["https://web.whatsapp.com/send?text="+encodeURIComponent("127.0.0.1/pwa/wordRotator/publicTest/"), "_blank", "noopener"]); + await t + .click(Selector("#share-button")) + .expect(Selector(".share-icon").nth(0).visible).ok() + .expect(Selector(".share-icon").nth(1).visible).ok() + .click(Selector(".share-icon").nth(1)) + .expect(Selector(".share-icon").nth(0).exists).eql(false) + .expect(Selector(".share-icon").nth(1).exists).eql(false); + await t.expect(await getLastWindowOpened()).eql(["https://t.me/share/url?url="+encodeURIComponent("127.0.0.1/pwa/wordRotator/publicTest/"), "_blank", "noopener"]); }); \ No newline at end of file