Mhurd has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/355865 )

Change subject: Add test for HTML in certain iOS announcement fields
......................................................................

Add test for HTML in certain iOS announcement fields

The iOS app doesn't support HTML in certain announcement fields.

Not testing for this caused some HTML to accidentally appear
uninterpreted in the latest iOS announcement. This was
hotfixed here: https://gerrit.wikimedia.org/r/#/c/355734/

Bug: T166356
Change-Id: I34b48f52f53d92168264011b7bf452e26c12db8e
---
M test/features/announcements/announcements.js
M test/utils/testUtil.js
2 files changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/65/355865/1

diff --git a/test/features/announcements/announcements.js 
b/test/features/announcements/announcements.js
index 483a2a5..a03d3ac 100644
--- a/test/features/announcements/announcements.js
+++ b/test/features/announcements/announcements.js
@@ -4,6 +4,8 @@
 const assert = require('../../utils/assert.js');
 const server = require('../../utils/server.js');
 const headers = require('../../utils/headers.js');
+const domino = require('domino');
+const testUtil = require('../../utils/testUtil.js');
 
 describe('announcements', function() {
 
@@ -51,4 +53,26 @@
                 assert.ok(res.body.announce.length === 0);
             });
     });
+
+    it('should not deliver HTML in certain iOS announcements fields', () => {
+        const doc = domino.createDocument();
+        return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/feed/announcements` })
+            .then((res) => {
+                assert.status(res, 200);
+                const iOSAnnouncements = res.body.announce
+                  .filter(announcement => 
announcement.platforms.includes('iOSApp'));
+                const textOnlyFields = ['text', 'action.title'];
+                iOSAnnouncements.forEach((iOSAnnouncement) => {
+                    textOnlyFields.forEach((textOnlyField) => {
+                        const deepObj = 
testUtil.valueByDotNotation(iOSAnnouncement, textOnlyField);
+                        const element = doc.createElement('div');
+                        element.innerHTML = deepObj;
+                        // Comparing innerHTML and textContent lengths catches 
even non-tag html,
+                        // such as '&nbsp';
+                        assert.equal(element.innerHTML.length, 
element.textContent.length,
+                          `iOS does not support HTML in the "${textOnlyField}" 
field`);
+                    });
+                });
+            });
+    });
 });
diff --git a/test/utils/testUtil.js b/test/utils/testUtil.js
index 71a44d2..f22ff3b 100644
--- a/test/utils/testUtil.js
+++ b/test/utils/testUtil.js
@@ -16,4 +16,16 @@
          dateUtil.pad(dateObj.getUTCDate())}`;
 };
 
+/**
+ * Dot notation for accessing deep object by a string path.
+ * See https://stackoverflow.com/a/29576764
+ * @param {!Object} object the object on which to seek a deep object
+ * @param {!String} path dot notation path for the sought deep object: such as 
'something' or
+ * 'something.stuff' or 'something[0].name'
+ */
+testUtil.valueByDotNotation = function(object, path) {
+    // eslint-disable-next-line no-new-func
+    return new Function('_', `return _.${path}`)(object);
+};
+
 module.exports = testUtil;

-- 
To view, visit https://gerrit.wikimedia.org/r/355865
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34b48f52f53d92168264011b7bf452e26c12db8e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mhurd <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to