Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default function (directive, proxyEvent, delegateMethods = [], propsToCon
};
},
created(){
if (typeof this.stDirective.state === 'function') {
this.stState = this.stDirective.state();
}
this.stDirective[proxyEvent](state => {
this.stState = state;
})
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/StPagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<span id="page">{{stState.page}}</span>
<span id="size">{{stState.size}}</span>
<span id="filtered-count">{{stState.filteredCount}}</span>
</div>
</template>

<script>
import StMixins from '../../dist/smart-table-vue.js';

export default {
name: 'StPagination',
mixins: [StMixins.pagination],
};
</script>
2 changes: 2 additions & 0 deletions test/ssr/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {test} from 'zora';
import testTable from './table.js';
import testPagination from './pagination.js';

test('table mixin (SSR)', testTable);
test('pagination mixin (SSR)', testPagination);
38 changes: 38 additions & 0 deletions test/ssr/pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {smartTable} from 'smart-table-core';
import {render} from '@vue/server-test-utils';
import paginationComponent from '../fixtures/StPagination.vue';
import {sleep, defaultTableState} from '../helpers.js';

export default ({test}) => {
const tableData = [
{ surname: "Renard", name: "Laurent" },
{ surname: "Lazo", name: "Jan" },
{ surname: "Leponge", name: "Bob" },
];
test('component has the correct page and size when mounted with initial data', async (t) => {
const table = smartTable({
data: tableData,
});
table.exec();
await sleep(20);

let wrapper = await render(paginationComponent, {
propsData: {
smartTable: table,
},
});
t.equal(wrapper.find('#page').text(), '1', 'initial page is current table page');
t.equal(wrapper.find('#size').text(), '', 'initial page size is current table page size');
t.equal(wrapper.find('#filtered-count').text(), tableData.length + '', 'initial count of filtered items is all items in the table');

table.slice({page: 2, size: 1});
wrapper = await render(paginationComponent, {
propsData: {
smartTable: table,
},
});
t.equal(wrapper.find('#page').text(), '2', 'page number is reactive to table directive updates');
t.equal(wrapper.find('#size').text(), '1', 'page size is reactive to table directive updates');
t.equal(wrapper.find('#filtered-count').text(), tableData.length + '', 'filtered item count is reactive to table directive updates');
});
};