From d0768dce9f6ff83f3e8d38d5979126e109c83c9f Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Fri, 26 May 2017 14:51:09 -0700 Subject: [PATCH] add shoebox tests --- package.json | 1 + tests/unit/services/fastboot/shoebox-test.js | 88 ++++++++++++++++++++ yarn.lock | 45 +++++----- 3 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 tests/unit/services/fastboot/shoebox-test.js diff --git a/package.json b/package.json index c60ff0a82..ce546a607 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "ember-export-application-global": "^1.0.5", "ember-load-initializers": "^0.6.0", "ember-resolver": "^2.0.3", + "ember-sinon": "^0.7.0", "ember-source": "^2.12.0-beta.1", "fs-extra": "^1.0.0", "glob": "^7.0.0", diff --git a/tests/unit/services/fastboot/shoebox-test.js b/tests/unit/services/fastboot/shoebox-test.js new file mode 100644 index 000000000..56cd475c5 --- /dev/null +++ b/tests/unit/services/fastboot/shoebox-test.js @@ -0,0 +1,88 @@ +import { moduleFor, test } from 'ember-qunit'; +import sinon from 'sinon'; + +let sandbox; + +moduleFor('service:fastboot', 'Unit | Service | fastboot | shoebox', { + beforeEach() { + sandbox = sinon.sandbox.create(); + }, + afterEach() { + sandbox.restore(); + } +}); + +test('retrieve returns value if isFastBoot false and key is cached', function(assert) { + let service = this.subject(); + + service.set('shoebox.foo', 'bar'); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar'); +}); + +test('retrieve returns undefined if isFastBoot false and shoebox is missing', function(assert) { + let service = this.subject(); + + let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo'); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined); + + sinon.assert.calledOnce(stub); +}); + +test('retrieve returns undefined if isFastBoot false and textContent is missing', function(assert) { + let service = this.subject(); + + let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({}); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined); + + sinon.assert.calledOnce(stub); +}); + +test('retrieve returns value if isFastBoot false and textContent is present', function(assert) { + let service = this.subject(); + + let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({ + textContent: '{"foo":"bar"}' + }); + + assert.deepEqual(service.get('shoebox').retrieve('foo'), { + foo: 'bar' + }); + + sinon.assert.calledOnce(stub); +}); + +test('retrieve returns undefined if isFastBoot true and shoebox is missing', function(assert) { + let service = this.subject({ + isFastBoot: true, + _fastbootInfo: {} + }); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined); +}); + +test('retrieve returns undefined if isFastBoot true and key is missing', function(assert) { + let service = this.subject({ + isFastBoot: true, + _fastbootInfo: { + shoebox: {} + } + }); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined); +}); + +test('retrieve returns value if isFastBoot true and key is present', function(assert) { + let service = this.subject({ + isFastBoot: true, + _fastbootInfo: { + shoebox: { + foo: 'bar' + } + } + }); + + assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar'); +}); diff --git a/yarn.lock b/yarn.lock index 4298c6f7a..3c04bde70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1165,15 +1165,15 @@ broccoli-config-replace@^1.1.2: fs-extra "^0.24.0" broccoli-debug@^0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/broccoli-debug/-/broccoli-debug-0.6.1.tgz#aec612ba8e5419952f44dc78be52bfabcbc087f6" + version "0.6.2" + resolved "https://registry.yarnpkg.com/broccoli-debug/-/broccoli-debug-0.6.2.tgz#4c6e89459fc3de7d5d4fc7b77e57f46019f44db1" dependencies: broccoli-plugin "^1.2.1" fs-tree-diff "^0.5.2" heimdalljs "^0.2.1" heimdalljs-logger "^0.1.7" minimatch "^3.0.3" - sanitize-filename "^1.6.1" + symlink-or-copy "^1.1.8" tree-sync "^1.2.2" broccoli-file-creator@^1.0.0: @@ -1205,7 +1205,7 @@ broccoli-funnel-reducer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/broccoli-funnel-reducer/-/broccoli-funnel-reducer-1.0.0.tgz#11365b2a785aec9b17972a36df87eef24c5cc0ea" -broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli-funnel@^1.2.0: +broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli-funnel@^1.1.0, broccoli-funnel@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/broccoli-funnel/-/broccoli-funnel-1.2.0.tgz#cddc3afc5ff1685a8023488fff74ce6fb5a51296" dependencies: @@ -1250,7 +1250,7 @@ broccoli-lint-eslint@^3.3.0: lodash.defaultsdeep "^4.6.0" md5-hex "^2.0.0" -broccoli-merge-trees@^1.0.0, broccoli-merge-trees@^1.1.0, broccoli-merge-trees@^1.1.1, broccoli-merge-trees@^1.1.4: +broccoli-merge-trees@^1.0.0, broccoli-merge-trees@^1.1.0, broccoli-merge-trees@^1.1.1, broccoli-merge-trees@^1.1.4, broccoli-merge-trees@^1.2.1: version "1.2.4" resolved "https://registry.yarnpkg.com/broccoli-merge-trees/-/broccoli-merge-trees-1.2.4.tgz#a001519bb5067f06589d91afa2942445a2d0fdb5" dependencies: @@ -1441,8 +1441,8 @@ can-symlink@^1.0.0: tmp "0.0.28" caniuse-lite@^1.0.30000670: - version "1.0.30000671" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000671.tgz#c206c2f1a1feb34de46064407c4356818389bf1e" + version "1.0.30000672" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000672.tgz#3f89b9907db78653f88bc4d056ed626e8ec74357" capture-exit@^1.1.0: version "1.2.0" @@ -1968,8 +1968,8 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" electron-to-chromium@^1.3.11: - version "1.3.11" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.11.tgz#744761df1d67b492b322ce9aa0aba5393260eb61" + version "1.3.12" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.12.tgz#62f33e4a59b4855f0de4bb8972bf1b841b98b6d2" ember-ajax@^2.4.1: version "2.5.6" @@ -2379,6 +2379,15 @@ ember-runtime-enumerable-includes-polyfill@^2.0.0: ember-cli-babel "^6.0.0" ember-cli-version-checker "^1.1.6" +ember-sinon@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/ember-sinon/-/ember-sinon-0.7.0.tgz#41b83b5b1c71626db26e8ffb4a52cdab9c039a29" + dependencies: + broccoli-funnel "^1.1.0" + broccoli-merge-trees "^1.2.1" + ember-cli-babel "^5.1.7" + sinon "^2.1.0" + ember-source@^2.12.0-beta.1: version "2.13.2" resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-2.13.2.tgz#9fa9439a26515890981aa5d466f23da20adccff8" @@ -5071,12 +5080,6 @@ sane@^1.1.1, sane@^1.6.0: walker "~1.0.5" watch "~0.10.0" -sanitize-filename@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.1.tgz#612da1c96473fa02dccda92dcd5b4ab164a6772a" - dependencies: - truncate-utf8-bytes "^1.0.0" - semver@^4.1.0, semver@^4.3.1: version "4.3.6" resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da" @@ -5172,7 +5175,7 @@ simple-is@~0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/simple-is/-/simple-is-0.2.0.tgz#2abb75aade39deb5cc815ce10e6191164850baf0" -sinon@^2.3.2: +sinon@^2.1.0, sinon@^2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.3.2.tgz#c43a9c570f32baac1159505cfeed19108855df89" dependencies: @@ -5604,12 +5607,6 @@ trim-right@^1.0.0, trim-right@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" -truncate-utf8-bytes@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b" - dependencies: - utf8-byte-length "^1.0.1" - try-resolve@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/try-resolve/-/try-resolve-1.0.1.tgz#cfde6fabd72d63e5797cfaab873abbe8e700e912" @@ -5731,10 +5728,6 @@ username-sync@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/username-sync/-/username-sync-1.0.1.tgz#1cde87eefcf94b8822984d938ba2b797426dae1f" -utf8-byte-length@^1.0.1: - version "1.0.4" - resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61" - util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"