mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
adds unit tests for SearchTextField
This commit is contained in:
parent
f91cb11666
commit
965fb78b06
1 changed files with 45 additions and 0 deletions
45
test/javascripts/views/search_text_field_test.js
Normal file
45
test/javascripts/views/search_text_field_test.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
var view;
|
||||||
|
|
||||||
|
var placeholderUsesKeyAndContext = function(key, context) {
|
||||||
|
var placeholder = view.get("placeholder");
|
||||||
|
equal(placeholder.key, key, "placeholder contains correct message");
|
||||||
|
deepEqual(placeholder.context, context, "correct parameters are passed to the message");
|
||||||
|
};
|
||||||
|
|
||||||
|
module("Discourse.SearchTextField", {
|
||||||
|
setup: function() {
|
||||||
|
sinon.stub(I18n, "t", function(key, context) {
|
||||||
|
return {key: key, context: context};
|
||||||
|
});
|
||||||
|
|
||||||
|
view = Discourse.SearchTextField.create();
|
||||||
|
},
|
||||||
|
|
||||||
|
teardown: function() {
|
||||||
|
I18n.t.restore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats placeholder correctly when no searchContext is provided", function() {
|
||||||
|
placeholderUsesKeyAndContext("search.placeholder", undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats placeholder correctly when user searchContext is provided", function() {
|
||||||
|
view.set("searchContext", {
|
||||||
|
type: "user",
|
||||||
|
user: {
|
||||||
|
username: "userName"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
placeholderUsesKeyAndContext("search.prefer.user", {username: "userName"});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats placeholder correctly when category searchContext is provided", function() {
|
||||||
|
view.set("searchContext", {
|
||||||
|
type: "category",
|
||||||
|
category: {
|
||||||
|
name: "categoryName"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
placeholderUsesKeyAndContext("search.prefer.category", {category: "categoryName"});
|
||||||
|
});
|
Loading…
Reference in a new issue