Skip to content

Commit

Permalink
style: auto-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Jan 20, 2022
1 parent f2ee9c3 commit 5a7c5ea
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 66 deletions.
27 changes: 19 additions & 8 deletions addon/validators/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export default ValidatorsMessages.extend({
},

_warn(msg, test, meta) {
if (this._config && get(this._config, 'intl_cp_validations.suppressWarnings')) {
if (
this._config &&
get(this._config, 'intl_cp_validations.suppressWarnings')
) {
return;
}

Expand All @@ -42,9 +45,13 @@ export default ValidatorsMessages.extend({
if (intl.exists(key)) {
return intl.t(key, options);
} else if (foundCustom) {
this._warn(`Custom descriptionKey '${key}' provided but does not exist in intl translations.`, false, {
id: 'ember-intl-cp-validations-missing-custom-key'
});
this._warn(
`Custom descriptionKey '${key}' provided but does not exist in intl translations.`,
false,
{
id: 'ember-intl-cp-validations-missing-custom-key',
}
);
}
}

Expand All @@ -59,10 +66,14 @@ export default ValidatorsMessages.extend({
return this.formatMessage(intl.t(key, options));
}

this._warn(`[ember-intl-cp-validations] Missing translation for validation key: ${key}\nhttp://offirgolan.github.io/ember-cp-validations/docs/messages/index.html`, false, {
id: 'ember-intl-cp-validations-missing-translation'
});
this._warn(
`[ember-intl-cp-validations] Missing translation for validation key: ${key}\nhttp://offirgolan.github.io/ember-cp-validations/docs/messages/index.html`,
false,
{
id: 'ember-intl-cp-validations-missing-translation',
}
);

return this._super(...arguments);
}
},
});
44 changes: 32 additions & 12 deletions tests/acceptance/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import startApp from '../helpers/start-app';

let application;

const { run:emberRun, RSVP } = Ember;
const { run: emberRun, RSVP } = Ember;

function contains(selector, string, assert) {
const element = find(selector)[0];
Expand All @@ -25,7 +25,7 @@ module('Acceptance: Smoke', {
if (application) {
emberRun(application, 'destroy');
}
}
},
});

test('basic translations', (assert) => {
Expand All @@ -35,12 +35,16 @@ test('basic translations', (assert) => {
andThen(() => {
contains('.email-validation', `This field can't be blank`, assert);

fillIn('#email', 'you@example.com').then(function() {
fillIn('#email', 'you@example.com').then(function () {
contains('.email-validation', ``, assert);
});

fillIn('#email', 'invalid-email').then(function() {
contains('.email-validation', `This field must be a valid email address`, assert);
fillIn('#email', 'invalid-email').then(function () {
contains(
'.email-validation',
`This field must be a valid email address`,
assert
);
});
});
});
Expand All @@ -53,7 +57,7 @@ test('inline message', (assert) => {
andThen(() => {
contains('.password-validation', `This field can't be blank`, assert);

fillIn('#password', 'err').then(function() {
fillIn('#password', 'err').then(function () {
contains('.password-validation', `oops, length is invalid`, assert);
done();
});
Expand All @@ -68,13 +72,21 @@ test('translations with custom description', (assert) => {

andThen(() => {
contains('.email-validation', `This field can't be blank`, assert);
contains('.emailConfirmation-validation', `This field can't be blank`, assert);
contains(
'.emailConfirmation-validation',
`This field can't be blank`,
assert
);

RSVP.all([
fillIn('#email', 'foo@bar.com'),
fillIn('#emailConfirmation', 'xx@bar.com')
]).then(function() {
contains('.emailConfirmation-validation', `Email addresses doesn't match email`, assert);
fillIn('#emailConfirmation', 'xx@bar.com'),
]).then(function () {
contains(
'.emailConfirmation-validation',
`Email addresses doesn't match email`,
assert
);
done();
});
});
Expand All @@ -84,14 +96,22 @@ test('translations with descriptionKey', (assert) => {
visit('/');

andThen(() => {
contains('.username-validation', `oops, Username length is invalid`, assert);
contains(
'.username-validation',
`oops, Username length is invalid`,
assert
);
});
});

test('translation with messageKey', (assert) => {
visit('/');

andThen(() => {
contains('.passwordConfirmation-validation', `Passwords doesn't match`, assert);
contains(
'.passwordConfirmation-validation',
`Passwords doesn't match`,
assert
);
});
});
12 changes: 6 additions & 6 deletions tests/dummy/app/formats.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var hhmmss = {
hour: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
second: 'numeric',
};

export default {
time: {
hhmmss: hhmmss
hhmmss: hhmmss,
},
date: {
hhmmss: hhmmss
hhmmss: hhmmss,
},
number: {
EUR: { style: 'currency', currency: 'EUR' },
USD: { style: 'currency', currency: 'USD' }
}
USD: { style: 'currency', currency: 'USD' },
},
};
21 changes: 9 additions & 12 deletions tests/dummy/app/models/dummy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@ var Validations = buildValidations({
message: 'oops, {description} length is invalid',
descriptionKey: 'errors.usernameDescription',
min: 4,
max: 8
max: 8,
}),
password: [
validator('presence', true),
validator('length', {
message: 'oops, length is invalid',
min: 4,
max: 8
})
max: 8,
}),
],
passwordConfirmation: validator('confirmation', {
on: 'password',
messageKey: 'errors.passwordConfirmation'
messageKey: 'errors.passwordConfirmation',
}),
email: [
validator('presence', true),
validator('format', { type: 'email' })
],
email: [validator('presence', true), validator('format', { type: 'email' })],
emailConfirmation: [
validator('presence', true),
validator('confirmation', {
on: 'email',
description: 'Email addresses'
})
]
description: 'Email addresses',
}),
],
});

export default Ember.Object.extend(Validations, {
username: '',
password: '',
email: ''
email: '',
});
14 changes: 7 additions & 7 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Ember from 'ember';

export default Ember.Route.extend({
intl: Ember.inject.service(),
intl: Ember.inject.service(),

beforeModel() {
this.get('intl').setLocale('en-us');
},
beforeModel() {
this.intl.setLocale('en-us');
},

model() {
return this.container.lookup('model:dummy');
}
model() {
return this.container.lookup('model:dummy');
},
});
4 changes: 2 additions & 2 deletions tests/dummy/config/ember-intl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env node */
'use strict';

module.exports = function() {
module.exports = function () {
return {
inputPath: 'tests/dummy/translations'
inputPath: 'tests/dummy/translations',
};
};
42 changes: 23 additions & 19 deletions tests/unit/validators/messages-test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('ember-intl-cp-validations@validator:messages', 'Unit | Validators | messages', {
unit: true,
needs: [
'service:intl',
'config:environment',
'translation:en-us',
'cldr:en',
'ember-intl@adapter:default'
]
});

test('it exists', function(assert) {
moduleFor(
'ember-intl-cp-validations@validator:messages',
'Unit | Validators | messages',
{
unit: true,
needs: [
'service:intl',
'config:environment',
'translation:en-us',
'cldr:en',
'ember-intl@adapter:default',
],
}
);

test('it exists', function (assert) {
assert.expect(1);
assert.ok(this.subject());
});

test('suppressWarnings set to true', function(assert) {
test('suppressWarnings set to true', function (assert) {
assert.expect(1);

this.register('config:environment', {
intl_cp_validations: {
suppressWarnings: true
}
suppressWarnings: true,
},
});

this.inject.service('intl');
Expand All @@ -32,14 +36,14 @@ test('suppressWarnings set to true', function(assert) {
const instance = this.subject({
warn() {
triggered = true;
}
},
});

instance.getMessageFor('foobarbaz');
assert.ok(!triggered);
assert.notOk(triggered);
});

test('suppressWarnings unset', function(assert) {
test('suppressWarnings unset', function (assert) {
assert.expect(1);

this.inject.service('intl');
Expand All @@ -48,7 +52,7 @@ test('suppressWarnings unset', function(assert) {
const instance = this.subject({
warn() {
assert.ok(true);
}
},
});

instance.getMessageFor('foobarbaz');
Expand Down

0 comments on commit 5a7c5ea

Please sign in to comment.