-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #93 - vikram7:vr-add-classify, r=poteto
Add classify helper The PR adds a `classify` helper per issue https://github.com/DockYard/ember-composable-helpers/issues/67
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
const { | ||
Helper: { helper }, | ||
String: { classify: _classify } | ||
} = Ember; | ||
|
||
export function classify([string]) { | ||
string = string || ''; | ||
return _classify(string); | ||
} | ||
|
||
export default helper(classify); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, classify } from 'ember-composable-helpers/helpers/classify'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('classify', 'Integration | Helper | {{classify}}', { | ||
integration: true | ||
}); | ||
|
||
test('It converts camelCase correctly', function(assert) { | ||
this.render(hbs`{{classify "andAnother"}}`); | ||
|
||
let expected = 'AndAnother'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'classifies camelCased strings'); | ||
}); | ||
|
||
test('It converts underscored strings correctly', function(assert) { | ||
this.render(hbs`{{classify "harry_potter"}}`); | ||
|
||
let expected = 'HarryPotter'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'classifies underscored strings'); | ||
}); | ||
|
||
test('It converts spaces in strings correctly', function(assert) { | ||
this.render(hbs`{{classify "age is foolish and forgetful when it underestimates youth"}}`); | ||
|
||
let expected = 'AgeIsFoolishAndForgetfulWhenItUnderestimatesYouth'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'classifies strings with spaces'); | ||
}); | ||
|
||
test('It correctly handles empty string input', function(assert) { | ||
this.render(hbs`{{classify ""}}`); | ||
|
||
let expected = ''; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'renders empty string if input is empty string'); | ||
}); | ||
|
||
test('It correctly handles undefined input', function(assert) { | ||
this.render(hbs`{{classify undefined}}`); | ||
|
||
let expected = ''; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'renders empty string if undefined input'); | ||
}); |