This repository was archived by the owner on Jun 27, 2024. It is now read-only.
File tree 4 files changed +66
-1
lines changed
4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { mount } from "@vue/test-utils"
2
2
import Table from "../js/Tailwind2/Table.vue" ;
3
3
import expect from 'expect'
4
+ import TableWithDataWithoutPagination from "./TableWithDataWithoutPagination.vue" ;
4
5
5
6
describe ( 'Table.vue' , ( ) => {
6
7
it ( 'can enable a search row' , ( ) => {
@@ -200,4 +201,35 @@ describe('Table.vue', () => {
200
201
expect ( updates ) . toHaveLength ( 1 ) ;
201
202
} ) ;
202
203
} ) ;
204
+
205
+ it ( 'knows when there are no results and there is no pagination' , ( ) => {
206
+ const component = mount ( Table , {
207
+ propsData : {
208
+ meta : { } ,
209
+ }
210
+ } ) ;
211
+
212
+ expect ( component . vm . paginationMeta ) . toEqual ( { meta : { total : 0 } } ) ;
213
+ } ) ;
214
+
215
+ it ( 'knows when there are results while there is no pagination' , ( ) => {
216
+ const component = mount ( TableWithDataWithoutPagination , {
217
+ propsData : {
218
+ meta : { } ,
219
+ }
220
+ } ) ;
221
+
222
+ expect ( component . html ( ) ) . toContain ( "<td></td>" ) ;
223
+ expect ( component . html ( ) ) . not . toContain ( "No results found" ) ;
224
+ } ) ;
225
+
226
+ it ( 'uses the meta property for pagination' , ( ) => {
227
+ const component = mount ( Table , {
228
+ propsData : {
229
+ meta : { meta : { total : 1 } } ,
230
+ }
231
+ } ) ;
232
+
233
+ expect ( component . html ( ) ) . not . toContain ( "No results found" ) ;
234
+ } ) ;
203
235
} )
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <Table >
3
+ <template #body >
4
+ <tr >
5
+ <td ></td >
6
+ </tr >
7
+ </template >
8
+ </Table >
9
+ </template >
10
+
11
+ <script >
12
+ import Table from " ../js/Tailwind2/Table.vue" ;
13
+
14
+ export default { components: { Table } };
15
+ </script >
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ export default {
52
52
return Object .keys (this .search || {}).length > 0 ;
53
53
},
54
54
55
+ hasBody () {
56
+ return !! this .$slots .body ;
57
+ },
58
+
55
59
onlyData () {
56
60
if (this .hasFilters || this .hasColumns || this .hasSearchRows ) {
57
61
return false ;
@@ -63,6 +67,20 @@ export default {
63
67
64
68
return this .search .global ? false : true ;
65
69
},
70
+
71
+ paginationMeta () {
72
+ if (this .hasBody ) {
73
+ return this .meta ;
74
+ }
75
+
76
+ const hasPagination = ' meta' in this .meta || (' total' in this .meta && ' to' in this .meta && ' from' in this .meta );
77
+
78
+ if (hasPagination) {
79
+ return this .meta ;
80
+ }
81
+
82
+ return { meta: { total: 0 } };
83
+ }
66
84
},
67
85
68
86
data () {
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ table >>> tr:hover td {
120
120
</slot >
121
121
122
122
<slot name =" pagination" >
123
- <Pagination :meta =" meta " />
123
+ <Pagination :meta =" paginationMeta " />
124
124
</slot >
125
125
</TableWrapper >
126
126
</slot >
You can’t perform that action at this time.
0 commit comments