From 0b33647969e7ea6cb6a2aed0a8d5341c4d68902c Mon Sep 17 00:00:00 2001 From: Ray Nicholus Date: Sat, 25 Oct 2014 04:15:52 +0000 Subject: [PATCH] test(validation): validation tests Also update the docs. closes #19 --- .jshintrc | 1 + file-input.html | 11 +++++++++ test/unit/file-input-spec.js | 44 +++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index cec980b..ef7fbf7 100644 --- a/.jshintrc +++ b/.jshintrc @@ -50,6 +50,7 @@ "describe", "document", "expect", + "jasmine", "navigator", "FrameGrab", "it", diff --git a/file-input.html b/file-input.html index 75efe09..ad9acd1 100644 --- a/file-input.html +++ b/file-input.html @@ -13,6 +13,17 @@ Now, a new, better, evolved (and evolving) element to take its place: ``! +#### `` integrates perfectly with ``! +Simply include a `` in [an ``](https://github.com/garstasio/ajax-form), +ensure the `name` attribute is present on the ``, and the `` +includes an `enctype` attriute with a value of `multipart/form-data`. Any valid +files will be sent along with the other form fields! + +If you incoude a `required` attribute on the ``, `` will +even prevent the form from being submitted if there isn't at least one valid +file selected! Note that the validation of custom elements, such as ``, +will first be possible in [`` 1.3.0](https://github.com/garstasio/ajax-form/issues/6). + __Don't forget to [vulcanize](http://www.polymer-project.org/articles/concatenating-web-components.html) your main/parent HTML file before deploying into production. This will ensure that all of your HTML imports are concatenated into one file.__ diff --git a/test/unit/file-input-spec.js b/test/unit/file-input-spec.js index a7397de..f955083 100644 --- a/test/unit/file-input-spec.js +++ b/test/unit/file-input-spec.js @@ -12,7 +12,9 @@ describe("file-input custom element tests", function() { fileInput: fileInputEl }, - fire: function() {} + fire: function() {}, + + invalidText: "not valid!" }; this.fileInputEl = fileInputEl; @@ -264,5 +266,45 @@ describe("file-input custom element tests", function() { expect(this.customElementInstance.files).toEqual(expectedValid); expect(this.customElementInstance.invalid).toEqual(expectedInvalid); }); + + it("marks the element as invalid on load if `required` attribute exists", function() { + var delegateInputEl, + fakeParent = jasmine.createSpyObj("fakeParent", ["insertBefore"]); + + this.customElementInstance.parentNode = fakeParent; + fakeParent.insertBefore.and.callFake(function(delegateInput, customEl) { + delegateInputEl = delegateInput; + + expect(delegateInput.tagName.toLowerCase()).toEqual("input"); + expect(delegateInputEl.validity.valid).toBe(true); + }); + + this.customElementInstance.files = []; + this.customElementInstance.required = ""; + + fileInput.domReady.call(this.customElementInstance); + expect(delegateInputEl.validity.valid).toBe(false); + expect(delegateInputEl.customElementRef).toEqual(this.customElementInstance); + }); + + it("marks the element as valid on load if `required` attribute exists once it is truly valid", function() { + var delegateInputEl, + fakeParent = jasmine.createSpyObj("fakeParent", ["insertBefore"]); + + this.customElementInstance.parentNode = fakeParent; + fakeParent.insertBefore.and.callFake(function(delegateInput, customEl) { + delegateInputEl = delegateInput; + }); + + this.customElementInstance.files = []; + this.customElementInstance.required = ""; + + fileInput.domReady.call(this.customElementInstance); + + this.customElementInstance.$.fileInput.files = [{name: "pic.jpg", size: 1000}]; + fileInput.changeHandler.call(this.customElementInstance); + + expect(delegateInputEl.validity.valid).toBe(true); + }); }); }); \ No newline at end of file