|
| 1 | +import { expect } from "chai"; |
| 2 | +import { createVueField, checkAttribute } from "../util"; |
| 3 | + |
| 4 | +import Vue from "vue"; |
| 5 | +import fieldFile from "src/fields/core/fieldFile.vue"; |
| 6 | + |
| 7 | +Vue.component("fieldFile", fieldFile); |
| 8 | + |
| 9 | +let el, vm, field; |
| 10 | + |
| 11 | +function createField(test, schema = {}, model = null, disabled = false, options) { |
| 12 | + [el, vm, field] = createVueField(test, "fieldFile", schema, model, disabled, options); |
| 13 | +} |
| 14 | + |
| 15 | +describe("fieldFile.vue", function () { |
| 16 | + |
| 17 | + describe("check template", () => { |
| 18 | + let schema = { |
| 19 | + type: "file", |
| 20 | + label: "Upload", |
| 21 | + inputName: "testupload", |
| 22 | + placeholder: "Field placeholder", |
| 23 | + readonly: false, |
| 24 | + required: false, |
| 25 | + disabled: false, |
| 26 | + multiple: true, |
| 27 | + accept: "image/*" |
| 28 | + }; |
| 29 | + let model = {}; |
| 30 | + let attributes = ["disabled", "placeholder", "readonly"]; |
| 31 | + let input; |
| 32 | + |
| 33 | + before(() => { |
| 34 | + createField(this, schema, model, false); |
| 35 | + input = el.getElementsByTagName("input")[0]; |
| 36 | + field.schema.inputType = "file"; |
| 37 | + }); |
| 38 | + |
| 39 | + it("should contain an input text element", () => { |
| 40 | + expect(field).to.be.exist; |
| 41 | + expect(field.$el).to.be.exist; |
| 42 | + |
| 43 | + expect(input).to.be.defined; |
| 44 | + expect(input.type).to.be.equal("file"); |
| 45 | + expect(input.classList.contains("form-control")).to.be.true; |
| 46 | + }); |
| 47 | + |
| 48 | + describe("check optional attribute", () => { |
| 49 | + attributes.forEach(function (name) { |
| 50 | + it("should set " + name, function (done) { |
| 51 | + checkAttribute(name, vm, input, field, schema, done); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should set name", () => { |
| 56 | + expect(input.name).to.be.equal("testupload"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should change name", () => { |
| 60 | + expect(input.name).to.be.equal("testupload"); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should set required", () => { |
| 64 | + expect(input.required).to.be.false; |
| 65 | + }); |
| 66 | + |
| 67 | + it("should set multiple", () => { |
| 68 | + expect(input.multiple).to.be.exist; |
| 69 | + }); |
| 70 | + |
| 71 | + it("should set accept", () => { |
| 72 | + expect(input.accept).to.be.equal("image/*"); |
| 73 | + }); |
| 74 | + |
| 75 | + }); |
| 76 | + |
| 77 | + }); |
| 78 | +}); |
0 commit comments