From 2527d2e65792655025bdaa786c1d89bce84b2162 Mon Sep 17 00:00:00 2001 From: Theresa Summa Lurie Date: Wed, 12 Jul 2017 17:48:12 -0700 Subject: [PATCH 1/7] upgrade and caretize first batch of npm libs --- regulations/static/config/package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/regulations/static/config/package.json b/regulations/static/config/package.json index cdd70d240..f87634c35 100644 --- a/regulations/static/config/package.json +++ b/regulations/static/config/package.json @@ -75,12 +75,12 @@ } }, "dependencies": { - "backbone": "1.2.3", + "backbone": "^1.3.3", "backbone-query-parameters": "0.4.0", - "backbone.localstorage": "1.1.16", - "clipboard": "1.5.5", - "datatables.net": "1.10.10", - "filesize": "3.2.1", + "backbone.localstorage": "^2.0.0", + "clipboard": "^1.7.1", + "datatables.net": "^1.10.15", + "filesize": "^3.5.10", "jquery": "1.12.2", "jquery-lazyload": "1.9.7", "jquery-scrollstop": "1.2.0", From 598b695bdce3c4964f455a6c06cdd0a29966d34f Mon Sep 17 00:00:00 2001 From: Theresa Summa Lurie Date: Wed, 19 Jul 2017 13:58:17 -0700 Subject: [PATCH 2/7] backbone.localstorage now returns a named variable --- .../regulations/js/source/collections/comment-collection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/regulations/static/regulations/js/source/collections/comment-collection.js b/regulations/static/regulations/js/source/collections/comment-collection.js index fe5b04b73..31261d9d4 100644 --- a/regulations/static/regulations/js/source/collections/comment-collection.js +++ b/regulations/static/regulations/js/source/collections/comment-collection.js @@ -2,7 +2,8 @@ const _ = require('underscore'); const Backbone = require('backbone'); -Backbone.LocalStorage = require('backbone.localstorage'); +localStorage = require('backbone.localstorage'); +Backbone.LocalStorage = localStorage.LocalStorage; const commentModel = require('../models/comment-model'); From 7f7c24ecb6fa984bb5d1fe878a84006967da1cc1 Mon Sep 17 00:00:00 2001 From: Theresa Summa Lurie Date: Thu, 20 Jul 2017 11:47:35 -0700 Subject: [PATCH 3/7] don't modify localStorage global, use const instead as intended --- .../regulations/js/source/collections/comment-collection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regulations/static/regulations/js/source/collections/comment-collection.js b/regulations/static/regulations/js/source/collections/comment-collection.js index 31261d9d4..39e55328f 100644 --- a/regulations/static/regulations/js/source/collections/comment-collection.js +++ b/regulations/static/regulations/js/source/collections/comment-collection.js @@ -2,7 +2,7 @@ const _ = require('underscore'); const Backbone = require('backbone'); -localStorage = require('backbone.localstorage'); +const localStorage = require('backbone.localstorage'); Backbone.LocalStorage = localStorage.LocalStorage; const commentModel = require('../models/comment-model'); From 1c9298d37ae44be8140ebc622c949f96925a64e1 Mon Sep 17 00:00:00 2001 From: Theresa Summa Lurie Date: Tue, 25 Jul 2017 08:23:54 -0700 Subject: [PATCH 4/7] update the rest of the packages, except jquery --- regulations/static/config/package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/regulations/static/config/package.json b/regulations/static/config/package.json index f87634c35..d1deb7243 100644 --- a/regulations/static/config/package.json +++ b/regulations/static/config/package.json @@ -82,16 +82,16 @@ "datatables.net": "^1.10.15", "filesize": "^3.5.10", "jquery": "1.12.2", - "jquery-lazyload": "1.9.7", - "jquery-scrollstop": "1.2.0", + "jquery-lazyload": "^1.9.7", + "jquery-scrollstop": "^1.2.0", "prosemirror": "0.4.0", - "query-command-supported": "1.0.0", + "query-command-supported": "^1.0.0", "react": "^15.4.1", "react-dom": "^15.4.1", "redux": "^3.6.0", - "respond.js": "1.4.2", - "underscore": "1.8.3", - "urijs": "1.17.1" + "respond.js": "^1.4.2", + "underscore": "^1.8.3", + "urijs": "^1.18.10" }, "config": { "travis-cov": { From fae7a674befbaa03d86a104c162093e9b54bfd6f Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 15 Aug 2017 10:50:38 -0400 Subject: [PATCH 5/7] Switch localstorage mocking libraries. node-localstorage writes its data to the local file system, which is a bit of a pain. In particular, we were loading `.`, which meant that if we cleared the storage, we'd delete everything in the current directory. dom-storage is a bit more widely used and can live in memory. --- regulations/static/config/package.json | 2 +- .../js/unittests/specs/views/comment-confirm-view-spec.js | 7 +++---- .../js/unittests/specs/views/comment-view-spec.js | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/regulations/static/config/package.json b/regulations/static/config/package.json index d1deb7243..4ee883634 100644 --- a/regulations/static/config/package.json +++ b/regulations/static/config/package.json @@ -38,6 +38,7 @@ "chai": "^3.5.0", "coveralls": "^2.11.2", "deamdify": "^0.1.1", + "dom-storage": "^2.0.2", "eslint": "^3.12.2", "eslint-config-airbnb": "^13.0.0", "eslint-plugin-import": "^2.2.0", @@ -60,7 +61,6 @@ "minifyify": "^7.2.1", "mocha": "^3.2.0", "mocha-jsdom": "^1.1.0", - "node-localstorage": "^1.3.0", "sinon": "^1.17.3", "sinon-chai": "^2.8.0", "watch": "^0.17.1" diff --git a/regulations/static/regulations/js/unittests/specs/views/comment-confirm-view-spec.js b/regulations/static/regulations/js/unittests/specs/views/comment-confirm-view-spec.js index f0dd176ca..bce9bc83d 100644 --- a/regulations/static/regulations/js/unittests/specs/views/comment-confirm-view-spec.js +++ b/regulations/static/regulations/js/unittests/specs/views/comment-confirm-view-spec.js @@ -1,9 +1,7 @@ var chai = require('chai'); var expect = chai.expect; var jsdom = require('mocha-jsdom'); -var localStorage = require('node-localstorage'); - -var storage = new localStorage.LocalStorage('.'); +var Storage = require('dom-storage'); describe('CommentConfirmView', function() { jsdom(); @@ -15,7 +13,7 @@ describe('CommentConfirmView', function() { Backbone = require('backbone'); $ = require('jquery'); Backbone.$ = $; - global.localStorage = window.localStorage = storage; + global.localStorage = window.localStorage = new Storage(); comments = require('../../../source/collections/comment-collection'); CommentModel = require('../../../source/models/comment-model').CommentModel; CommentConfirmView = require('../../../source/views/comment/comment-confirm-view'); @@ -37,6 +35,7 @@ describe('CommentConfirmView', function() { comments.models.forEach(function(comment) { comment.destroy(); }); + window.localStorage.clear(); }); it('clears comments when metadata is defined', function() { diff --git a/regulations/static/regulations/js/unittests/specs/views/comment-view-spec.js b/regulations/static/regulations/js/unittests/specs/views/comment-view-spec.js index 36cfe4ef5..ae2605dd9 100644 --- a/regulations/static/regulations/js/unittests/specs/views/comment-view-spec.js +++ b/regulations/static/regulations/js/unittests/specs/views/comment-view-spec.js @@ -2,11 +2,9 @@ var chai = require('chai'); var expect = chai.expect; var sinon = require('sinon'); var jsdom = require('mocha-jsdom'); -var localStorage = require('node-localstorage'); +var Storage = require('dom-storage'); var _ = require('underscore'); -var storage = new localStorage.LocalStorage('.'); - describe('CommentView', function() { jsdom(); @@ -18,7 +16,7 @@ describe('CommentView', function() { $ = require('jquery'); Backbone.$ = $; edit = require('prosemirror/dist/edit'); - global.localStorage = window.localStorage = storage; + global.localStorage = window.localStorage = new Storage(); comments = require('../../../source/collections/comment-collection'); CommentEvents = require('../../../source/events/comment-events'); CommentView = require('../../../source/views/comment/comment-view'); @@ -60,6 +58,7 @@ describe('CommentView', function() { edit.ProseMirror.prototype.getContent.restore(); edit.ProseMirror.prototype.setContent.restore(); edit.ProseMirror.prototype.ensureOperation.restore(); + window.localStorage.clear(); }); it('removes an attachment', function() { From bce9c17ea32557847934575975620477571f6074 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 15 Aug 2017 12:30:17 -0400 Subject: [PATCH 6/7] Update to jQuery 1.12.4. We'll probably want to switch to the 3.X line, but I didn't want to make that potentially breaking change now. 1.12.4's version of :visible doesn't work with DOM elements that aren't attached (including those of jsdom), so some tests needed to be tweaked to avoid that. --- regulations/static/config/package.json | 2 +- .../specs/views/stars-helpers-spec.js | 80 ++++++++----------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/regulations/static/config/package.json b/regulations/static/config/package.json index 4ee883634..7a3de4f1b 100644 --- a/regulations/static/config/package.json +++ b/regulations/static/config/package.json @@ -81,7 +81,7 @@ "clipboard": "^1.7.1", "datatables.net": "^1.10.15", "filesize": "^3.5.10", - "jquery": "1.12.2", + "jquery": "^1.12.4", "jquery-lazyload": "^1.9.7", "jquery-scrollstop": "^1.2.0", "prosemirror": "0.4.0", diff --git a/regulations/static/regulations/js/unittests/specs/views/stars-helpers-spec.js b/regulations/static/regulations/js/unittests/specs/views/stars-helpers-spec.js index 6988da971..666b5e16f 100644 --- a/regulations/static/regulations/js/unittests/specs/views/stars-helpers-spec.js +++ b/regulations/static/regulations/js/unittests/specs/views/stars-helpers-spec.js @@ -2,45 +2,45 @@ var chai = require('chai'); var expect = chai.expect; var jsdom = require('mocha-jsdom'); +let $; // Must be loaded after the jsdom + +// jsdom doesn't support jQuery's latest revision of :visible +function isVisible($el) { + const elHidden = $el.css('display') === 'none'; + const parentHidden = $el.parents().filter( + (idx, p) => $(p).css('display') === 'none').length > 0; + return !elHidden && !parentHidden; +} + describe('starsHelpers.inline', function() { jsdom(); - var starsHelpers, $; + var starsHelpers, $li; before(function() { $ = require('jquery'); starsHelpers = require('../../../source/views/main/stars-helpers'); - }); - - it('does not hide the marker, but does hide the intro text', function() { - var $li = $( + $li = $( '
  • ' + 'b.' + 'Remainder of the text' + '

  • '); + }); + + it('does not hide the marker, but does hide the intro text', function() { starsHelpers.inline($li); - expect($li.find('.collapsed-marker').is(':visible')).to.be.true; - expect($li.find('.paragraph-text').is(':visible')).to.be.false; + expect(isVisible($li.find('.collapsed-marker'))).to.be.true; + expect(isVisible($li.find('.paragraph-text'))).to.be.false; }); it('generates an expander which reverses the hiding', function() { - var $li = $( - '
  • ' + - 'b.' + - 'Remainder of the text' + - '

  • '); var $expander = starsHelpers.inline($li); expect($li.find($expander)).to.be.ok; $expander.click(); - expect($li.find('.collapsed-marker').is(':visible')).to.be.true; - expect($li.find('.paragraph-text').is(':visible')).to.be.true; + expect(isVisible($li.find('.collapsed-marker'))).to.be.true; + expect(isVisible($li.find('.paragraph-text'))).to.be.true; expect($li.find($expander).length).to.equal(0); }); it('unsets and resets the "collapsed" class', function() { - var $li = $( - '
  • '); var $expander = starsHelpers.inline($li); expect($li.find('.collapsed')).not.to.be.truthy; @@ -51,53 +51,43 @@ describe('starsHelpers.inline', function() { describe('starsHelpers.full', function() { jsdom(); - var starsHelpers, $; + var starsHelpers, $li; before(function() { $ = require('jquery'); starsHelpers = require('../../../source/views/main/stars-helpers'); - }); - - it('hides everything within the li if no expander is provided', function() { - var $li = $( + $li = $( '
  • ' + 'b.' + 'Remainder of the text' + '

  • '); + }); + + it('hides everything within the li if no expander is provided', function() { starsHelpers.full($li, null); - expect($li.is(':visible')).to.be.true; - expect($li.find('.collapsed-marker').is(':visible')).to.be.false; - expect($li.find('.paragraph-text').is(':visible')).to.be.false; + expect(isVisible($li)).to.be.true; + expect(isVisible($li.find('.collapsed-marker'))).to.be.false; + expect(isVisible($li.find('.paragraph-text'))).to.be.false; }); it('if no expander is provided, a new one is generated', function() { - var $li = $( - '
  • ' + - 'b.' + - 'Remainder of the text' + - '

  • '); var $expander = starsHelpers.full($li, null); expect($li.find($expander)).to.be.ok; $expander.click(); - expect($li.find('.collapsed-marker').is(':visible')).to.be.true; - expect($li.find('.paragraph-text').is(':visible')).to.be.true; + expect(isVisible($li.find('.collapsed-marker'))).to.be.true; + expect(isVisible($li.find('.paragraph-text'))).to.be.true; expect($li.find($expander).length).to.equal(0); }); it('reuses an existing expander, if provided and hides the li', function() { - var $li = $( - '
  • '); var $expander = $('