From 682e6a658e88ebc168f63b59636656adf6ed716e Mon Sep 17 00:00:00 2001 From: jelhan Date: Thu, 28 Jan 2016 12:34:56 +0100 Subject: [PATCH] fix coding style errors > helpers/poll-has-users.js should pass jscs. > requireSemicolons: Missing semicolon after statement at helpers/poll-has-users.js is incostitent with JSHint which complains about this semicolon other ones should be fixed by rewrite of create/options --- .../acceptance/participate-in-a-poll-test.js | 8 ++-- tests/acceptance/view-poll-test.js | 36 ++++++++-------- tests/helpers/poll-has-answers.js | 6 +-- tests/helpers/poll-has-options.js | 4 +- tests/helpers/poll-participate.js | 4 +- tests/helpers/select-dates.js | 2 +- tests/helpers/server-get-polls.js | 42 +++++++++---------- tests/helpers/server-post-polls.js | 6 +-- tests/helpers/server-post-users.js | 8 ++-- tests/helpers/switch-tab.js | 2 +- tests/integration/create-a-poll-test.js | 24 +++++------ tests/integration/legacy-support-test.js | 14 +++---- tests/integration/translations-test.js | 32 +++++++------- tests/unit/components/fm-input-group-test.js | 2 +- tests/unit/controllers/error-test.js | 4 +- .../controllers/poll/participation-test.js | 4 +- tests/unit/services/encryption-test.js | 4 +- tests/unit/validators/time-test.js | 14 +++---- .../unit/validators/valid-collection-test.js | 2 +- 19 files changed, 108 insertions(+), 110 deletions(-) diff --git a/tests/acceptance/participate-in-a-poll-test.js b/tests/acceptance/participate-in-a-poll-test.js index 49c2ffe..9e085bc 100644 --- a/tests/acceptance/participate-in-a-poll-test.js +++ b/tests/acceptance/participate-in-a-poll-test.js @@ -116,8 +116,8 @@ test('participate in a poll which does not force an answer to all options', func andThen(function() { assert.equal(currentPath(), 'poll.evaluation'); - pollHasUsersCount(assert, 1, "user is added to user selections table"); - pollHasUser(assert, "Karl Käfer", [t("answerTypes.yes.label"), ""]); + pollHasUsersCount(assert, 1, 'user is added to user selections table'); + pollHasUser(assert, 'Karl Käfer', [t('answerTypes.yes.label'), '']); }); }); }); @@ -148,8 +148,8 @@ test('participate in a poll which allows anonymous participation', function(asse andThen(function() { assert.equal(currentPath(), 'poll.evaluation'); - pollHasUsersCount(assert, 1, "user is added to user selections table"); - pollHasUser(assert, "", [t("answerTypes.yes.label"), t("answerTypes.no.label")]); + pollHasUsersCount(assert, 1, 'user is added to user selections table'); + pollHasUser(assert, '', [t('answerTypes.yes.label'), t('answerTypes.no.label')]); }); }); }); diff --git a/tests/acceptance/view-poll-test.js b/tests/acceptance/view-poll-test.js index f8d8247..deba6ea 100644 --- a/tests/acceptance/view-poll-test.js +++ b/tests/acceptance/view-poll-test.js @@ -89,7 +89,7 @@ test('view a poll with dates and times', function(assert) { { title: '2015-12-12T13:13:00.000Z' }, { title: '2016-01-01T11:11:00.000Z' } ], - timezone: timezone + timezone }, encryptionKey ); }); @@ -107,15 +107,14 @@ test('view a poll with dates and times', function(assert) { }); test('view a poll while timezone differs from the one poll got created in and choose local timezone', function(assert) { - var id = 'test', - encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789', - timezoneLocal = jstz.determine().name(), - timezonePoll; + const id = 'test'; + const encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789'; + const timezoneLocal = jstz.determine().name(); + let timezonePoll; - if(timezoneLocal !== 'America/Caracas') { + if (timezoneLocal !== 'America/Caracas') { timezonePoll = 'America/Caracas'; - } - else { + } else { timezonePoll = 'Europe/Moscow'; } @@ -135,7 +134,7 @@ test('view a poll while timezone differs from the one poll got created in and ch visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() { stop(); - Ember.run.later(function(){ + Ember.run.later(function() { start(); assert.equal( @@ -153,7 +152,7 @@ test('view a poll while timezone differs from the one poll got created in and ch ]); stop(); - Ember.run.later(function(){ + Ember.run.later(function() { start(); assert.equal( @@ -168,15 +167,14 @@ test('view a poll while timezone differs from the one poll got created in and ch }); test('view a poll while timezone differs from the one poll got created in and choose poll timezone', function(assert) { - var id = 'test', - encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789', - timezoneLocal = jstz.determine().name(), - timezonePoll; + const id = 'test'; + const encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789'; + const timezoneLocal = jstz.determine().name(); + let timezonePoll; - if(timezoneLocal !== 'America/Caracas') { + if (timezoneLocal !== 'America/Caracas') { timezonePoll = 'America/Caracas'; - } - else { + } else { timezonePoll = 'Europe/Moscow'; } @@ -196,7 +194,7 @@ test('view a poll while timezone differs from the one poll got created in and ch visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() { stop(); - Ember.run.later(function(){ + Ember.run.later(function() { start(); assert.equal( @@ -214,7 +212,7 @@ test('view a poll while timezone differs from the one poll got created in and ch ]); stop(); - Ember.run.later(function(){ + Ember.run.later(function() { start(); assert.equal( diff --git a/tests/helpers/poll-has-answers.js b/tests/helpers/poll-has-answers.js index a4c9326..aef567c 100644 --- a/tests/helpers/poll-has-answers.js +++ b/tests/helpers/poll-has-answers.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export default Ember.Test.registerHelper('pollHasAnswers', function(app, assert, answers) { - const elBase = find('.participation .selections .form-group')[0]; + const [ elBase ] = find('.participation .selections .form-group'); assert.equal( find('.radio label', elBase).length, answers.length, @@ -9,9 +9,9 @@ export default Ember.Test.registerHelper('pollHasAnswers', function(app, assert, ); answers.forEach((answer, index) => { assert.equal( - find('.radio:nth-child(' + (index + 1) + ') label', elBase).text().trim(), + find(`.radio:nth-child(${index + 1}) label`, elBase).text().trim(), answer, - 'poll answer ' + index + ' is as expected' + `poll answer ${index} is as expected` ); }); }); diff --git a/tests/helpers/poll-has-options.js b/tests/helpers/poll-has-options.js index 08d91e1..f321e8b 100644 --- a/tests/helpers/poll-has-options.js +++ b/tests/helpers/poll-has-options.js @@ -11,9 +11,9 @@ export default Ember.Test.registerHelper('pollHasOptions', function(app, assert, expectedOptions.forEach((option, index) => { assert.equal( - find('.form-group:nth-child(' + (index + 1) + ') label.control-label', elBase).text().trim(), + find(`.form-group:nth-child(${index + 1}) label.control-label`, elBase).text().trim(), option, - 'poll option ' + index + ' is as expected' + `poll option ${index} is as expected` ); }); }); diff --git a/tests/helpers/poll-participate.js b/tests/helpers/poll-participate.js index 1b7ebae..5817733 100644 --- a/tests/helpers/poll-participate.js +++ b/tests/helpers/poll-participate.js @@ -9,9 +9,9 @@ export default Ember.Test.registerAsyncHelper('pollParticipate', function(app, n selections.forEach((selection, index) => { if (!Ember.isEmpty(selection)) { if (isFreeText) { - fillIn('.participation .selections .form-group:nth-child(' + (index + 1) + ') input', selection); + fillIn(`.participation .selections .form-group:nth-child(${index + 1}) input`, selection); } else { - click('.participation .selections .form-group:nth-child(' + (index + 1) + ') input[type="radio"][value="' + selection + '"]'); + click(`.participation .selections .form-group:nth-child(${index + 1}) input[type="radio"][value="${selection}"]`); } } }); diff --git a/tests/helpers/select-dates.js b/tests/helpers/select-dates.js index 3d4954b..1b4f0cf 100644 --- a/tests/helpers/select-dates.js +++ b/tests/helpers/select-dates.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export default Ember.Test.registerAsyncHelper('selectDates', function(app, datepickerElement, dates) { - var normalizedDates = dates.map((date) => { + const normalizedDates = dates.map((date) => { if (typeof date.toDate === 'function') { date = date.toDate(); } diff --git a/tests/helpers/server-get-polls.js b/tests/helpers/server-get-polls.js index e608d0d..bfbdce8 100644 --- a/tests/helpers/server-get-polls.js +++ b/tests/helpers/server-get-polls.js @@ -1,8 +1,8 @@ import Ember from 'ember'; /* global sjcl */ -export default function (attr, key) { - var defaultAttr = { +export default function(attr, key) { + const defaultAttr = { id: 'test', title: 'default title', description: 'default description', @@ -10,27 +10,27 @@ export default function (attr, key) { answerType: 'YesNo', answers: [ { - type: "yes", - labelTranslation: "answerTypes.yes.label", - icon: "glyphicon glyphicon-thumbs-up", - label: "Ja" + type: 'yes', + labelTranslation: 'answerTypes.yes.label', + icon: 'glyphicon glyphicon-thumbs-up', + label: 'Ja' }, { - type: "no", - labelTranslation: "answerTypes.no.label", - icon: "glyphicon glyphicon-thumbs-down", - label: "Nein" + type: 'no', + labelTranslation: 'answerTypes.no.label', + icon: 'glyphicon glyphicon-thumbs-down', + label: 'Nein' } ], options: [ { - title: "2017-12-24" + title: '2017-12-24' }, { - title: "2018-01-01" + title: '2018-01-01' } ], - creationDate: "2015-04-01T11:11:11.111Z", + creationDate: '2015-04-01T11:11:11.111Z', forceAnswer: true, anonymousUser: false, isDateTime: false, @@ -39,19 +39,19 @@ export default function (attr, key) { timezone: '', version: 'v0.3' }; - - var encrypt = function(prop) { + + const encrypt = function(prop) { return sjcl.encrypt( key, JSON.stringify(prop) ); }; - - var data = Ember.merge(defaultAttr, attr); - var users = data.users.map(function(user, index) { + let data = Ember.merge(defaultAttr, attr); + + const users = data.users.map(function(user, index) { return { - id: data.id + '_' + index, + id: `${data.id}_${index}`, creationDate: encrypt(user.creationDate), name: encrypt(user.name), poll: data.id, @@ -62,7 +62,7 @@ export default function (attr, key) { return [ 200, - { "Content-Type": "application/json" }, + { 'Content-Type': 'application/json' }, JSON.stringify({ poll: { id: data.id, @@ -78,7 +78,7 @@ export default function (attr, key) { isDateTime: encrypt(data.isDateTime), timezone: encrypt(data.timezone), expirationDate: encrypt(data.expirationDate), - users: users, + users, version: data.version } }) diff --git a/tests/helpers/server-post-polls.js b/tests/helpers/server-post-polls.js index 59ccbe3..98eb56d 100644 --- a/tests/helpers/server-post-polls.js +++ b/tests/helpers/server-post-polls.js @@ -1,9 +1,9 @@ -export default function (requestBody, id) { - var poll = JSON.parse(requestBody); +export default function(requestBody, id) { + let poll = JSON.parse(requestBody); poll.poll.id = id; return [ 200, - {"Content-Type": "application/json"}, + { 'Content-Type': 'application/json' }, JSON.stringify(poll) ]; } diff --git a/tests/helpers/server-post-users.js b/tests/helpers/server-post-users.js index d2a8a20..ab9e67c 100644 --- a/tests/helpers/server-post-users.js +++ b/tests/helpers/server-post-users.js @@ -1,13 +1,13 @@ -export default function (requestBody, id) { +export default function(requestBody, id) { if (id === null) { id = 1; } - - var poll = JSON.parse(requestBody); + + let poll = JSON.parse(requestBody); poll.user.id = id; return [ 200, - {"Content-Type": "application/json"}, + { 'Content-Type': 'application/json' }, JSON.stringify(poll) ]; } diff --git a/tests/helpers/switch-tab.js b/tests/helpers/switch-tab.js index df23b34..364050a 100644 --- a/tests/helpers/switch-tab.js +++ b/tests/helpers/switch-tab.js @@ -1,5 +1,5 @@ import Ember from 'ember'; export default Ember.Test.registerAsyncHelper('switchTab', function(app, tab) { - click('.nav-tabs .' + tab + ' a'); + click(`.nav-tabs .${tab} a`); }); diff --git a/tests/integration/create-a-poll-test.js b/tests/integration/create-a-poll-test.js index 223449a..008fa1e 100644 --- a/tests/integration/create-a-poll-test.js +++ b/tests/integration/create-a-poll-test.js @@ -1,32 +1,32 @@ -import Ember from "ember"; +import Ember from 'ember'; import { module, test } from 'qunit'; import startApp from '../helpers/start-app'; import moment from 'moment'; /* jshint proto: true */ -var application; +let application; module('Integration', { - beforeEach: function() { + beforeEach() { application = startApp(); moment.locale( application.__container__.lookup('service:i18n').get('locale') ); }, - afterEach: function() { + afterEach() { Ember.run(application, 'destroy'); } }); -test("create a default poll and participate", function(assert) { - var dates = +test('create a default poll and participate', function(assert) { + const dates = [ moment().add(1, 'day'), moment().add(1, 'week'), moment().add(1, 'month') ]; - var formattedDates = + const formattedDates = dates.map((date) => { return date.format( moment.localeData().longDateFormat('LLLL') @@ -39,25 +39,25 @@ test("create a default poll and participate", function(assert) { visit('/create').then(function() { click('button[type="submit"]'); - andThen(function(){ + andThen(function() { assert.equal(currentPath(), 'create.meta'); fillIn('.title input', 'default poll'); click('button[type="submit"]'); - andThen(function(){ + andThen(function() { assert.equal(currentPath(), 'create.options'); selectDates('#datepicker .ember-view', dates); click('button[type="submit"]'); - andThen(function(){ + andThen(function() { assert.equal(currentPath(), 'create.settings'); click('button[type="submit"]'); - andThen(function(){ + andThen(function() { assert.equal(currentPath(), 'poll.participation'); pollTitleEqual(assert, 'default poll'); @@ -65,7 +65,7 @@ test("create a default poll and participate", function(assert) { pollHasOptions(assert, formattedDates); pollHasUsersCount(assert, 0); pollParticipate('Max Hoelz', ['no', 'no', 'yes']); - andThen(function(){ + andThen(function() { assert.equal(currentPath(), 'poll.evaluation'); pollHasUsersCount(assert, 1); pollHasUser( diff --git a/tests/integration/legacy-support-test.js b/tests/integration/legacy-support-test.js index 5c1d35f..e84fae7 100644 --- a/tests/integration/legacy-support-test.js +++ b/tests/integration/legacy-support-test.js @@ -6,19 +6,19 @@ import startApp from 'croodle/tests/helpers/start-app'; let application; module('Integration | legacy support', { - beforeEach: function() { + beforeEach() { application = startApp(); }, - afterEach: function() { + afterEach() { Ember.run(application, 'destroy'); } }); test('show a default poll created with v0.3.0', function(assert) { - var id = 'JlHpRs0Pzi', - encryptionKey = '5MKFuNTKILUXw6RuqkAw6ooZw4k3mWWx98ZQw8vH', - timezone = 'Europe/Berlin'; + const id = 'JlHpRs0Pzi'; + const encryptionKey = '5MKFuNTKILUXw6RuqkAw6ooZw4k3mWWx98ZQw8vH'; + const timezone = 'Europe/Berlin'; visit(`/poll/${id}?encryptionKey=${encryptionKey}`); @@ -84,8 +84,8 @@ test('show a default poll created with v0.3.0', function(assert) { }); test('find a poll using free text created with v0.3.0', function(assert) { - var id = 'PjW3XwbuRc', - encryptionKey = 'Rre6dAGOYLW9gYKOP4LhX7Qwfhe5Th3je0uKDtyy'; + const id = 'PjW3XwbuRc'; + const encryptionKey = 'Rre6dAGOYLW9gYKOP4LhX7Qwfhe5Th3je0uKDtyy'; visit(`/poll/${id}?encryptionKey=${encryptionKey}`); diff --git a/tests/integration/translations-test.js b/tests/integration/translations-test.js index d6b23b2..2f830bd 100644 --- a/tests/integration/translations-test.js +++ b/tests/integration/translations-test.js @@ -8,9 +8,9 @@ moduleFor('service:i18n', 'Integration | translations', { // Replace this with your real tests. test('configuration is correct', function(assert) { - const i18n = this.subject(), - locales = i18n.get('locales'), - defaultLocale = config.i18n.defaultLocale; + const i18n = this.subject(); + const locales = i18n.get('locales'); + const { defaultLocale } = config.i18n; assert.ok(defaultLocale, 'default locale is set'); assert.ok(locales, 'there are locales'); @@ -18,10 +18,10 @@ test('configuration is correct', function(assert) { }); test('all locales have same amount of translation strings as default locale', function(assert) { - const i18n = this.subject(), - locales = i18n.get('locales'), - defaultLocale = config.i18n.defaultLocale, - defaultTranslations = new LocaleHelper(defaultLocale, i18n.get('container')).translations; + const i18n = this.subject(); + const locales = i18n.get('locales'); + const { defaultLocale } = config.i18n; + const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, i18n.get('container')); assert.expect((locales.length - 1) * 2); @@ -29,25 +29,25 @@ test('all locales have same amount of translation strings as default locale', fu if (locale === defaultLocale) { return; } - var translations = new LocaleHelper(locale, i18n.get('container')).translations; - assert.ok(translations, 'could retrive locale ' + locale); + const { translations } = new LocaleHelper(locale, i18n.get('container')); + assert.ok(translations, `could retrive locale ${locale}`); assert.equal( Object.keys(translations).length, Object.keys(defaultTranslations).length, - 'correct amount of translations for locale ' + locale + `correct amount of translations for locale ${locale}` ); }); }); test('all locales have same translation strings as default locale', function(assert) { - const i18n = this.subject(), - locales = i18n.get('locales'), - defaultLocale = config.i18n.defaultLocale, - defaultTranslations = new LocaleHelper(defaultLocale, i18n.get('container')).translations; + const i18n = this.subject(); + const locales = i18n.get('locales'); + const { defaultLocale } = config.i18n; + const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, i18n.get('container')); assert.expect( // count of non default locales * translation strings of default locale - ( locales.length - 1 ) * Object.keys(defaultTranslations).length + (locales.length - 1) * Object.keys(defaultTranslations).length ); Object.keys(defaultTranslations).map((translationString) => { @@ -59,7 +59,7 @@ test('all locales have same translation strings as default locale', function(ass i18n.set('locale', locale); assert.ok( i18n.exists(translationString), - 'translation for ' + translationString + ' exists in locale ' + locale + `translation for ${translationString} exists in locale ${locale}` ); }); }); diff --git a/tests/unit/components/fm-input-group-test.js b/tests/unit/components/fm-input-group-test.js index 84baeee..a42a6bc 100644 --- a/tests/unit/components/fm-input-group-test.js +++ b/tests/unit/components/fm-input-group-test.js @@ -10,7 +10,7 @@ test('it renders', function(assert) { assert.expect(2); // Creates the component instance - var component = this.subject(); + let component = this.subject(); assert.equal(component._state, 'preRender'); // Renders the component to the page diff --git a/tests/unit/controllers/error-test.js b/tests/unit/controllers/error-test.js index bce8bd1..83525cf 100644 --- a/tests/unit/controllers/error-test.js +++ b/tests/unit/controllers/error-test.js @@ -1,12 +1,12 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('controller:error', { +moduleFor('controller:error', 'Unit | Controller | error', { // Specify the other units that are required for this test. // needs: ['controller:foo'] }); // Replace this with your real tests. test('it exists', function(assert) { - var controller = this.subject(); + let controller = this.subject(); assert.ok(controller); }); diff --git a/tests/unit/controllers/poll/participation-test.js b/tests/unit/controllers/poll/participation-test.js index ca1a0d5..32ee790 100644 --- a/tests/unit/controllers/poll/participation-test.js +++ b/tests/unit/controllers/poll/participation-test.js @@ -1,12 +1,12 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('controller:poll/participation', { +moduleFor('controller:poll/participation', 'Unit | Controller | poll/participation', { // Specify the other units that are required for this test. // needs: ['controller:foo'] }); // Replace this with your real tests. test('it exists', function(assert) { - var controller = this.subject(); + let controller = this.subject(); assert.ok(controller); }); diff --git a/tests/unit/services/encryption-test.js b/tests/unit/services/encryption-test.js index 24a0801..6786548 100644 --- a/tests/unit/services/encryption-test.js +++ b/tests/unit/services/encryption-test.js @@ -1,12 +1,12 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('service:encryption', 'Unit | Service | encryption key', { +moduleFor('service:encryption', 'Unit | Service | encryption', { // Specify the other units that are required for this test. // needs: ['service:foo'] }); // Replace this with your real tests. test('it exists', function(assert) { - var service = this.subject(); + let service = this.subject(); assert.ok(service); }); diff --git a/tests/unit/validators/time-test.js b/tests/unit/validators/time-test.js index 286295c..2881f4f 100644 --- a/tests/unit/validators/time-test.js +++ b/tests/unit/validators/time-test.js @@ -5,44 +5,44 @@ moduleFor('validator:time', 'Unit | Validator | time', { }); test('HH:mm is treated as valid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(validator.validate('00:00')); assert.ok(validator.validate('23:59')); }); test('24:00 is invalid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(typeof validator.validate('24:00') === 'string'); }); test('00:60 is invalid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(typeof validator.validate('00:60') === 'string'); }); test('an empty string is invalid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(typeof validator.validate('') === 'string'); }); test('null is invalid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(typeof validator.validate(null) === 'string'); }); test('undefined is invalid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(typeof validator.validate(undefined) === 'string'); }); test('a valid time wrapped by spaces is valid', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(validator.validate(' 10:00 ')); }); diff --git a/tests/unit/validators/valid-collection-test.js b/tests/unit/validators/valid-collection-test.js index e4ae0dc..5b75f88 100644 --- a/tests/unit/validators/valid-collection-test.js +++ b/tests/unit/validators/valid-collection-test.js @@ -5,6 +5,6 @@ moduleFor('validator:valid-collection', 'Unit | Validator | valid-collection', { }); test('it works', function(assert) { - var validator = this.subject(); + let validator = this.subject(); assert.ok(validator); });