mirror of
https://github.com/tenrok/vue-tribute.git
synced 2026-06-08 17:52:25 +03:00
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
before_script:
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
sudo: false
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<input type="text" v-input-autosize v-model="foo" placeholder="Butts" />
|
||||
<input type="text" v-input-autosize v-model="foo" placeholder="A placeholder" />
|
||||
</template>
|
||||
<script>
|
||||
import Vue from "vue";
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
frameworks: ["browserify", "jasmine"],
|
||||
files: [
|
||||
"test/support/*.js",
|
||||
"test/**/*.spec.js"
|
||||
],
|
||||
preprocessors: {
|
||||
"src/**/*.js": ["browserify"],
|
||||
"test/**/*.spec.js": ["browserify"]
|
||||
},
|
||||
browsers: ["PhantomJS"],
|
||||
reporters: ["spec"],
|
||||
browserify: {
|
||||
transform: [["babelify", {
|
||||
presets: ["es2015"],
|
||||
plugins: ["transform-runtime"]
|
||||
}]],
|
||||
}
|
||||
});
|
||||
}
|
||||
+19
-2
@@ -17,7 +17,9 @@
|
||||
"build": "BUILD_ENV=cjs rollup -c",
|
||||
"build:umd": "BUILD_ENV=umd rollup -c",
|
||||
"example": "vbuild --dev -e example",
|
||||
"example:build": "vbuild -e example -t VueInputAutosize"
|
||||
"example:build": "vbuild -e example -t VueInputAutosize",
|
||||
"test": "karma start karma.conf.js --single-run true --auto-watch false",
|
||||
"watch-test": "karma start karma.conf.js --single-run false --auto-watch true"
|
||||
},
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
@@ -33,8 +35,23 @@
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.11.4",
|
||||
"babel-plugin-transform-runtime": "^6.9.0",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-es2015-rollup": "^1.1.1",
|
||||
"babel-runtime": "^6.9.2",
|
||||
"babelify": "^7.3.0",
|
||||
"browserify": "^13.0.1",
|
||||
"jasmine-core": "^2.4.1",
|
||||
"karma": "^1.1.1",
|
||||
"karma-browserify": "^5.1.0",
|
||||
"karma-jasmine": "^1.0.2",
|
||||
"karma-phantomjs-launcher": "^1.0.1",
|
||||
"karma-spec-reporter": "0.0.26",
|
||||
"phantomjs-prebuilt": "^2.1.7",
|
||||
"rollup": "^0.33.0",
|
||||
"rollup-plugin-babel": "^2.6.1"
|
||||
"rollup-plugin-babel": "^2.6.1",
|
||||
"vue": "^1.0.26",
|
||||
"watchify": "^3.7.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import Vue from "vue";
|
||||
import VueInputAutosize from "../src";
|
||||
|
||||
Vue.use(VueInputAutosize);
|
||||
|
||||
describe("vue-input-autosize", () => {
|
||||
it("has an install method for Vue.use()", () => {
|
||||
expect(typeof VueInputAutosize.install).toEqual("function");
|
||||
});
|
||||
it("creates the v-input-autosize directive", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text'>",
|
||||
}).$mount();
|
||||
|
||||
expect(typeof vm.$options.directives["input-autosize"]).toEqual("object");
|
||||
});
|
||||
it("sets the proper width according to the content of the input", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' value='Hello' v-el:test />"
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(33);
|
||||
done();
|
||||
}, 0)
|
||||
});
|
||||
it("uses the placeholder if there's no content to determine the width", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' value='' placeholder='Hello' v-el:test />"
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(33);
|
||||
done();
|
||||
}, 0)
|
||||
});
|
||||
it("increases the width of the input when text is added", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' v-model='msg' v-el:test />",
|
||||
data(){
|
||||
return {
|
||||
msg: "Hello"
|
||||
}
|
||||
}
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
vm.msg = "Hello World";
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(66);
|
||||
}, 0);
|
||||
});
|
||||
it("decreases the width of the input when text is removed", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' v-model='msg' v-el:test />",
|
||||
data(){
|
||||
return {
|
||||
msg: "Hello"
|
||||
}
|
||||
}
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
vm.msg = "Hey!";
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(30);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
it("clamps the input's width to the max width option", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' v-model='msg' v-el:test />",
|
||||
data(){
|
||||
return {
|
||||
msg: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
||||
}
|
||||
}
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(500);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
it("clamps the input's width to the min width option", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' v-model='msg' v-el:test />",
|
||||
data(){
|
||||
return {
|
||||
msg: "Hi"
|
||||
}
|
||||
}
|
||||
}).$mount();
|
||||
setTimeout(() => {
|
||||
expect( Math.round(vm.$els.test.getBoundingClientRect().width) ).toEqual(20);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
|
||||
// https://github.com/ariya/phantomjs/issues/10522
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function(oThis) {
|
||||
if (typeof this !== 'function') {
|
||||
// closest thing possible to the ECMAScript 5
|
||||
// internal IsCallable function
|
||||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1),
|
||||
fToBind = this,
|
||||
fNOP = function() {},
|
||||
fBound = function() {
|
||||
return fToBind.apply(this instanceof fNOP
|
||||
? this
|
||||
: oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
if (this.prototype) {
|
||||
// native functions don't have a prototype
|
||||
fNOP.prototype = this.prototype;
|
||||
}
|
||||
fBound.prototype = new fNOP();
|
||||
|
||||
return fBound;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
|
||||
if (typeof Object.assign != 'function') {
|
||||
(function () {
|
||||
Object.assign = function (target) {
|
||||
'use strict';
|
||||
if (target === undefined || target === null) {
|
||||
throw new TypeError('Cannot convert undefined or null to object');
|
||||
}
|
||||
|
||||
var output = Object(target);
|
||||
for (var index = 1; index < arguments.length; index++) {
|
||||
var source = arguments[index];
|
||||
if (source !== undefined && source !== null) {
|
||||
for (var nextKey in source) {
|
||||
if (source.hasOwnProperty(nextKey)) {
|
||||
output[nextKey] = source[nextKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user