Skip to content

Commit

Permalink
new: change faker.js to fakerator
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Jun 1, 2016
1 parent ca1b180 commit 3184fa4
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
"browser": true,
"commonjs": true,
"es6": true,
"jquery": true
"jquery": true,
mocha: true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
72 changes: 22 additions & 50 deletions dev/data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import faker from 'faker';
import Fakerator from 'fakerator';
import moment from 'moment';

let fakerator = new Fakerator();

let roles = [
{ id: "admin", name: "Administrator"},
{ id: "moderator", name: "Moderator"},
Expand All @@ -17,63 +19,33 @@ module.exports = {
users: (function() {
let res = [];
for (let i = 0; i < 5; i++) {
let lang = faker.helpers.randomize(['en-US', 'en-GB', 'de', 'fr', 'it']);
//faker.locale = lang;
let user = faker.helpers.createCard();
let lang = fakerator.random.arrayElement(['en-US', 'en-GB', 'de', 'fr', 'it']);
let user = fakerator.entity.user();
user.id = i + 1;
user.type = faker.helpers.randomize(["personal", "business"]);
user.password = faker.internet.password(10);
user.bio = faker.lorem.paragraph();
let dob = faker.date.past(40, "1998-01-01");
user.type = fakerator.random.arrayElement(["personal", "business"]);
user.bio = fakerator.lorem.paragraph();
let dob = fakerator.date.past(40, "1998-01-01");
user.dob = dob.valueOf();
user.time = moment().format("hh:mm:ss");
user.age = moment().year() - moment(dob).year();
user.rank = faker.random.number({
min: 1,
max: 10
});
user.role = faker.helpers.randomize(roles).id;
//user.mobile = faker.phone.phoneNumber();
user.avatar = faker.internet.avatar();
user.rank = fakerator.random.number(1, 10);
user.role = fakerator.random.arrayElement(roles).id;
//user.mobile = fakerator.phone.phoneNumber();
user.avatar = fakerator.internet.avatar();

user.skills = [];
user.skills.push(faker.helpers.randomize(skills));
user.skills.push(faker.helpers.randomize(skills));
user.skills = fakerator.utimes(fakerator.random.arrayElement, 2, skills);

user.language = lang;
user.status = faker.helpers.randomize([true, false, true]);
user.created = faker.date.recent(30).valueOf();
user.dt = faker.date.recent(30).valueOf();
user.favoriteColor = faker.internet.color();

if (user.type == "business") {
user.company = {
"name": faker.company.companyName(),
"catchPhrase": faker.company.catchPhrase(),
"bs": faker.company.bs(),
"website": faker.internet.domainName(),
"phone": faker.phone.phoneNumber(),
"address": {
"street": faker.address.streetAddress(),
"city": faker.address.city(),
"country": faker.address.country(),
"zipcode": faker.address.zipCode(),
"geo": {
"lat": faker.address.latitude(),
"lng": faker.address.longitude()
}
}

}
} else {
user.company = undefined;
}

user.posts = undefined;
user.accountHistory = undefined;

user.status = fakerator.random.boolean(75);
user.created = fakerator.date.recent(30).valueOf();
user.dt = fakerator.date.recent(30).valueOf();
user.favoriteColor = "#" + fakerator.internet.color();

if (user.type == "business")
user.company = fakerator.entity.company();

res.push(user);
//console.log(user);
console.log(user);
}
//console.log(res);
return res;
Expand Down
2 changes: 1 addition & 1 deletion dev/dataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
td {{ row.id }}
td
img(:src="row.avatar")
| {{ row.name }}
| {{ row.firstName + " " + row.lastName }} ({{row.userName}})
.label.label-warning(v-if="!row.status") Inactive
td {{ row.email }}
td {{ row.address.country }}
Expand Down
51 changes: 36 additions & 15 deletions dev/schema.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import moment from "moment";
import faker from "faker";
import Fakerator from "fakerator";
import {} from "lodash";

import { validators } from "../src";

let fakerator = new Fakerator();

module.exports = {
fields: [
{
Expand All @@ -28,11 +30,11 @@ module.exports = {
},
{
type: "text",
label: "Name",
model: "name",
label: "First name",
model: "firstName",
featured: true,
required: true,
placeholder: "User's full name",
placeholder: "User's first name",
validator: validators.string,

onChanged(model, newVal, oldVal, field) {
Expand All @@ -44,6 +46,25 @@ module.exports = {
// console.warn("Validation error in Name field! Errors:", errors);
}
},
{
type: "text",
label: "Last name",
model: "lastName",
featured: true,
required: true,
placeholder: "User's last name",
validator: validators.string
},
{
type: "text",
label: "Username",
model: "userName",
featured: true,
required: true,
min: 5,
placeholder: "User's last name",
validator: validators.string
},
{
type: "password",
label: "Password",
Expand Down Expand Up @@ -253,7 +274,7 @@ module.exports = {
model: "address.country",
multi: true,
required: true,
values: faker.definitions.address.country,
values: ["United Kingdom", "France", "Germany"],
//default: "United Kingdom",
multiSelect: false,
selectOptions: {
Expand All @@ -273,7 +294,7 @@ module.exports = {
{
type: "text",
label: "Street",
model: "address.streetC"
model: "address.street"
},
{
type: "text",
Expand All @@ -282,7 +303,7 @@ module.exports = {
disabled: false,
get(model) {
if (model && model.address && model.address.geo)
return model.address.geo.lat + ", " + model.address.geo.lng;
return model.address.geo.latitude + ", " + model.address.geo.longitude;
},
set(model, val) {
let values = val.split(",");
Expand All @@ -293,14 +314,14 @@ module.exports = {
model.address.geo = {};

if (values.length > 0 && values[0].trim() != "")
model.address.geo.lat = parseFloat(values[0].trim());
model.address.geo.latitude = parseFloat(values[0].trim());
else
model.address.geo.lat = 0
model.address.geo.latitude = 0

if (values.length > 1 && values[1].trim() != "")
model.address.geo.lng = parseFloat(values[1].trim());
model.address.geo.longitude = parseFloat(values[1].trim());
else
model.address.geo.lng = 0
model.address.geo.longitude = 0
},
buttons: [
{
Expand All @@ -315,8 +336,8 @@ module.exports = {
if (!model.address.geo)
model.address.geo = {};

model.address.geo.lat = pos.coords.latitude.toFixed(5);
model.address.geo.lng = pos.coords.longitude.toFixed(5);
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
});
} else {
alert("Geolocation is not supported by this browser.");
Expand All @@ -328,8 +349,8 @@ module.exports = {
label: "Clear",
onclick: function(model) {
model.address.geo = {
lat: 0,
lng: 0
latitude: 0,
longitude: 0
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"prebuild": "npm run test",
"build": "webpack --config webpack.build.config.js",
"dev": "webpack-dev-server --config webpack.dev.config.js --inline --hot --content-base dev/",
"lint": "eslint --ext=.js,.vue src",
"lint": "eslint --ext=.js,.vue src test/unit/specs",
"coverall": "cat ./test/unit/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coverage": "npm run test && npm run coverall",
"changelog": "conventional-changelog -i CHANGELOG.md -s",
Expand Down Expand Up @@ -54,7 +54,7 @@
"eslint-loader": "1.3.0",
"eslint-plugin-html": "1.4.0",
"eslint-plugin-vue": "0.1.1",
"faker": "3.1.0",
"fakerator": "0.1.1",
"git-commit-message-convention": "git://github.com/kazupon/git-commit-message-convention.git#065dfffbe2de5f6f16150aac9d4db7fdf5515e56",
"gitbook-cli": "2.1.3",
"inject-loader": "2.0.1",
Expand Down
26 changes: 13 additions & 13 deletions test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe("VueFormGenerator.vue", () => {

describe("with empty schema", () => {
let schema = {};
let model = null;

beforeEach( () => {
createFormGenerator(schema);
Expand Down Expand Up @@ -75,47 +74,47 @@ describe("VueFormGenerator.vue", () => {
vm.$nextTick(() => {
expect(tr.classList.contains("featured")).to.be.true;
done();
})
});
});

it("should be readonly class", (done) => {
vm.schema.fields[0].readonly = true;
vm.$nextTick(() => {
expect(tr.classList.contains("readonly")).to.be.true;
done();
})
});
});

it("should be disabled class", (done) => {
vm.schema.fields[0].disabled = true;
vm.$nextTick(() => {
expect(tr.classList.contains("disabled")).to.be.true;
done();
})
});
});

it("should be required class", (done) => {
vm.schema.fields[0].required = true;
vm.$nextTick(() => {
expect(tr.classList.contains("required")).to.be.true;
done();
})
});
});

it("should be error class", (done) => {
vm.$set("schema.fields[0].errors", [ "!!!" ]);
vm.$nextTick(() => {
expect(tr.classList.contains("error")).to.be.true;
done();
})
});
});

it("should be add a custom classes", (done) => {
vm.$set("schema.fields[0].styleClasses", "classA");
vm.$nextTick(() => {
expect(tr.classList.contains("classA")).to.be.true;
done();
})
});
});

it("should be add more custom classes", (done) => {
Expand All @@ -124,13 +123,13 @@ describe("VueFormGenerator.vue", () => {
expect(tr.classList.contains("classB")).to.be.true;
expect(tr.classList.contains("classC")).to.be.true;
done();
})
});
});

});

describe("check form row caption cell", () => {
let tr, tdCaption, tdField;
let tr, tdCaption;
let schema = {
fields: [
{
Expand All @@ -146,7 +145,6 @@ describe("VueFormGenerator.vue", () => {
createFormGenerator(schema);
tr = el.getElementsByTagName("tr")[0];
tdCaption = tr.getElementsByTagName("td")[0];
tdField = tr.getElementsByTagName("td")[1];
});

it("should be text of cell is the name of field", () => {
Expand All @@ -163,7 +161,7 @@ describe("VueFormGenerator.vue", () => {
expect(span.querySelector(".helpText")).to.be.exist;
expect(span.querySelector(".helpText").textContent).to.be.equal("Sample help");
done();
})
});
});

});
Expand Down Expand Up @@ -246,10 +244,11 @@ describe("VueFormGenerator.vue", () => {
}
]
};

let model = {
name: "John Doe",
status: true
}
};

before( () => {
createFormGenerator(schema, model);
Expand Down Expand Up @@ -319,10 +318,11 @@ describe("VueFormGenerator.vue", () => {
}
]
};

let model = {
name: "John Doe",
status: true
}
};

before( () => {
createFormGenerator(schema, model);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/fields/abstractField.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global sinon */
import { expect } from "chai";

import Vue from "vue";
import VueFormGenerator from "src/index";
import AbstractField from "src/fields/abstractField";

Vue.component("AbstractField", AbstractField);
Expand Down Expand Up @@ -133,7 +133,7 @@ describe("abstractField.vue", () => {
expect(schema.onChanged.calledOnce).to.be.true;
expect(schema.onChanged.calledWith(model, "Jane Doe", "John Doe", schema)).to.be.true;
done();
})
});
});

});
Expand All @@ -148,7 +148,7 @@ describe("abstractField.vue", () => {
let model = { name: "John Doe" };
let options = {
validateAfterChanged: false
}
};

beforeEach( () => {
createField(schema, model, false, options);
Expand Down
Loading

0 comments on commit 3184fa4

Please sign in to comment.