Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove deprecations to support ember 4.x #90

Merged
merged 8 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:ember/recommended',
// 'plugin:prettier/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
rules: {
'ember/new-module-imports': 'off',
'ember/no-get': 'off',
'no-undef': 'off',
},
rules: {},
overrides: [
// node files
{
Expand Down Expand Up @@ -52,14 +48,7 @@ module.exports = {
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
'ember/no-restricted-resolver-tests': 'off',
'ember/no-test-and-then': 'off',
'ember/no-test-module-for': 'off',
'ember/prefer-ember-test-helpers': 'off',
'qunit/no-arrow-tests': 'off',
'qunit/no-negated-ok': 'off',
},
rules: {},
},
],
};
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- master
pull_request: {}

concurrency:
Expand Down Expand Up @@ -63,7 +62,7 @@ jobs:
- ember-release
- ember-beta
- ember-canary
# - embroider-safe
- embroider-safe
# - embroider-optimized

steps:
Expand Down
5 changes: 1 addition & 4 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

module.exports = {
extends: 'recommended',
rules: {
'no-curly-component-invocation': false,
'no-implicit-this': false,
},
rules: {},
};
33 changes: 20 additions & 13 deletions addon/validators/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { inject as service } from '@ember/service';
import { warn } from '@ember/debug';
import { getOwner } from '@ember/application';
import { isEmpty } from '@ember/utils';
import { get } from '@ember/object';

export default ValidatorsMessages.extend({
intl: service(),
Expand All @@ -20,16 +19,16 @@ export default ValidatorsMessages.extend({
},

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

warn(msg, test, meta);
},

getDescriptionFor(attribute, options = {}) {
let intl = get(this, 'intl');
let key = `${get(this, 'prefix')}.description`;
let intl = this.intl;
let key = `${this.prefix}.description`;
let foundCustom;

if (!isEmpty(options.descriptionKey)) {
Expand All @@ -43,27 +42,35 @@ 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',
}
);
}
}

return this._super(...arguments);
},

getMessageFor(type, options = {}) {
let key = get(options, 'messageKey') || `${get(this, 'prefix')}.${type}`;
let intl = get(this, 'intl');
let key = options.messageKey || `${this.prefix}.${type}`;
let intl = this.intl;

if (intl && intl.exists(key)) {
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}\nhttps://adopted-ember-addons.github.io/ember-cp-validations/docs/messages/index.html`,
false,
{
id: 'ember-intl-cp-validations-missing-translation',
}
);

return this._super(...arguments);
}
},
});
8 changes: 8 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': '~4.0.0',
'ember-auto-import': '^2',
webpack: '^5',
},
},
},
Expand All @@ -36,6 +38,8 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': await getChannelURL('release'),
'ember-auto-import': '^2',
webpack: '^5',
},
},
},
Expand All @@ -44,6 +48,8 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': await getChannelURL('beta'),
'ember-auto-import': '^2',
webpack: '^5',
},
},
},
Expand All @@ -52,6 +58,8 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': await getChannelURL('canary'),
'ember-auto-import': '^2',
webpack: '^5',
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"test:all": "ember try:each"
},
"dependencies": {
"ember-cli-babel": "^7.26.10",
"ember-getowner-polyfill": "^2.0.1"
"ember-cli-babel": "^7.26.10"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
Expand All @@ -59,7 +58,6 @@
"ember-intl": "^5.7.2",
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-open-browser": "^0.5.1",
"ember-page-title": "^6.2.2",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
Expand Down
13 changes: 8 additions & 5 deletions tests/acceptance/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { module, test } from 'qunit';
module('Acceptance: Smoke', function (hooks) {
setupApplicationTest(hooks);

test('basic translations', async (assert) => {
test('basic translations', async function (assert) {
assert.expect(3);
await visit('/');

Expand All @@ -20,7 +20,7 @@ module('Acceptance: Smoke', function (hooks) {
.hasText(`This field must be a valid email address`);
});

test('inline message', async (assert) => {
test('inline message', async function (assert) {
assert.expect(2);
await visit('/');

Expand All @@ -30,7 +30,7 @@ module('Acceptance: Smoke', function (hooks) {
assert.dom('.password-validation').hasText(`oops, length is invalid`);
});

test('translations with custom description', async (assert) => {
test('translations with custom description', async function (assert) {
assert.expect(3);
await visit('/');

Expand All @@ -46,17 +46,20 @@ module('Acceptance: Smoke', function (hooks) {
.hasText(`Email addresses doesn't match email`);
});

test('translations with descriptionKey', async (assert) => {
test('translations with descriptionKey', async function (assert) {
await visit('/');

assert
.dom('.username-validation')
.hasText(`oops, Username length is invalid`);
});

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

await fillIn('#password', '1234');
await fillIn('#password', '12345');

assert
.dom('.passwordConfirmation-validation')
.hasText(`Passwords doesn't match`);
Expand Down
11 changes: 11 additions & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class extends Controller {
@action
update(attribute, event) {
let value = event.target.value;
this.model[attribute] = value;
return this.model[attribute];
}
}
34 changes: 17 additions & 17 deletions tests/dummy/app/models/dummy.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import Ember from 'ember';
import EmberObject from '@ember/object';
import { validator, buildValidations } from 'ember-cp-validations';
import { tracked } from '@glimmer/tracking';

var Validations = buildValidations({
username: validator('length', {
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: ''
});
export default class extends EmberObject.extend(Validations) {
@tracked email = '';
@tracked emailConfirmation = '';
@tracked password = '';
@tracked passwordConfirmation = '';
@tracked username = '';
}
21 changes: 11 additions & 10 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Ember from 'ember';
import Route from '@ember/routing/route';
import { getOwner } from '@ember/application';
import { inject as service } from '@ember/service';

export default Ember.Route.extend({
intl: Ember.inject.service(),
export default class extends Route {
@service intl;

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

model() {
return getOwner(this).lookup('model:dummy');
}
});
model() {
return getOwner(this).lookup('model:dummy');
}
}
Loading