From c2e590b343b307f306a6496d43995c3ab52f4555 Mon Sep 17 00:00:00 2001 From: Wojciech Zawistowski Date: Thu, 19 Dec 2013 19:29:15 +0100 Subject: [PATCH] adds unit tests for Discourse.TextField --- test/javascripts/views/text_field_test.js | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/javascripts/views/text_field_test.js diff --git a/test/javascripts/views/text_field_test.js b/test/javascripts/views/text_field_test.js new file mode 100644 index 00000000000..1a8290a41ad --- /dev/null +++ b/test/javascripts/views/text_field_test.js @@ -0,0 +1,57 @@ +var appendTextFieldWithProperties = function(properties) { + var view = Discourse.TextField.create(properties); + Ember.run(function() { + view.appendTo(fixture()); + }); +}; + +var hasAttr = function($element, attrName, attrValue) { + equal($element.attr(attrName), attrValue, "'" + attrName + "' attribute is correctly rendered"); +}; + +var hasNoAttr = function($element, attrName) { + equal($element.attr(attrName), undefined, "'" + attrName + "' attribute is not rendered"); +}; + +module("Discourse.TextField"); + +test("renders correctly with no properties set", function() { + appendTextFieldWithProperties({}); + + var $input = fixture("input"); + hasAttr($input, "type", "text"); + hasAttr($input, "placeholder", ""); + hasNoAttr($input, "autocorrect"); + hasNoAttr($input, "autocapitalize"); + hasNoAttr($input, "autofocus"); +}); + +test("renders correctly with all allowed properties set", function() { + this.stub(I18n, "t").returnsArg(0); + + appendTextFieldWithProperties({ + autocorrect: "on", + autocapitalize: "off", + autofocus: "autofocus", + placeholderKey: "placeholder.i18n.key" + }); + + var $input = fixture("input"); + hasAttr($input, "type", "text"); + hasAttr($input, "placeholder", "placeholder.i18n.key"); + hasAttr($input, "autocorrect", "on"); + hasAttr($input, "autocapitalize", "off"); + hasAttr($input, "autofocus", "autofocus"); +}); + +test("is registered as helper", function() { + var view = Ember.View.create({ + template: Ember.Handlebars.compile("{{textField}}") + }); + + Ember.run(function() { + view.appendTo(fixture()); + }); + + ok(exists(fixture("input"))); +});