-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
4 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,27 @@ | ||
import commonPrefix from 'vault/utils/common-prefix'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Util | common prefix', function() { | ||
test('it returns empty string if there are no common prefixes', function(assert) { | ||
let secrets = ['asecret', 'secret2', 'secret3'].map(s => ({id: s})); | ||
let returned = commonPrefix(secrets); | ||
assert.equal(returned, '', 'returns an empty string'); | ||
}); | ||
|
||
test('it returns the longest prefix', function(assert) { | ||
let secrets = ['secret1', 'secret2', 'secret3'].map(s => ({id: s})); | ||
let returned = commonPrefix(secrets); | ||
assert.equal(returned, 'secret', 'finds secret prefix'); | ||
let greetings = ['hello-there', 'hello-hi', 'hello-howdy'].map(s => ({id: s})); | ||
returned = commonPrefix(greetings); | ||
assert.equal(returned, 'hello-', 'finds hello- prefix'); | ||
}); | ||
|
||
|
||
test('it can compare an attribute that is not "id" to calculate the longest prefix', function(assert) { | ||
let secrets = ['secret1', 'secret2', 'secret3'].map(s => ({name: s})); | ||
let returned = commonPrefix(secrets, 'name'); | ||
assert.equal(returned, 'secret', 'finds secret prefix from name attribute'); | ||
}); | ||
}); | ||
|