Skip to content

Commit 9438629

Browse files
committed
♻️ Run Codemods
1 parent 499c8cb commit 9438629

File tree

9 files changed

+427
-398
lines changed

9 files changed

+427
-398
lines changed
Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
1-
import { notEmpty } from '@ember/object/computed';
2-
import { A } from '@ember/array';
3-
import { isPresent, typeOf } from '@ember/utils';
4-
import { computed, get } from '@ember/object';
5-
import Component from '@ember/component';
6-
import layout from '../templates/components/twbs-errors-alert';
1+
import { A } from "@ember/array";
2+
import Component from "@ember/component";
3+
import { computed, get } from "@ember/object";
4+
import { notEmpty } from "@ember/object/computed";
5+
import { isPresent, typeOf } from "@ember/utils";
6+
7+
import layout from "../templates/components/twbs-errors-alert";
78

89
export default Component.extend({
9-
attributeBindings: ['role'],
10-
classNames: ['alert'],
10+
attributeBindings: ["role"],
11+
classNames: ["alert"],
1112
/**
1213
* Prepare a copy of the errors that include/exclude only the fields specified or returns all the errors.
1314
*/
14-
errors: computed('_excludesArray.[]', '_includesArray.[]', '[email protected]', /*'model.errors.[]', 'model.errors.length', */function () {
15-
const excludedFields = this.get('_excludesArray');
16-
if (isPresent(excludedFields)) {
17-
const filteredErrors = A();
18-
if (isPresent(this.get('model.errors'))) {
19-
this.get('model.errors').forEach((error) => {
20-
if (!excludedFields.includes(get(error, 'attribute'))) {
21-
filteredErrors.pushObject(get(error, 'message'));
22-
}
23-
});
24-
}
25-
return filteredErrors;
26-
}
27-
if (isPresent(this.get('_includesArray'))) {
28-
const filteredErrors = A();
29-
const modelErrors = this.get('model.errors');
30-
this.get('_includesArray').forEach((field) => {
31-
if (isPresent(modelErrors)) {
32-
modelErrors.forEach((error) => {
33-
if (field === get(error, 'attribute')) {
34-
filteredErrors.pushObject(get(error, 'message'));
15+
errors: computed(
16+
"_excludesArray.[]",
17+
"_includesArray.[]",
18+
19+
/*'model.errors.[]', 'model.errors.length', */ function () {
20+
const excludedFields = this.get("_excludesArray");
21+
if (isPresent(excludedFields)) {
22+
const filteredErrors = A();
23+
if (isPresent(this.get("model.errors"))) {
24+
this.get("model.errors").forEach((error) => {
25+
if (!excludedFields.includes(get(error, "attribute"))) {
26+
filteredErrors.pushObject(get(error, "message"));
3527
}
3628
});
3729
}
38-
});
39-
return filteredErrors;
30+
return filteredErrors;
31+
}
32+
if (isPresent(this.get("_includesArray"))) {
33+
const filteredErrors = A();
34+
const modelErrors = this.get("model.errors");
35+
this.get("_includesArray").forEach((field) => {
36+
if (isPresent(modelErrors)) {
37+
modelErrors.forEach((error) => {
38+
if (field === get(error, "attribute")) {
39+
filteredErrors.pushObject(get(error, "message"));
40+
}
41+
});
42+
}
43+
});
44+
return filteredErrors;
45+
}
46+
return this.get("model.errors.messages");
4047
}
41-
return this.get('model.errors.messages');
42-
}),
43-
'errorsPresent?': notEmpty('errors'),
48+
),
49+
"errorsPresent?": notEmpty("errors"),
4450
/**
4551
* The camel-cased field names to exclude from the computed errors collection. Takes precedence over `includes`.
4652
*/
@@ -50,27 +56,27 @@ export default Component.extend({
5056
* is present.
5157
*/
5258
includes: undefined,
53-
isVisible: notEmpty('errors'),
59+
isVisible: notEmpty("errors"),
5460
layout,
5561
/**
5662
* REQUIRED.
5763
*/
5864
model: undefined,
59-
role: 'alert',
60-
_excludesArray: computed('excludes', function () {
61-
return this._convertToArray(this.get('excludes'));
65+
role: "alert",
66+
_excludesArray: computed("excludes", function () {
67+
return this._convertToArray(this.excludes);
6268
}),
63-
_includesArray: computed('includes', function () {
64-
return this._convertToArray(this.get('includes'));
69+
_includesArray: computed("includes", function () {
70+
return this._convertToArray(this.includes);
6571
}),
6672
_convertToArray(object) {
67-
if ('array' === typeOf(object)) {
73+
if ("array" === typeOf(object)) {
6874
return A().pushObjects(object);
6975
}
7076
if (isPresent(object)) {
7177
// assume a String and split it on comma
72-
return A().pushObjects(String(object).split(','));
78+
return A().pushObjects(String(object).split(","));
7379
}
7480
return A();
75-
}
81+
},
7682
});

addon/components/twbs-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Component.extend({
1414
layout,
1515
tagName: "form",
1616
didInsertElement() {
17-
const resetAction = this.get("reset");
17+
const resetAction = this.reset;
1818
if (isPresent(resetAction)) {
1919
this.$()
2020
.off("reset.twbs-form")

tests/dummy/app/components/cannot-submit-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import layout from '../templates/components/cannot-submit-form';
55
export default Component.extend({
66
actions: {
77
submit() {
8-
this.get('results').pushObject('Submitted On-Enter');
8+
this.results.pushObject('Submitted On-Enter');
99
return true;
1010
}
1111
},

tests/dummy/app/models/demo-model.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export default DS.Model.extend({
77
someNumber: DS.attr('number'),
88
someString: DS.attr('string'),
99
_addErrorToAnotherString: observer('anotherString', function () {
10-
if (this.get('anotherString') === 'error') {
11-
this.get('errors')._add('anotherString', 'Now change the text to error2 to add a second');
12-
} else if (this.get('anotherString') === 'error2') {
13-
this.get('errors')._add('anotherString', 'Another error, take it easy');
10+
if (this.anotherString === 'error') {
11+
this.errors._add('anotherString', 'Now change the text to error2 to add a second');
12+
} else if (this.anotherString === 'error2') {
13+
this.errors._add('anotherString', 'Another error, take it easy');
1414
} else {
15-
this.get('errors')._remove('anotherString');
15+
this.errors._remove('anotherString');
1616
}
1717
})
1818
});

tests/dummy/app/routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default Route.extend({
1010
}
1111
},
1212
model() {
13-
const demoModel = this.get('store').createRecord('demo-model');
13+
const demoModel = this.store.createRecord('demo-model');
1414
demoModel.get('errors')._add('someBoolean', 'An error message about the someBoolean attribute');
1515
demoModel.get('errors')._add('someNumber', 'An error message about the someNumber attribute');
1616
demoModel.get('errors')._add('someString', 'An error message about the someString attribute');
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { moduleForComponent, test } from 'ember-qunit';
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render, find } from '@ember/test-helpers';
24
import hbs from 'htmlbars-inline-precompile';
35

4-
moduleForComponent('hidden-submit', 'Integration | Component | hidden submit', {
5-
integration: true
6-
});
6+
module('Integration | Component | hidden submit', function(hooks) {
7+
setupRenderingTest(hooks);
78

8-
test("button is classed with `hidden-submit` and bootstrap's `sr-only`", function (assert) {
9-
this.render(hbs`{{hidden-submit}}`);
10-
assert.ok(this.$('button').hasClass('hidden-submit'));
11-
assert.ok(this.$('button').hasClass('sr-only'));
12-
});
9+
test("button is classed with `hidden-submit` and bootstrap's `sr-only`", async function(assert) {
10+
await render(hbs`{{hidden-submit}}`);
11+
assert.ok(find('button').classList.contains('hidden-submit'));
12+
assert.ok(find('button').classList.contains('sr-only'));
13+
});
1314

14-
test('button contains html comment concerning its purpose', function (assert) {
15-
this.render(hbs`{{hidden-submit}}`);
16-
assert.equal(this.$('button').html().trim(),
17-
'<!-- This hidden submit button is used to help trigger form submits by pressing enter while focused on inputs -->');
15+
test('button contains html comment concerning its purpose', async function(assert) {
16+
await render(hbs`{{hidden-submit}}`);
17+
assert.equal(find('button').innerHTML.trim(),
18+
'<!-- This hidden submit button is used to help trigger form submits by pressing enter while focused on inputs -->');
19+
});
1820
});

0 commit comments

Comments
 (0)