Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
continue tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish2 committed Nov 13, 2017
1 parent a22238a commit d351a23
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 33 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
},
"scripts": {
"build": "babel lib -d compiled",
"test-client": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/client-setup.js test/*.spec.js test/client/*.spec.js",
"watch-client": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --watch --require test/setup.js test/client-setup.js test/*.spec.js test/client/*.spec.js",
"test-server": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/server-setup.js test/*.spec.js test/server/*.spec.js",
"watch-server": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --watch --require test/setup.js test/server-setup.js test/*.spec.js test/server/*.spec.js"
"test-client": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --require test/setup/setup.js test/setup/client-setup.js test/*.spec.js test/client/*.spec.js",
"watch-client": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --watch --require test/setup/setup.js test/setup/client-setup.js test/*.spec.js test/client/*.spec.js",
"test-server": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --require test/setup/setup.js test/setup/server-setup.js test/*.spec.js test/server/*.spec.js",
"watch-server": "cross-env NODE_ENV=test mocha-webpack --webpack-config webpack.config.js --watch --require test/setup/setup.js test/setup/server-setup.js test/*.spec.js test/server/*.spec.js"
},
"license": "MIT",
"main": "compiled/index.js",
Expand Down
47 changes: 47 additions & 0 deletions test/child-row.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import childRow from './setup/ChildRow.vue';

describe(suite + ': Child row', () => {

var firstRowToggler = 'table tbody tr td:first-child span';

beforeEach(()=>{

setOptions({
childRow
});

});

it('generates a child row when toggler is clicked, and removes it when clicked again', (done) =>{

click(firstRowToggler);

run(function() {
see('My Child Row ZW','table tbody tr:nth-child(2)');
click(firstRowToggler);
see('Zambia','table tbody tr:nth-child(2)');
},done);

});

it('only opens the clicked row', (done) => {

click(firstRowToggler);

run(function() {
count('.VueTables__child-row',1);
},done);

});

it('displays the correct toggler icon', (done) => {
run(function() {
count('.VueTables__child-row-toggler--closed', 10);
click(firstRowToggler);
count('.VueTables__child-row-toggler--closed', 9);
exists('table tbody tr:first-child .VueTables__child-row-toggler--open');
},done);
});


});
19 changes: 0 additions & 19 deletions test/client-setup.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/display.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ describe(suite +': Basic Display (default options)', () => {
exists('.VueTables__search input');
});

it('displays sort icons for all columns', () => {
exists('table thead tr:first-child th:first-child .glyphicon.glyphicon-sort');
exists('table thead tr:first-child th:nth-child(2) .glyphicon.glyphicon-sort');
exists('table thead tr:first-child th:nth-child(3) .glyphicon.glyphicon-sort');
});

it('displays pagination links', ()=>{
count('ul.VuePagination__pagination li',9) // 50 records = prev-chunk + prev + 5 pages + next + next-chunk
});


})
94 changes: 86 additions & 8 deletions test/server/request.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,97 @@
describe('Server: Request', () => {

var initialParams = {
query: '',
limit: 10,
ascending: 1,
page: 1,
byColumn: 0
};

it('sends a request when initialized to the URL defined by the consumer with the right parameters', ()=>{

var request = moxios.requests.mostRecent();

expect(request.config.url).toEqual(vm().url);

expect(request.config.params).toEqual(
{
query: '',
limit: 10,
ascending: 1,
page: 1,
byColumn: 0
});
expect(request.config.params).toEqual(initialParams);

// orderBy is not sent by default, unless the consumer defined a column to sort by using the orderBy option

});

it('Allows for modifying the request keys', (done) => {

setOptions({
requestKeys:{
query:'filter',
limit:'perPage'
}
});

vm().getData(true).then(()=>{

done();

var request = moxios.requests.mostRecent();

expect(request.config.params).toEqual(
{
filter: '',
perPage: 10,
ascending: 1,
page: 1,
byColumn: 0
});
});


});

it('can use a custom request function', (done)=>{

var response = {data:[],count:0};

setOptions({
requestFunction(data) {
return new Promise(function(resolve, reject) {

setTimeout(()=>{
resolve(response);
done();
},100);

});
}
});


vm().getData(true).then((res)=>{
expect(res).toEqual(response);
});

});

it('can use a request adapter', (done)=>{


setOptions({
requestAdapter(data) {
return {data};
}
});

vm().getData(true).then(()=>{

done();

var request = moxios.requests.mostRecent();

expect(request.config.params).toEqual({data:initialParams});

});


});

});
11 changes: 11 additions & 0 deletions test/setup/ChildRow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
My Child Row {{data.code}}
</div>
</template>

<script>
export default {
props:['data']
}
</script>
23 changes: 23 additions & 0 deletions test/setup/client-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import Vue from 'vue'
import { mount } from 'vue-test-utils'
import ClientTable from '../../compiled/v-client-table'
import data from './example-data'

global.suite = 'Client';

global.run = function(cb, done) {
cb();
done();
}

beforeEach(function() {
global.wrapper = mount(ClientTable.install(Vue), {
propsData:{
columns:['code','name','uri'],
data,
options:{}
}
});
});

File renamed without changes.
5 changes: 3 additions & 2 deletions test/server-setup.js → test/setup/server-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'
import { mount } from 'vue-test-utils'
import ServerTable from '../compiled/v-server-table.js'
import ServerTable from '../../compiled/v-server-table.js'

global.suite = 'Server';
global.axios = require('axios');
Expand All @@ -22,7 +22,8 @@ beforeEach(()=>{
global.wrapper = mount(ServerTable.install(Vue), {
propsData:{
columns:['code','name','uri'],
url:'get-data'
url:'get-data',
options:{}
}
});

Expand Down
8 changes: 8 additions & 0 deletions test/setup.js → test/setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ global.count = function(selector, count) {
expect(wrapper.findAll(selector)).toHaveLength(count);
}

global.setOptions = function(options) {
wrapper.setProps({options});
}

global.click = function(selector) {
wrapper.find(selector).trigger('click');
}



0 comments on commit d351a23

Please sign in to comment.