aloha-vue 2.83.0 → 2.85.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/CHANGELOG.md +8 -0
- package/dist/aloha-vue.es.js +175 -148
- package/dist/aloha-vue.umd.js +55 -55
- package/package.json +1 -1
- package/src/ATable/ATable.js +26 -20
- package/src/ATable/__tests__/ATable.MultipleActionRows.test.js +86 -0
- package/src/ATable/compositionAPI/CountAPI.js +3 -2
- package/src/ATable/compositionAPI/MultipleActionAPI.js +1 -1
- package/src/ATable/compositionAPI/RowsAPI.js +15 -2
- package/src/ATable/compositionAPI/VariablesAPI.js +2 -0
- package/src/ATranslation/ATranslation.js +46 -0
- package/src/ATranslation/__tests__/ATranslation.test.js +121 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aloha-vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.85.0",
|
|
4
4
|
"description": "Aloha-vue is a JavaScript library that provides a wide range of accessible components and directives for Vue.js. Accessibility is of paramount importance to us, and we have designed all our components to meet accessibility compliance criteria. This library is a valuable tool for frontend developers and has already been used in three projects, including two large-scale ones",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility compliance criteria",
|
package/src/ATable/ATable.js
CHANGED
|
@@ -530,12 +530,9 @@ export default {
|
|
|
530
530
|
modelIsTableWithoutScrollComputed,
|
|
531
531
|
} = SimpleTableAPI(props);
|
|
532
532
|
|
|
533
|
-
const {
|
|
534
|
-
countAllRowsLocal,
|
|
535
|
-
} = CountAPI(props);
|
|
536
|
-
|
|
537
533
|
const {
|
|
538
534
|
columnsScrollInvisible,
|
|
535
|
+
currentMultipleActions,
|
|
539
536
|
indexFirstScrollInvisibleColumn,
|
|
540
537
|
isMultipleActionsActive,
|
|
541
538
|
modelColumnsVisibleLocal,
|
|
@@ -572,10 +569,10 @@ export default {
|
|
|
572
569
|
const {
|
|
573
570
|
columnsOrderedFromSimpleTable,
|
|
574
571
|
renderedGroupedColumns,
|
|
575
|
-
} = ColumnsGroupedAPI(props, {
|
|
576
|
-
modelSort: modelSortLocal,
|
|
577
|
-
slots: context.slots,
|
|
578
|
-
});
|
|
572
|
+
} = ColumnsGroupedAPI(props, {
|
|
573
|
+
modelSort: modelSortLocal,
|
|
574
|
+
slots: context.slots,
|
|
575
|
+
});
|
|
579
576
|
|
|
580
577
|
const {
|
|
581
578
|
columnIdsGroupByLocked,
|
|
@@ -609,6 +606,7 @@ export default {
|
|
|
609
606
|
|
|
610
607
|
const {
|
|
611
608
|
addRow,
|
|
609
|
+
dataFiltered,
|
|
612
610
|
deleteRow,
|
|
613
611
|
hasRows,
|
|
614
612
|
rowsLocal,
|
|
@@ -617,13 +615,21 @@ export default {
|
|
|
617
615
|
stopRenderRows,
|
|
618
616
|
updateRow,
|
|
619
617
|
} = RowsAPI(props, {
|
|
618
|
+
currentMultipleActions,
|
|
620
619
|
dataSorted,
|
|
620
|
+
isMultipleActionsActive,
|
|
621
621
|
limit,
|
|
622
622
|
offset,
|
|
623
623
|
setEmptySelectedRowsIndexes,
|
|
624
624
|
usePaginationLocal,
|
|
625
625
|
});
|
|
626
626
|
|
|
627
|
+
const {
|
|
628
|
+
countAllRowsLocal,
|
|
629
|
+
} = CountAPI(props, {
|
|
630
|
+
data: dataFiltered,
|
|
631
|
+
});
|
|
632
|
+
|
|
627
633
|
const {
|
|
628
634
|
columnActionsBtnGroupMaxWidthStyle,
|
|
629
635
|
columnActionsWidthLocal,
|
|
@@ -678,7 +684,6 @@ export default {
|
|
|
678
684
|
areAllVisibleRowsSelected,
|
|
679
685
|
areSomeRowsSelected,
|
|
680
686
|
closeMultipleActionsActive,
|
|
681
|
-
currentMultipleActions,
|
|
682
687
|
hasMultipleActions,
|
|
683
688
|
selectedRows,
|
|
684
689
|
selectedRowsIndexes,
|
|
@@ -688,6 +693,7 @@ export default {
|
|
|
688
693
|
toggleMultipleActionsActive,
|
|
689
694
|
} = MultipleActionAPI(props, context, {
|
|
690
695
|
checkVisibleColumns,
|
|
696
|
+
currentMultipleActions,
|
|
691
697
|
isMultipleActionsActive,
|
|
692
698
|
rowsLocalAll,
|
|
693
699
|
rowsLocalLength,
|
|
@@ -1001,7 +1007,7 @@ export default {
|
|
|
1001
1007
|
onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
|
|
1002
1008
|
columnsForRender: this.renderedGroupedColumns,
|
|
1003
1009
|
}) :
|
|
1004
|
-
h(ATableHeader, {
|
|
1010
|
+
h(ATableHeader, {
|
|
1005
1011
|
areAllRowsSelected: this.areAllRowsSelected,
|
|
1006
1012
|
areAllVisibleRowsSelected: this.areAllVisibleRowsSelected,
|
|
1007
1013
|
areSomeRowsSelected: this.areSomeRowsSelected,
|
|
@@ -1014,8 +1020,8 @@ export default {
|
|
|
1014
1020
|
rowsLocalLength: this.rowsLocalLength,
|
|
1015
1021
|
showFirstSortingSequenceNumber: this.showFirstSortingSequenceNumber,
|
|
1016
1022
|
sortingSequenceNumberClass: this.sortingSequenceNumberClass,
|
|
1017
|
-
onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
|
|
1018
|
-
}, this.$slots),
|
|
1023
|
+
onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
|
|
1024
|
+
}, this.$slots),
|
|
1019
1025
|
h("div", {
|
|
1020
1026
|
class: "a_table__loading",
|
|
1021
1027
|
}, [
|
|
@@ -1050,10 +1056,10 @@ export default {
|
|
|
1050
1056
|
level: 1,
|
|
1051
1057
|
row,
|
|
1052
1058
|
rowActionsClass: this.rowActionsClass,
|
|
1053
|
-
rowClass: this.rowClass,
|
|
1054
|
-
rowIndex,
|
|
1055
|
-
rowIndexPath: `${ rowIndex }`,
|
|
1056
|
-
rowsLength: this.rowsLocal.length,
|
|
1059
|
+
rowClass: this.rowClass,
|
|
1060
|
+
rowIndex,
|
|
1061
|
+
rowIndexPath: `${ rowIndex }`,
|
|
1062
|
+
rowsLength: this.rowsLocal.length,
|
|
1057
1063
|
selectedRowsIndexes: this.selectedRowsIndexes,
|
|
1058
1064
|
onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
|
|
1059
1065
|
}, {
|
|
@@ -1101,10 +1107,10 @@ export default {
|
|
|
1101
1107
|
level: 1,
|
|
1102
1108
|
row,
|
|
1103
1109
|
rowActionsClass: this.rowActionsClass,
|
|
1104
|
-
rowClass: this.rowClass,
|
|
1105
|
-
rowIndex,
|
|
1106
|
-
rowIndexPath: `${ rowIndex }`,
|
|
1107
|
-
rowsLength: this.rowsFooter.length,
|
|
1110
|
+
rowClass: this.rowClass,
|
|
1111
|
+
rowIndex,
|
|
1112
|
+
rowIndexPath: `${ rowIndex }`,
|
|
1113
|
+
rowsLength: this.rowsFooter.length,
|
|
1108
1114
|
selectedRowsIndexes: this.selectedRowsIndexes,
|
|
1109
1115
|
onSetSelectedRowsIndexes: this.setSelectedRowsIndexes,
|
|
1110
1116
|
}, {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nextTick,
|
|
3
|
+
ref,
|
|
4
|
+
} from "vue";
|
|
5
|
+
import {
|
|
6
|
+
describe,
|
|
7
|
+
expect,
|
|
8
|
+
it,
|
|
9
|
+
vi,
|
|
10
|
+
} from "vitest";
|
|
11
|
+
|
|
12
|
+
import CountAPI from "../compositionAPI/CountAPI";
|
|
13
|
+
import MultipleActionAPI from "../compositionAPI/MultipleActionAPI";
|
|
14
|
+
import RowsAPI from "../compositionAPI/RowsAPI";
|
|
15
|
+
import VariablesAPI from "../compositionAPI/VariablesAPI";
|
|
16
|
+
|
|
17
|
+
describe("ATable multiple action row filtering", () => {
|
|
18
|
+
it("filters before pagination, updates counts and selection, and restores rows on close", async() => {
|
|
19
|
+
const data = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
|
|
20
|
+
const callback = vi.fn(({ row }) => row.id === 2);
|
|
21
|
+
const props = {
|
|
22
|
+
clearSelectedRowsOnDataChange: true,
|
|
23
|
+
data,
|
|
24
|
+
multipleActions: [],
|
|
25
|
+
pagination: { isOutside: false },
|
|
26
|
+
rowsCountRenderPerTick: 0,
|
|
27
|
+
};
|
|
28
|
+
const {
|
|
29
|
+
currentMultipleActions,
|
|
30
|
+
isMultipleActionsActive,
|
|
31
|
+
} = VariablesAPI();
|
|
32
|
+
const clearSelection = vi.fn();
|
|
33
|
+
const rows = RowsAPI(props, {
|
|
34
|
+
currentMultipleActions,
|
|
35
|
+
dataSorted: ref(data),
|
|
36
|
+
isMultipleActionsActive,
|
|
37
|
+
limit: ref(2),
|
|
38
|
+
offset: ref(0),
|
|
39
|
+
setEmptySelectedRowsIndexes: clearSelection,
|
|
40
|
+
usePaginationLocal: ref(true),
|
|
41
|
+
});
|
|
42
|
+
const { countAllRowsLocal } = CountAPI(props, { data: rows.dataFiltered });
|
|
43
|
+
const actions = MultipleActionAPI(props, { emit: vi.fn() }, {
|
|
44
|
+
currentMultipleActions,
|
|
45
|
+
isMultipleActionsActive,
|
|
46
|
+
rowsLocalAll: rows.rowsLocalAll,
|
|
47
|
+
rowsLocalLength: rows.rowsLocalLength,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
currentMultipleActions.value = { isRowHiddenCallback: callback };
|
|
51
|
+
expect(rows.rowsLocal.value).toEqual(data.slice(0, 2));
|
|
52
|
+
expect(callback).not.toHaveBeenCalled();
|
|
53
|
+
|
|
54
|
+
isMultipleActionsActive.value = true;
|
|
55
|
+
await nextTick();
|
|
56
|
+
|
|
57
|
+
expect(rows.rowsLocal.value).toEqual([data[0], data[2]]);
|
|
58
|
+
expect(countAllRowsLocal.value).toBe(3);
|
|
59
|
+
expect(callback).toHaveBeenCalledWith({ row: data[1], rowIndex: 1 });
|
|
60
|
+
expect(clearSelection).toHaveBeenCalledOnce();
|
|
61
|
+
actions.setSelectedRowsIndexes({ isAll: true });
|
|
62
|
+
expect(actions.selectedRows.value).toEqual([data[0], data[2]]);
|
|
63
|
+
|
|
64
|
+
actions.closeMultipleActionsActive();
|
|
65
|
+
await nextTick();
|
|
66
|
+
|
|
67
|
+
expect(rows.rowsLocal.value).toEqual(data.slice(0, 2));
|
|
68
|
+
expect(countAllRowsLocal.value).toBe(4);
|
|
69
|
+
expect(actions.selectedRows.value).toEqual([]);
|
|
70
|
+
expect(props.data).toEqual(data);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each([undefined, {}, { isRowHiddenCallback: true }, { isHiddenCallback: () => true }])(
|
|
74
|
+
"keeps rows when the active action has no row callback: %j",
|
|
75
|
+
action => {
|
|
76
|
+
const data = [{ id: 1 }];
|
|
77
|
+
const { rowsLocal } = RowsAPI({ pagination: {}, rowsCountRenderPerTick: 0 }, {
|
|
78
|
+
currentMultipleActions: ref(action),
|
|
79
|
+
dataSorted: ref(data),
|
|
80
|
+
isMultipleActionsActive: ref(true),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(rowsLocal.value).toEqual(data);
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
});
|
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
isPlainObject,
|
|
15
15
|
} from "lodash-es";
|
|
16
16
|
|
|
17
|
-
export default function CountAPI(props
|
|
17
|
+
export default function CountAPI(props, {
|
|
18
|
+
data = toRef(props, "data"),
|
|
19
|
+
} = {}) {
|
|
18
20
|
const countAllRows = toRef(props, "countAllRows");
|
|
19
|
-
const data = toRef(props, "data");
|
|
20
21
|
const isTree = toRef(props, "isTree");
|
|
21
22
|
const keyChildren = toRef(props, "keyChildren");
|
|
22
23
|
const keyCountAllRowsInData = toRef(props, "keyCountAllRowsInData");
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
|
|
22
22
|
export default function MultipleActionAPI(props, { emit }, {
|
|
23
23
|
checkVisibleColumns = () => {},
|
|
24
|
+
currentMultipleActions = ref(undefined),
|
|
24
25
|
isMultipleActionsActive = ref(undefined),
|
|
25
26
|
rowsLocalAll = computed(() => []),
|
|
26
27
|
rowsLocalLength = computed(() => 0),
|
|
@@ -28,7 +29,6 @@ export default function MultipleActionAPI(props, { emit }, {
|
|
|
28
29
|
const id = toRef(props, "id");
|
|
29
30
|
const multipleActions = toRef(props, "multipleActions");
|
|
30
31
|
|
|
31
|
-
const currentMultipleActions = ref(undefined);
|
|
32
32
|
const selectedRowsIndexes = ref({});
|
|
33
33
|
const areAllRowsSelected = ref(false);
|
|
34
34
|
|
|
@@ -7,11 +7,14 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
isEqual,
|
|
10
|
+
isFunction,
|
|
10
11
|
map,
|
|
11
12
|
} from "lodash-es";
|
|
12
13
|
|
|
13
14
|
export default function RowsAPI(props, {
|
|
15
|
+
currentMultipleActions = ref(undefined),
|
|
14
16
|
dataSorted = computed(() => []),
|
|
17
|
+
isMultipleActionsActive = ref(undefined),
|
|
15
18
|
limit = ref(0),
|
|
16
19
|
offset = ref(0),
|
|
17
20
|
setEmptySelectedRowsIndexes = () => {},
|
|
@@ -27,13 +30,22 @@ export default function RowsAPI(props, {
|
|
|
27
30
|
let rowsLocalIndex = 0;
|
|
28
31
|
let rowsLocalInterval = undefined;
|
|
29
32
|
|
|
33
|
+
const dataFiltered = computed(() => {
|
|
34
|
+
if (isMultipleActionsActive.value && isFunction(currentMultipleActions.value?.isRowHiddenCallback)) {
|
|
35
|
+
return dataSorted.value.filter((row, rowIndex) => {
|
|
36
|
+
return !currentMultipleActions.value.isRowHiddenCallback({ row, rowIndex });
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return dataSorted.value;
|
|
40
|
+
});
|
|
41
|
+
|
|
30
42
|
const dataPaginated = computed(() => {
|
|
31
43
|
if (limit.value && !pagination.value.isOutside && usePaginationLocal.value) {
|
|
32
44
|
const INDEX_START = offset.value;
|
|
33
45
|
const INDEX_END = INDEX_START + limit.value;
|
|
34
|
-
return
|
|
46
|
+
return dataFiltered.value.slice(INDEX_START, INDEX_END);
|
|
35
47
|
}
|
|
36
|
-
return
|
|
48
|
+
return dataFiltered.value;
|
|
37
49
|
});
|
|
38
50
|
|
|
39
51
|
const rowsLocalAll = computed(() => {
|
|
@@ -110,6 +122,7 @@ export default function RowsAPI(props, {
|
|
|
110
122
|
|
|
111
123
|
return {
|
|
112
124
|
addRow,
|
|
125
|
+
dataFiltered,
|
|
113
126
|
deleteRow,
|
|
114
127
|
hasRows,
|
|
115
128
|
rowsLocal,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
export default function VariablesAPI() {
|
|
6
6
|
const columnsScrollInvisible = ref([]);
|
|
7
|
+
const currentMultipleActions = ref(undefined);
|
|
7
8
|
const indexFirstScrollInvisibleColumn = ref(undefined);
|
|
8
9
|
const isMultipleActionsActive = ref(undefined);
|
|
9
10
|
const modelColumnsVisibleLocal = ref({});
|
|
@@ -12,6 +13,7 @@ export default function VariablesAPI() {
|
|
|
12
13
|
|
|
13
14
|
return {
|
|
14
15
|
columnsScrollInvisible,
|
|
16
|
+
currentMultipleActions,
|
|
15
17
|
indexFirstScrollInvisibleColumn,
|
|
16
18
|
isMultipleActionsActive,
|
|
17
19
|
modelColumnsVisibleLocal,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
computed,
|
|
2
3
|
h,
|
|
3
4
|
} from "vue";
|
|
4
5
|
|
|
6
|
+
import AMobileAPI from "../compositionAPI/AMobileAPI";
|
|
5
7
|
import AriaLabelAPI from "./compositionAPI/AriaLabelAPI";
|
|
6
8
|
import AttributesAPI from "./compositionAPI/AttributesAPI";
|
|
7
9
|
import HtmlAPI from "./compositionAPI/HtmlAPI";
|
|
@@ -10,6 +12,17 @@ import RestAttributesAPI from "./compositionAPI/RestAttributesAPI";
|
|
|
10
12
|
import TextAPI from "./compositionAPI/TextAPI";
|
|
11
13
|
import TextAfterBeforeAPI from "./compositionAPI/TextAfterBeforeAPI";
|
|
12
14
|
import TitleAPI from "./compositionAPI/TitleAPI";
|
|
15
|
+
import {
|
|
16
|
+
isPlaceholderTranslate,
|
|
17
|
+
} from "./compositionAPI/UtilsAPI";
|
|
18
|
+
import {
|
|
19
|
+
timeTranslationLastChanged,
|
|
20
|
+
translation,
|
|
21
|
+
} from "./compositionAPI/ATranslationAPI";
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
isPlainObject,
|
|
25
|
+
} from "lodash-es";
|
|
13
26
|
|
|
14
27
|
export default {
|
|
15
28
|
name: "ATranslation",
|
|
@@ -28,6 +41,10 @@ export default {
|
|
|
28
41
|
required: false,
|
|
29
42
|
default: undefined,
|
|
30
43
|
},
|
|
44
|
+
hideWithoutTranslation: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
required: false,
|
|
47
|
+
},
|
|
31
48
|
html: {
|
|
32
49
|
type: [String, Number, Object, Array],
|
|
33
50
|
required: false,
|
|
@@ -127,9 +144,34 @@ export default {
|
|
|
127
144
|
hasTextBefore,
|
|
128
145
|
});
|
|
129
146
|
|
|
147
|
+
const {
|
|
148
|
+
isMobileWidth,
|
|
149
|
+
} = AMobileAPI();
|
|
150
|
+
|
|
151
|
+
const hasMissingTranslation = computed(() => {
|
|
152
|
+
if (!props.hideWithoutTranslation || !timeTranslationLastChanged.value) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const content = hasText.value ? props.text : hasSafeHtml.value ? props.safeHtml : props.html;
|
|
156
|
+
return [content, props.textBefore, props.textAfter, props.title, props.placeholder, props.ariaLabel]
|
|
157
|
+
.some(value => {
|
|
158
|
+
const valueForCurrentDevice = isPlainObject(value) ?
|
|
159
|
+
value[isMobileWidth.value ? "mobile" : "desktop"] :
|
|
160
|
+
value;
|
|
161
|
+
return [].concat(valueForCurrentDevice).some(text => {
|
|
162
|
+
if (!isPlaceholderTranslate(text)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const translated = translation?.[text];
|
|
166
|
+
return translated === undefined || translated === null || translated === "";
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
130
171
|
return {
|
|
131
172
|
ariaLabelAttributes,
|
|
132
173
|
attributesLocal,
|
|
174
|
+
hasMissingTranslation,
|
|
133
175
|
hasText,
|
|
134
176
|
hasTextAfter,
|
|
135
177
|
hasTextBefore,
|
|
@@ -144,6 +186,10 @@ export default {
|
|
|
144
186
|
};
|
|
145
187
|
},
|
|
146
188
|
render() {
|
|
189
|
+
if (this.hasMissingTranslation) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
147
193
|
if (this.hasText) {
|
|
148
194
|
return h(this.tag, {
|
|
149
195
|
...this.attributesLocal,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nextTick,
|
|
3
|
+
} from "vue";
|
|
4
|
+
import {
|
|
5
|
+
afterEach,
|
|
6
|
+
beforeEach,
|
|
7
|
+
describe,
|
|
8
|
+
expect,
|
|
9
|
+
it,
|
|
10
|
+
} from "vitest";
|
|
11
|
+
import {
|
|
12
|
+
mount,
|
|
13
|
+
} from "@vue/test-utils";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
isMobileWidth,
|
|
17
|
+
} from "../../compositionAPI/AMobileAPI";
|
|
18
|
+
import {
|
|
19
|
+
setI18n,
|
|
20
|
+
setLanguage,
|
|
21
|
+
toggleTranslate,
|
|
22
|
+
updateTranslation,
|
|
23
|
+
} from "../compositionAPI/ATranslationAPI";
|
|
24
|
+
|
|
25
|
+
import ATranslation from "../ATranslation";
|
|
26
|
+
|
|
27
|
+
describe("ATranslation hideWithoutTranslation", () => {
|
|
28
|
+
let wrapper;
|
|
29
|
+
|
|
30
|
+
beforeEach(async() => {
|
|
31
|
+
setI18n({ de: { _PRESENT_: "Translated", _ZERO_: 0, _EMPTY_: "", _NULL_: null } });
|
|
32
|
+
setLanguage("de");
|
|
33
|
+
toggleTranslate(true);
|
|
34
|
+
isMobileWidth.value = false;
|
|
35
|
+
updateTranslation();
|
|
36
|
+
await nextTick();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
wrapper?.unmount();
|
|
41
|
+
setI18n({});
|
|
42
|
+
updateTranslation();
|
|
43
|
+
isMobileWidth.value = undefined;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("keeps the existing fallback unless enabled", async() => {
|
|
47
|
+
wrapper = mount(ATranslation, { props: { text: "_MISSING_" } });
|
|
48
|
+
expect(wrapper.text()).toBe("_MISSING_");
|
|
49
|
+
await wrapper.setProps({ hideWithoutTranslation: true });
|
|
50
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
51
|
+
await wrapper.setProps({ hideWithoutTranslation: false });
|
|
52
|
+
expect(wrapper.text()).toBe("_MISSING_");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it.each(["text", "html", "safeHtml", "title", "placeholder", "ariaLabel", "textBefore", "textAfter"])(
|
|
56
|
+
"hides the whole element for a missing %s translation, including its slot",
|
|
57
|
+
prop => {
|
|
58
|
+
wrapper = mount(ATranslation, {
|
|
59
|
+
props: { [prop]: "_MISSING_", hideWithoutTranslation: true },
|
|
60
|
+
slots: { default: "Slot content" },
|
|
61
|
+
});
|
|
62
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
it.each(["_EMPTY_", "_NULL_", "_MISSING_"])("hides missing or empty translation %s", text => {
|
|
67
|
+
wrapper = mount(ATranslation, { props: { text, hideWithoutTranslation: true } });
|
|
68
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it.each([
|
|
72
|
+
["_PRESENT_", "Translated"],
|
|
73
|
+
["_ZERO_", "0"],
|
|
74
|
+
["Literal text", "Literal text"],
|
|
75
|
+
[0, "0"],
|
|
76
|
+
])("renders valid content %s", (text, expected) => {
|
|
77
|
+
wrapper = mount(ATranslation, { props: { text, hideWithoutTranslation: true } });
|
|
78
|
+
expect(wrapper.find("div").exists()).toBe(true);
|
|
79
|
+
expect(wrapper.text()).toBe(expected);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("checks all array entries", async() => {
|
|
83
|
+
wrapper = mount(ATranslation, {
|
|
84
|
+
props: { text: ["Literal", "_PRESENT_", "_MISSING_"], hideWithoutTranslation: true },
|
|
85
|
+
});
|
|
86
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
87
|
+
await wrapper.setProps({ text: ["Literal", "_PRESENT_"] });
|
|
88
|
+
expect(wrapper.text()).toBe("Literal Translated");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("checks only the current device and rendered content prop", async() => {
|
|
92
|
+
wrapper = mount(ATranslation, {
|
|
93
|
+
props: {
|
|
94
|
+
text: { desktop: "_PRESENT_", mobile: "_MISSING_" },
|
|
95
|
+
html: "_MISSING_",
|
|
96
|
+
hideWithoutTranslation: true,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
expect(wrapper.text()).toBe("Translated");
|
|
100
|
+
isMobileWidth.value = true;
|
|
101
|
+
await nextTick();
|
|
102
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("reacts to loading translations and changing languages", async() => {
|
|
106
|
+
setLanguage("unloaded");
|
|
107
|
+
await nextTick();
|
|
108
|
+
wrapper = mount(ATranslation, { props: { text: "_PRESENT_", hideWithoutTranslation: true } });
|
|
109
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
110
|
+
setI18n({ de: { _PRESENT_: "Loaded" }, unloaded: { _PRESENT_: "Arrived" } });
|
|
111
|
+
updateTranslation();
|
|
112
|
+
await nextTick();
|
|
113
|
+
expect(wrapper.text()).toBe("Arrived");
|
|
114
|
+
setLanguage("de");
|
|
115
|
+
await nextTick();
|
|
116
|
+
expect(wrapper.text()).toBe("Loaded");
|
|
117
|
+
setLanguage("missing");
|
|
118
|
+
await nextTick();
|
|
119
|
+
expect(wrapper.find("div").exists()).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|