vuetable-next 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +4 -0
- package/.idea/easycode.ignore +13 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/material_theme_project_new.xml +13 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/vuetable-next.iml +12 -0
- package/.vscode/extensions.json +3 -0
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/auto-imports.d.ts +21 -0
- package/dist/style.css +1 -0
- package/dist/vite.svg +1 -0
- package/dist/vuetable-next.js +6061 -0
- package/dist/vuetable-next.js.map +1 -0
- package/dist/vuetable-next.umd.cjs +36 -0
- package/dist/vuetable-next.umd.cjs.map +1 -0
- package/eslint.config.js +122 -0
- package/index.html +161 -0
- package/package.json +80 -0
- package/public/vite.svg +1 -0
- package/src/assets/vue.svg +1 -0
- package/src/components/Vuetable.vue +1212 -0
- package/src/components/VuetableColGroup.vue +66 -0
- package/src/components/VuetableColGutter.vue +25 -0
- package/src/components/VuetableCssSemanticUI.ts +36 -0
- package/src/components/VuetableFieldCheckbox.vue +87 -0
- package/src/components/VuetableFieldCheckboxMixin.vue +46 -0
- package/src/components/VuetableFieldHandle.vue +41 -0
- package/src/components/VuetableFieldMixin.vue +30 -0
- package/src/components/VuetableFieldSequence.vue +43 -0
- package/src/components/VuetablePagination.vue +119 -0
- package/src/components/VuetablePaginationDropdown.vue +88 -0
- package/src/components/VuetablePaginationInfo.vue +51 -0
- package/src/components/VuetablePaginationInfoMixin.vue +64 -0
- package/src/components/VuetablePaginationMixin.vue +107 -0
- package/src/components/VuetableRowHeader.vue +190 -0
- package/src/components/useVuetablePagination.ts +56 -0
- package/src/components/useVuetablePaginationInfo.ts +40 -0
- package/src/data/fields.ts +102 -0
- package/src/data/lang.ts +4 -0
- package/src/index.ts +59 -0
- package/src/main.ts +396 -0
- package/src/style.css +79 -0
- package/src/vite-env.d.ts +1 -0
- package/test/Vuetable.AJAX.test.ts +291 -0
- package/test/Vuetable.Composable.test.ts +151 -0
- package/test/Vuetable.Computed.test.ts +211 -0
- package/test/Vuetable.Features.test.ts +145 -0
- package/test/Vuetable.FieldsDefinition.test.ts +236 -0
- package/test/Vuetable.HTML.test.ts +16 -0
- package/test/Vuetable.Methods.test.ts +373 -0
- package/test/__snapshots__/Vuetable.HTML.test.ts.snap +85 -0
- package/tsconfig.app.json +32 -0
- package/tsconfig.json +16 -0
- package/tsconfig.node.json +13 -0
- package/vite.config.ts +29 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import MockAdapter from "axios-mock-adapter";
|
|
3
|
+
import { shallowMount } from "@vue/test-utils";
|
|
4
|
+
import Vuetable from "../src/components/Vuetable.vue";
|
|
5
|
+
|
|
6
|
+
describe("AJAX functionality", () => {
|
|
7
|
+
let mock: MockAdapter;
|
|
8
|
+
let apiUrl: string;
|
|
9
|
+
|
|
10
|
+
beforeEach( () => {
|
|
11
|
+
mock = new MockAdapter(axios);
|
|
12
|
+
apiUrl = "api.example.com/hello";
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach( () => {
|
|
16
|
+
mock.reset();
|
|
17
|
+
apiUrl = "";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("load-on-start", () => {
|
|
21
|
+
it("calls API endpoint when load: load-on-start", context => new Promise(done => {
|
|
22
|
+
mock.onGet(apiUrl).reply(200, [
|
|
23
|
+
{ id: 1, code: "AAA" },
|
|
24
|
+
{ id: 2, code: "BBB" }
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const wrapper = shallowMount(Vuetable, {
|
|
28
|
+
propsData: {
|
|
29
|
+
apiUrl: apiUrl,
|
|
30
|
+
fields: ["id", "code"],
|
|
31
|
+
paginationPath: ""
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
36
|
+
expect(res.request.responseURL).toContain("api.example.com/hello");
|
|
37
|
+
expect(res.data[0].code).toEqual("AAA");
|
|
38
|
+
done(context);
|
|
39
|
+
});
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("http-method", () => {
|
|
44
|
+
const stubResponse = [
|
|
45
|
+
{ id: 1, code: "AAA" },
|
|
46
|
+
{ id: 2, code: "BBB" }
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const shallowVuetable = (httpMethod) => shallowMount(Vuetable, {
|
|
50
|
+
propsData: {
|
|
51
|
+
apiUrl: apiUrl,
|
|
52
|
+
fields: ["id", "code"],
|
|
53
|
+
paginationPath: "",
|
|
54
|
+
httpMethod
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('calls API endpoint using "get" verb', context => new Promise(done => {
|
|
59
|
+
mock.onGet(apiUrl).reply(200, stubResponse);
|
|
60
|
+
|
|
61
|
+
const wrapper = shallowVuetable("get");
|
|
62
|
+
expect(wrapper.vm.httpMethod).toEqual("get");
|
|
63
|
+
|
|
64
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
65
|
+
expect(res.request.responseURL).toContain("api.example.com/hello");
|
|
66
|
+
expect(res.data[0].code).toEqual("AAA");
|
|
67
|
+
done(context);
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
it('calls API endpoint using "post" verb', context => new Promise(done => {
|
|
72
|
+
mock.onPost(apiUrl).reply(200, stubResponse);
|
|
73
|
+
|
|
74
|
+
const wrapper = shallowVuetable("post");
|
|
75
|
+
expect(wrapper.vm.httpMethod).toEqual("post");
|
|
76
|
+
|
|
77
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
78
|
+
expect(res.request.responseURL).toContain("api.example.com/hello");
|
|
79
|
+
expect(res.data[0].code).toEqual("AAA");
|
|
80
|
+
done(context);
|
|
81
|
+
});
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("query-params", () => {
|
|
86
|
+
|
|
87
|
+
it("returns correct default", context => new Promise(done => {
|
|
88
|
+
const queryParams = {
|
|
89
|
+
sort: "sort",
|
|
90
|
+
page: "page",
|
|
91
|
+
perPage: "per_page"
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const params = new URLSearchParams(queryParams).toString();
|
|
95
|
+
|
|
96
|
+
mock.onGet(`${ apiUrl }?${ params }`).reply(200, "foo");
|
|
97
|
+
|
|
98
|
+
const wrapper = shallowMount(Vuetable, {
|
|
99
|
+
propsData: {
|
|
100
|
+
apiUrl: `${ apiUrl }?${ params }`,
|
|
101
|
+
fields: ["id", "code"],
|
|
102
|
+
paginationPath: ""
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(wrapper.vm.queryParams).toEqual({
|
|
107
|
+
sort: "sort",
|
|
108
|
+
page: "page",
|
|
109
|
+
perPage: "per_page"
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
113
|
+
expect(res.status).toEqual(200);
|
|
114
|
+
expect(res.request.responseURL).toEqual(
|
|
115
|
+
`${ apiUrl }?${ params }`
|
|
116
|
+
);
|
|
117
|
+
done(context);
|
|
118
|
+
});
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
it("uses the given query params object to make a call to API endpoint", context => new Promise(done => {
|
|
122
|
+
const queryParams = {
|
|
123
|
+
sort: "sss",
|
|
124
|
+
page: "ppp",
|
|
125
|
+
perPage: "ggg"
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const params = new URLSearchParams(queryParams).toString();
|
|
129
|
+
mock.onGet(`${ apiUrl }?${ params }`).reply(200, "foo");
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const wrapper = shallowMount(Vuetable, {
|
|
133
|
+
propsData: {
|
|
134
|
+
apiUrl: `${ apiUrl }?${ params }`,
|
|
135
|
+
fields: ["id", "code"],
|
|
136
|
+
paginationPath: "",
|
|
137
|
+
queryParams
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(wrapper.vm.queryParams).toEqual(queryParams);
|
|
142
|
+
|
|
143
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
144
|
+
expect(res.request.responseURL).toEqual(
|
|
145
|
+
`${apiUrl}?${ params }`
|
|
146
|
+
);
|
|
147
|
+
done(context);
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
it("uses the given callback to construct query params", context => new Promise(done => {
|
|
152
|
+
const queryParams = () => {
|
|
153
|
+
return {
|
|
154
|
+
aaa: "111",
|
|
155
|
+
bbb: "222",
|
|
156
|
+
ccc: "333"
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const params = new URLSearchParams(queryParams()).toString();
|
|
161
|
+
mock.onGet(`${ apiUrl }?${ params }`).reply(200, "foo");
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
const wrapper = shallowMount(Vuetable, {
|
|
165
|
+
propsData: {
|
|
166
|
+
apiUrl: `${ apiUrl }?${ params }`,
|
|
167
|
+
fields: ["id", "code"],
|
|
168
|
+
paginationPath: "",
|
|
169
|
+
queryParams
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(wrapper.vm.queryParams).toEqual(queryParams);
|
|
174
|
+
|
|
175
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
176
|
+
expect(res.request.responseURL).toEqual(
|
|
177
|
+
`${apiUrl}?${ params }`
|
|
178
|
+
);
|
|
179
|
+
done(context);
|
|
180
|
+
});
|
|
181
|
+
}));
|
|
182
|
+
|
|
183
|
+
it("defaults to empty object when the given queryParams function does not return Object", context => new Promise(done => {
|
|
184
|
+
const queryParams = () => "bar";
|
|
185
|
+
|
|
186
|
+
mock.onGet(apiUrl).reply(200, "foo");
|
|
187
|
+
|
|
188
|
+
const wrapper = shallowMount(Vuetable, {
|
|
189
|
+
propsData: {
|
|
190
|
+
apiUrl: apiUrl,
|
|
191
|
+
fields: ["id", "code"],
|
|
192
|
+
paginationPath: "",
|
|
193
|
+
queryParams
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(wrapper.vm.queryParams).toEqual(queryParams);
|
|
198
|
+
|
|
199
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
200
|
+
expect(res.config.params).toEqual({});
|
|
201
|
+
expect(res.request.responseURL).toEqual(apiUrl);
|
|
202
|
+
done(context);
|
|
203
|
+
});
|
|
204
|
+
}));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("append-params", () => {
|
|
208
|
+
const appends = {
|
|
209
|
+
"aaa": "111",
|
|
210
|
+
"bbb": "222"
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
it("appends additional parameters to the API request", context => new Promise(done => {
|
|
214
|
+
const params = new URLSearchParams(appends).toString();
|
|
215
|
+
|
|
216
|
+
mock.onGet(`${apiUrl}?${ params }`).reply(200, "foo");
|
|
217
|
+
|
|
218
|
+
const wrapper = shallowMount(Vuetable, {
|
|
219
|
+
propsData: {
|
|
220
|
+
apiUrl: `${apiUrl}?${ params }`,
|
|
221
|
+
fields: ["id", "code"],
|
|
222
|
+
paginationPath: "",
|
|
223
|
+
appendParams: appends
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
228
|
+
expect(res.config.params).toEqual(expect.objectContaining(appends));
|
|
229
|
+
expect(res.request.responseURL).toEqual(expect.stringContaining("aaa=111&bbb=222"));
|
|
230
|
+
done(context);
|
|
231
|
+
});
|
|
232
|
+
}));
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("http-options", () => {
|
|
236
|
+
const options = {
|
|
237
|
+
headers: {
|
|
238
|
+
"Authorization": "my-token"
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
it("attaches other options to the API request", context => new Promise(done => {
|
|
243
|
+
mock.onGet(apiUrl).reply(200, "foo", { ...options.headers });
|
|
244
|
+
|
|
245
|
+
const wrapper = shallowMount(Vuetable, {
|
|
246
|
+
propsData: {
|
|
247
|
+
apiUrl,
|
|
248
|
+
fields: ["id", "code"],
|
|
249
|
+
paginationPath: "",
|
|
250
|
+
httpOptions: options
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
wrapper.vm.instanceFetch.then(res => {
|
|
255
|
+
expect(res.headers).toEqual(expect.objectContaining(options.headers));
|
|
256
|
+
done(context);
|
|
257
|
+
});
|
|
258
|
+
}));
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("http-fetch", () => {
|
|
262
|
+
it("uses the given http-fetch function when specified", context => new Promise(done => {
|
|
263
|
+
mock.onGet(apiUrl).reply(200);
|
|
264
|
+
|
|
265
|
+
const myFetch = vi.fn( () => {
|
|
266
|
+
return axios.get(apiUrl);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const wrapper = shallowMount(Vuetable, {
|
|
270
|
+
propsData: {
|
|
271
|
+
apiUrl,
|
|
272
|
+
fields: ["id", "code"],
|
|
273
|
+
paginationPath: "",
|
|
274
|
+
httpFetch: myFetch as any
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
wrapper.vm.instanceFetch.then(() => {
|
|
279
|
+
expect(myFetch).toBeCalledWith(
|
|
280
|
+
apiUrl,
|
|
281
|
+
{
|
|
282
|
+
params: {
|
|
283
|
+
page: 1, per_page: 10, sort: ""
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
done(context);
|
|
288
|
+
});
|
|
289
|
+
}));
|
|
290
|
+
});
|
|
291
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useVuetablePaginationInfo } from "../src/components/useVuetablePaginationInfo";
|
|
2
|
+
import { createApp } from "vue";
|
|
3
|
+
import { expect } from "vitest";
|
|
4
|
+
import { useVuetablePagination } from "../src/components/useVuetablePagination";
|
|
5
|
+
import { mount } from "@vue/test-utils";
|
|
6
|
+
import { VuetablePagination, VuetablePaginationInfo } from "../src";
|
|
7
|
+
|
|
8
|
+
function withSetupPaginationInfo () {
|
|
9
|
+
let result: any;
|
|
10
|
+
|
|
11
|
+
const app = createApp({
|
|
12
|
+
props: ["noDataTemplate", "infoTemplate"],
|
|
13
|
+
setup (props) {
|
|
14
|
+
result = useVuetablePaginationInfo(() => props.noDataTemplate as string, () => props.infoTemplate as string);
|
|
15
|
+
return () => {};
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
infoTemplate: "Displaying {from} to {to} of {total} items",
|
|
19
|
+
noDataTemplate: "No relevant data"
|
|
20
|
+
});
|
|
21
|
+
app.mount(document.createElement("div"));
|
|
22
|
+
return [result, app];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("Vuetable - Composable in the usePaginationInfo", () => {
|
|
26
|
+
it("should tablePagination changed", () => {
|
|
27
|
+
const [result] = withSetupPaginationInfo();
|
|
28
|
+
|
|
29
|
+
const pagination = {
|
|
30
|
+
total: 100,
|
|
31
|
+
current_page: 1,
|
|
32
|
+
last_page: 10,
|
|
33
|
+
from: 1,
|
|
34
|
+
to: 2
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
expect(result.tablePagination.value).toBe(null);
|
|
38
|
+
|
|
39
|
+
result.setPaginationData(pagination);
|
|
40
|
+
|
|
41
|
+
expect(result.tablePagination.value).toStrictEqual(pagination);
|
|
42
|
+
|
|
43
|
+
result.resetData();
|
|
44
|
+
|
|
45
|
+
expect(result.tablePagination.value).toBe(null);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("isCurrentPage equal to current_page", () => {
|
|
49
|
+
const [result] = withSetupPaginationInfo();
|
|
50
|
+
|
|
51
|
+
result.tablePagination.value = {
|
|
52
|
+
total: 100,
|
|
53
|
+
current_page: 2,
|
|
54
|
+
last_page: 10,
|
|
55
|
+
from: 2,
|
|
56
|
+
to: 3
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
expect(result.isCurrentPage(2)).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("The paginationInfo changed", async () => {
|
|
63
|
+
const wrapper = mount(VuetablePaginationInfo, {
|
|
64
|
+
propsData: {
|
|
65
|
+
infoTemplate: "Displaying {from} to {to} of {total} items",
|
|
66
|
+
noDataTemplate: "No relevant data"
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await wrapper.setProps({
|
|
71
|
+
noDataTemplate: "New noDataTemplate"
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(wrapper.vm.noDataTemplate).toBe("New noDataTemplate");
|
|
75
|
+
expect(wrapper.vm.paginationInfo).toBe(wrapper.vm.noDataTemplate);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("Vuetable - Composable in the usePagination", () => {
|
|
80
|
+
const app = createApp({}, {
|
|
81
|
+
onEachSide: 2,
|
|
82
|
+
firstPage: 1
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should tablePagination changed", () => {
|
|
86
|
+
const pagination = {
|
|
87
|
+
total: 100,
|
|
88
|
+
current_page: 1,
|
|
89
|
+
last_page: 10,
|
|
90
|
+
from: 1,
|
|
91
|
+
to: 2
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const {
|
|
95
|
+
tablePagination,
|
|
96
|
+
setPaginationData,
|
|
97
|
+
resetData
|
|
98
|
+
} = useVuetablePagination(() => app._props.onEachSide as number, () => app._props.firstPage as number);
|
|
99
|
+
|
|
100
|
+
expect(tablePagination.value).toBe(null);
|
|
101
|
+
|
|
102
|
+
setPaginationData(pagination);
|
|
103
|
+
|
|
104
|
+
expect(tablePagination.value).toStrictEqual(pagination);
|
|
105
|
+
|
|
106
|
+
resetData();
|
|
107
|
+
|
|
108
|
+
expect(tablePagination.value).toBe(null);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should computed reactive", () => {
|
|
112
|
+
const pagination = {
|
|
113
|
+
total: 100,
|
|
114
|
+
current_page: 1,
|
|
115
|
+
last_page: 10,
|
|
116
|
+
from: 1,
|
|
117
|
+
to: 2
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const {
|
|
121
|
+
tablePagination,
|
|
122
|
+
isOnFirstPage,
|
|
123
|
+
isOnLastPage,
|
|
124
|
+
notEnoughPages
|
|
125
|
+
} = useVuetablePagination(() => app._props.onEachSide as number, () => app._props.firstPage as number);
|
|
126
|
+
|
|
127
|
+
tablePagination.value = pagination;
|
|
128
|
+
|
|
129
|
+
expect(isOnFirstPage.value).toBeTruthy();
|
|
130
|
+
expect(isOnLastPage.value).toBeFalsy();
|
|
131
|
+
|
|
132
|
+
tablePagination.value.current_page = 10;
|
|
133
|
+
|
|
134
|
+
expect(isOnLastPage.value).toBeTruthy();
|
|
135
|
+
|
|
136
|
+
expect(notEnoughPages.value).toBeFalsy();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should windowSize changed", async () => {
|
|
140
|
+
const wrapper = mount(VuetablePagination);
|
|
141
|
+
|
|
142
|
+
expect(wrapper.vm.windowSize).toBe(5);
|
|
143
|
+
|
|
144
|
+
await wrapper.setProps({
|
|
145
|
+
onEachSide: 4
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(wrapper.vm.onEachSide).toBe(4);
|
|
149
|
+
expect(wrapper.vm.windowSize).toBe(9);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { createApp } from "vue";
|
|
2
|
+
import { mount, shallowMount } from "@vue/test-utils";
|
|
3
|
+
import Vuetable from "../src/components/Vuetable.vue";
|
|
4
|
+
|
|
5
|
+
describe("Vuetable - Computed properties", () => {
|
|
6
|
+
|
|
7
|
+
beforeAll( () => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
global.console.warn = vitest.fn(msg => msg);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterAll( () => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
global.console.warn.mockReset();
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
global.console.warn.mockRestore();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const mountVuetable = (fields: any) => mount(Vuetable, {
|
|
20
|
+
propsData: {
|
|
21
|
+
loadOnStart: false,
|
|
22
|
+
fields
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("countVisibleFields", () => {
|
|
27
|
+
const wrapper = mountVuetable(["code", "description"]);
|
|
28
|
+
|
|
29
|
+
expect(wrapper.vm.countVisibleFields).toEqual(2);
|
|
30
|
+
wrapper.vm.tableFields[0].visible = false;
|
|
31
|
+
expect(wrapper.vm.countVisibleFields).toEqual(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("countTableData", () => {
|
|
35
|
+
const wrapper = mountVuetable(["code"]);
|
|
36
|
+
|
|
37
|
+
expect(wrapper.vm.countTableData).toEqual(0);
|
|
38
|
+
wrapper.vm.setData([
|
|
39
|
+
{ code: "AAA" },
|
|
40
|
+
{ code: "BBB" }
|
|
41
|
+
]);
|
|
42
|
+
expect(wrapper.vm.countTableData).toEqual(2);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("displayEmptyDataRow", async () => {
|
|
46
|
+
const wrapper = mountVuetable(["code"]);
|
|
47
|
+
|
|
48
|
+
// where there's no data
|
|
49
|
+
expect(wrapper.vm.displayEmptyDataRow).toBe(true);
|
|
50
|
+
|
|
51
|
+
// when there are no data, but no-data-template is empty
|
|
52
|
+
await wrapper.setProps({
|
|
53
|
+
noDataTemplate: ""
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(wrapper.vm.displayEmptyDataRow).toBe(false);
|
|
57
|
+
|
|
58
|
+
// when there are data
|
|
59
|
+
wrapper.vm.setData([
|
|
60
|
+
{ code: "AAA" },
|
|
61
|
+
{ code: "BBB" }
|
|
62
|
+
]);
|
|
63
|
+
expect(wrapper.vm.displayEmptyDataRow).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("useDetailRow", () => {
|
|
67
|
+
const app = createApp({});
|
|
68
|
+
const detailRow = app.component("detail-row", {
|
|
69
|
+
template: "<div>AAA</div>"
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const mountVuetable = () => mount(Vuetable, {
|
|
73
|
+
propsData: {
|
|
74
|
+
apiMode: false,
|
|
75
|
+
fields: ["code"],
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns false when data is not available", async () => {
|
|
80
|
+
const wrapper = mountVuetable();
|
|
81
|
+
await wrapper.setProps({ detailRowComponent: detailRow });
|
|
82
|
+
|
|
83
|
+
expect(wrapper.vm.useDetailRow).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("returns false when data is available, but detail-row-component was not specified", () => {
|
|
87
|
+
const wrapper = mountVuetable();
|
|
88
|
+
wrapper.vm.setData([{ code: "AAA" }]);
|
|
89
|
+
|
|
90
|
+
expect(wrapper.vm.useDetailRow).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("returns true when both the data and detail-row-component are available", async () => {
|
|
94
|
+
const wrapper = mountVuetable();
|
|
95
|
+
await wrapper.setProps({
|
|
96
|
+
detailRowComponent: detailRow,
|
|
97
|
+
data: [ { code: "AAA" } ]
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(wrapper.vm.useDetailRow).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("dataIsAvailable", () => {
|
|
105
|
+
const mountVuetable = () => shallowMount(Vuetable, {
|
|
106
|
+
propsData: {
|
|
107
|
+
apiMode: false,
|
|
108
|
+
fields: ["code"],
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("return false when data is not available", () => {
|
|
113
|
+
const wrapper = mountVuetable();
|
|
114
|
+
|
|
115
|
+
expect(wrapper.vm.dataIsAvailable).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("return true when data is available", async () => {
|
|
119
|
+
const wrapper = mountVuetable();
|
|
120
|
+
await wrapper.setProps({
|
|
121
|
+
data: [{ code: "AAA" }]
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(wrapper.vm.dataIsAvailable).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("hasRowIdentifier", () => {
|
|
129
|
+
const mountVuetable = () => shallowMount(Vuetable, {
|
|
130
|
+
propsData: {
|
|
131
|
+
apiMode: false,
|
|
132
|
+
fields: ["code"],
|
|
133
|
+
data: [ { code: "AAA" } ]
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("return false when row identifier cannot be found in the given data", () => {
|
|
138
|
+
const wrapper = mountVuetable();
|
|
139
|
+
|
|
140
|
+
expect(wrapper.vm.hasRowIdentifier).toBe(false);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("return true when row identifier can be found in the given data", async () => {
|
|
144
|
+
const wrapper = mountVuetable();
|
|
145
|
+
await wrapper.setProps({
|
|
146
|
+
trackBy: "code"
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(wrapper.vm.hasRowIdentifier).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("lessThanMinRows", () => {
|
|
154
|
+
|
|
155
|
+
const mountVuetable = () => {
|
|
156
|
+
return shallowMount(Vuetable, {
|
|
157
|
+
propsData: {
|
|
158
|
+
apiMode: false,
|
|
159
|
+
fields: ["code"],
|
|
160
|
+
minRows: 2,
|
|
161
|
+
data: [
|
|
162
|
+
{ code: "AAA" }
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
it("returns true when available data has less row than min-rows prop", () => {
|
|
169
|
+
const wrapper = mountVuetable();
|
|
170
|
+
|
|
171
|
+
expect(wrapper.vm.lessThanMinRows).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("returns false when available data has at least the same number specified in min-rows", async () => {
|
|
175
|
+
const wrapper = mountVuetable();
|
|
176
|
+
await wrapper.setProps({
|
|
177
|
+
minRows: 1
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
expect(wrapper.vm.lessThanMinRows).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("blankRows", () => {
|
|
185
|
+
|
|
186
|
+
const mountVuetable = (minRows, data) => {
|
|
187
|
+
return shallowMount(Vuetable, {
|
|
188
|
+
propsData: {
|
|
189
|
+
apiMode: false,
|
|
190
|
+
fields: ["code"],
|
|
191
|
+
minRows,
|
|
192
|
+
data
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
it("returns correct number of blank rows", () => {
|
|
198
|
+
let wrapper = mountVuetable(0, []);
|
|
199
|
+
expect(wrapper.vm.blankRows).toEqual(0);
|
|
200
|
+
|
|
201
|
+
wrapper = mountVuetable(1, []);
|
|
202
|
+
expect(wrapper.vm.blankRows).toEqual(1);
|
|
203
|
+
|
|
204
|
+
wrapper = mountVuetable(2, []);
|
|
205
|
+
expect(wrapper.vm.blankRows).toEqual(2);
|
|
206
|
+
|
|
207
|
+
wrapper = mountVuetable(2, [{ code: "AAA" }]);
|
|
208
|
+
expect(wrapper.vm.blankRows).toEqual(1);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|