@shopbite-de/storefront 1.26.0 → 1.26.1
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/CLAUDE.md +1 -1
- package/app/components/Product/CrossSelling.vue +137 -24
- package/app/components/Product/DeselectIngredient.vue +9 -2
- package/app/components/Product/Detail.vue +16 -18
- package/app/components/Product/QuickView.vue +5 -4
- package/docs/notes/2026-09-17-quick-view-compact-options.md +63 -0
- package/package.json +1 -1
- package/test/nuxt/ProductCrossSelling.test.ts +99 -0
package/CLAUDE.md
CHANGED
|
@@ -94,7 +94,7 @@ The storefront reads plain Shopware entities with fixed names; seed data must ma
|
|
|
94
94
|
|
|
95
95
|
- **Navigation:** menu sections are the children of the sales channel navigation root (`readNavigation main-navigation`), optionally scoped by `runtimeConfig.public.shopBite.menuCategoryId`. Category icon comes from the custom field `shopbite_category_icon` (icones.js.org name such as `i-lucide-pizza`), set by the ShopBite plugin.
|
|
96
96
|
- **Property groups:** `Hauptzutaten` (ingredients on the card, deselectable on the detail page, removed ones are appended to the cart label with "-"), `Vegetarisch` and `Vegan` with the option `Ja` (diet badges), `Küche` (kitchen badge). Filterable groups appear as listing filters.
|
|
97
|
-
- **Extras:** product cross-sellings of type `productList`; the cross-selling name is the label ("Extras", "Beilagen"), the assigned products need a price and sales-channel visibility but no category. Selected extras are sent as children of a `container` line item (`useAddToCart.ts`, handled by the ShopBite plugin). The product card has no buttons: the card opens the quick view drawer (`Product/QuickView.vue`), whose state is the `produkt` query parameter (product number) via `useProductQuickView` (#325).
|
|
97
|
+
- **Extras:** product cross-sellings of type `productList`; the cross-selling name is the label ("Extras", "Beilagen"), the assigned products need a price and sales-channel visibility but no category. In the quick view each cross-selling is a collapsible checkbox list that shows 6 entries of a long list and a search field above 15 entries (`Product/CrossSelling.vue`). Selected extras are sent as children of a `container` line item (`useAddToCart.ts`, handled by the ShopBite plugin). The product card has no buttons: the card opens the quick view drawer (`Product/QuickView.vue`), whose state is the `produkt` query parameter (product number) via `useProductQuickView` (#325).
|
|
98
98
|
- **Custom fields on products:** `shopbite_receipt_print_type` (`number` prints the menu number on the receipt, `label` prints the name) and `shopbite_delivery_time_factor` (int) and `shopbite_cart_upsell` (bool, suggests the product on the order confirmation step `/bestellung/bestaetigen` via `useCartUpsell`; variant parents are never suggested, a flag on a parent applies to its variants), all from the ShopBite plugin.
|
|
99
99
|
- **Variants:** standard configurator settings (`Product/Configurator.vue`); `server/api/product/variant.get.ts` resolves a variant by option ids.
|
|
100
100
|
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
|
|
7
7
|
// The extras are loaded by useProductDetail together with the product, so
|
|
8
8
|
// the list renders once and stays put when a variant is switched.
|
|
9
|
-
defineProps<{
|
|
9
|
+
const props = defineProps<{
|
|
10
10
|
associations: AssociationItem[];
|
|
11
11
|
}>();
|
|
12
12
|
|
|
@@ -14,50 +14,163 @@ const emit = defineEmits<{
|
|
|
14
14
|
"extras-selected": [selectedExtras: AssociationItemProduct[]];
|
|
15
15
|
}>();
|
|
16
16
|
|
|
17
|
+
// Long extras lists made the quick view a long scroll: a group shows its first
|
|
18
|
+
// entries, the rest on request, and a search field once the list is long.
|
|
19
|
+
const PREVIEW_LIMIT = 6;
|
|
20
|
+
const SEARCH_THRESHOLD = 15;
|
|
21
|
+
|
|
22
|
+
const { getFormattedPrice } = useCommercePrice();
|
|
23
|
+
|
|
17
24
|
const selectedExtras = ref<AssociationItemProduct[]>([]);
|
|
25
|
+
// Only the first group starts open, the others show their selection summary.
|
|
26
|
+
const openGroups = ref<string[]>(
|
|
27
|
+
props.associations[0] ? [props.associations[0].label] : [],
|
|
28
|
+
);
|
|
29
|
+
const expandedGroups = ref<string[]>([]);
|
|
30
|
+
const queries = ref<Record<string, string>>({});
|
|
18
31
|
|
|
19
32
|
const isSelected = (extra: AssociationItemProduct) =>
|
|
20
33
|
selectedExtras.value.some((selected) => selected.value === extra.value);
|
|
21
34
|
|
|
22
|
-
function
|
|
23
|
-
selectedExtras.value =
|
|
24
|
-
? selectedExtras.value
|
|
25
|
-
:
|
|
35
|
+
function setSelected(extra: AssociationItemProduct, selected: boolean) {
|
|
36
|
+
selectedExtras.value = selected
|
|
37
|
+
? [...selectedExtras.value, extra]
|
|
38
|
+
: selectedExtras.value.filter((item) => item.value !== extra.value);
|
|
26
39
|
}
|
|
27
40
|
|
|
41
|
+
function toggleGroup(label: string) {
|
|
42
|
+
openGroups.value = openGroups.value.includes(label)
|
|
43
|
+
? openGroups.value.filter((open) => open !== label)
|
|
44
|
+
: [...openGroups.value, label];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function visibleProducts(association: AssociationItem) {
|
|
48
|
+
const query = queries.value[association.label]?.trim().toLowerCase();
|
|
49
|
+
if (query) {
|
|
50
|
+
return association.products.filter((extra) =>
|
|
51
|
+
extra.label.toLowerCase().includes(query),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
// Hiding one or two entries behind a button saves less than the button costs.
|
|
55
|
+
const collapsed =
|
|
56
|
+
association.products.length > PREVIEW_LIMIT + 2 &&
|
|
57
|
+
!expandedGroups.value.includes(association.label);
|
|
58
|
+
return collapsed
|
|
59
|
+
? association.products.slice(0, PREVIEW_LIMIT)
|
|
60
|
+
: association.products;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function hiddenCount(association: AssociationItem) {
|
|
64
|
+
if (queries.value[association.label]?.trim()) return 0;
|
|
65
|
+
return association.products.length - visibleProducts(association).length;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function summary(association: AssociationItem) {
|
|
69
|
+
const selected = association.products.filter(isSelected);
|
|
70
|
+
if (selected.length === 0) return "optional";
|
|
71
|
+
const price = selected.reduce(
|
|
72
|
+
(sum, extra) => sum + (extra.unitPrice ?? 0),
|
|
73
|
+
0,
|
|
74
|
+
);
|
|
75
|
+
return `${selected.length} gewählt · +${getFormattedPrice(price)}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const baseId = useId();
|
|
79
|
+
const groupId = (index: number) => `${baseId}-extras-${index}`;
|
|
80
|
+
|
|
28
81
|
watch(selectedExtras, () => emit("extras-selected", selectedExtras.value));
|
|
29
82
|
</script>
|
|
30
83
|
|
|
31
84
|
<template>
|
|
32
85
|
<div
|
|
33
|
-
v-for="association in associations"
|
|
86
|
+
v-for="(association, index) in associations"
|
|
34
87
|
:key="association.label"
|
|
35
|
-
class="flex flex-col
|
|
88
|
+
class="flex flex-col"
|
|
36
89
|
>
|
|
37
|
-
<
|
|
90
|
+
<button
|
|
91
|
+
type="button"
|
|
92
|
+
class="flex items-center gap-2 py-1 text-start"
|
|
93
|
+
:aria-expanded="openGroups.includes(association.label)"
|
|
94
|
+
:aria-controls="groupId(index)"
|
|
95
|
+
@click="toggleGroup(association.label)"
|
|
96
|
+
>
|
|
97
|
+
<UIcon
|
|
98
|
+
name="i-lucide-chevron-down"
|
|
99
|
+
class="size-5 shrink-0 text-muted transition-transform"
|
|
100
|
+
:class="{ '-rotate-90': !openGroups.includes(association.label) }"
|
|
101
|
+
/>
|
|
38
102
|
<span class="font-semibold text-highlighted">{{
|
|
39
103
|
association.label
|
|
40
104
|
}}</span>
|
|
41
|
-
<span
|
|
42
|
-
|
|
105
|
+
<span
|
|
106
|
+
class="ms-auto text-xs"
|
|
107
|
+
:class="
|
|
108
|
+
association.products.some(isSelected)
|
|
109
|
+
? 'font-medium text-primary'
|
|
110
|
+
: 'text-muted'
|
|
111
|
+
"
|
|
112
|
+
>
|
|
113
|
+
{{ summary(association) }}
|
|
114
|
+
</span>
|
|
115
|
+
</button>
|
|
116
|
+
|
|
43
117
|
<div
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
118
|
+
v-if="openGroups.includes(association.label)"
|
|
119
|
+
:id="groupId(index)"
|
|
120
|
+
class="flex flex-col gap-1 pt-2"
|
|
47
121
|
>
|
|
122
|
+
<UInput
|
|
123
|
+
v-if="association.products.length > SEARCH_THRESHOLD"
|
|
124
|
+
v-model="queries[association.label]"
|
|
125
|
+
icon="i-lucide-search"
|
|
126
|
+
:placeholder="`${association.label} durchsuchen`"
|
|
127
|
+
:aria-label="`${association.label} durchsuchen`"
|
|
128
|
+
class="mb-1 w-full"
|
|
129
|
+
/>
|
|
130
|
+
<div
|
|
131
|
+
class="flex flex-col divide-y divide-default"
|
|
132
|
+
role="group"
|
|
133
|
+
:aria-label="association.label"
|
|
134
|
+
>
|
|
135
|
+
<UCheckbox
|
|
136
|
+
v-for="extra in visibleProducts(association)"
|
|
137
|
+
:key="extra.value"
|
|
138
|
+
variant="card"
|
|
139
|
+
size="lg"
|
|
140
|
+
:model-value="isSelected(extra)"
|
|
141
|
+
:ui="{
|
|
142
|
+
root: 'items-center rounded-none border-0 px-1 py-2.5',
|
|
143
|
+
wrapper: 'ms-3',
|
|
144
|
+
label: 'flex items-baseline justify-between gap-3 font-normal',
|
|
145
|
+
}"
|
|
146
|
+
@update:model-value="setSelected(extra, $event === true)"
|
|
147
|
+
>
|
|
148
|
+
<template #label>
|
|
149
|
+
<span>{{ extra.label }}</span>
|
|
150
|
+
<span class="shrink-0 text-sm text-muted tabular-nums">
|
|
151
|
+
+{{ extra.price }}
|
|
152
|
+
</span>
|
|
153
|
+
</template>
|
|
154
|
+
</UCheckbox>
|
|
155
|
+
</div>
|
|
156
|
+
<p
|
|
157
|
+
v-if="
|
|
158
|
+
queries[association.label]?.trim() &&
|
|
159
|
+
visibleProducts(association).length === 0
|
|
160
|
+
"
|
|
161
|
+
class="py-2 text-sm text-muted"
|
|
162
|
+
>
|
|
163
|
+
Keine Treffer
|
|
164
|
+
</p>
|
|
48
165
|
<UButton
|
|
49
|
-
v-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
:icon="isSelected(extra) ? 'i-lucide-check' : 'i-lucide-plus'"
|
|
56
|
-
:aria-pressed="isSelected(extra)"
|
|
57
|
-
@click="toggle(extra)"
|
|
166
|
+
v-if="hiddenCount(association) > 0"
|
|
167
|
+
variant="link"
|
|
168
|
+
color="primary"
|
|
169
|
+
trailing-icon="i-lucide-chevron-down"
|
|
170
|
+
class="self-start px-1"
|
|
171
|
+
@click="expandedGroups = [...expandedGroups, association.label]"
|
|
58
172
|
>
|
|
59
|
-
{{
|
|
60
|
-
<span class="font-normal opacity-80">+{{ extra.price }}</span>
|
|
173
|
+
Alle {{ association.products.length }} anzeigen
|
|
61
174
|
</UButton>
|
|
62
175
|
</div>
|
|
63
176
|
</div>
|
|
@@ -28,7 +28,14 @@ watch(deselected, () => emit("ingredients-deselected", deselected.value));
|
|
|
28
28
|
|
|
29
29
|
<template>
|
|
30
30
|
<div v-if="ingredients.length > 0" class="flex flex-col gap-2">
|
|
31
|
-
|
|
31
|
+
<!-- The quick view lists the ingredients only here (no chip row above
|
|
32
|
+
repeating them): tapping one removes it from the order. Both states
|
|
33
|
+
carry an icon of the same size, so toggling a chip keeps its width
|
|
34
|
+
and never rewraps the row (the drawer grew on phones). -->
|
|
35
|
+
<div class="flex items-baseline justify-between">
|
|
36
|
+
<span class="font-semibold text-highlighted">Zutaten</span>
|
|
37
|
+
<span class="text-xs text-muted">antippen zum Entfernen</span>
|
|
38
|
+
</div>
|
|
32
39
|
<div
|
|
33
40
|
class="flex flex-wrap gap-2"
|
|
34
41
|
role="group"
|
|
@@ -42,7 +49,7 @@ watch(deselected, () => emit("ingredients-deselected", deselected.value));
|
|
|
42
49
|
:class="{ 'line-through': deselected.includes(ingredient) }"
|
|
43
50
|
:color="deselected.includes(ingredient) ? 'error' : 'neutral'"
|
|
44
51
|
:variant="deselected.includes(ingredient) ? 'subtle' : 'outline'"
|
|
45
|
-
:icon="deselected.includes(ingredient) ? 'i-lucide-
|
|
52
|
+
:icon="deselected.includes(ingredient) ? 'i-lucide-plus' : 'i-lucide-x'"
|
|
46
53
|
:aria-pressed="deselected.includes(ingredient)"
|
|
47
54
|
:label="ingredient"
|
|
48
55
|
@click="toggle(ingredient)"
|
|
@@ -53,9 +53,10 @@ const onAddToCart = () => emit("product-added");
|
|
|
53
53
|
</script>
|
|
54
54
|
|
|
55
55
|
<template>
|
|
56
|
-
<div class="flex flex-col gap-5">
|
|
57
|
-
<!-- One placeholder in the shape of the loaded body (options,
|
|
58
|
-
ingredients), shown until product and extras are both
|
|
56
|
+
<div class="flex flex-1 flex-col gap-5">
|
|
57
|
+
<!-- One placeholder in the shape of the loaded body (options,
|
|
58
|
+
ingredients, extras), shown until product and extras are both
|
|
59
|
+
loaded. -->
|
|
59
60
|
<div v-if="pending" class="flex flex-col gap-5" aria-busy="true">
|
|
60
61
|
<div class="flex flex-col gap-2">
|
|
61
62
|
<USkeleton class="h-5 w-24" />
|
|
@@ -64,18 +65,15 @@ const onAddToCart = () => emit("product-added");
|
|
|
64
65
|
<div class="flex flex-col gap-2">
|
|
65
66
|
<USkeleton class="h-5 w-20" />
|
|
66
67
|
<div class="flex flex-wrap gap-2">
|
|
67
|
-
<USkeleton class="h-
|
|
68
|
-
<USkeleton class="h-
|
|
69
|
-
<USkeleton class="h-
|
|
70
|
-
<USkeleton class="h-
|
|
68
|
+
<USkeleton class="h-8 w-20 rounded-full" />
|
|
69
|
+
<USkeleton class="h-8 w-24 rounded-full" />
|
|
70
|
+
<USkeleton class="h-8 w-16 rounded-full" />
|
|
71
|
+
<USkeleton class="h-8 w-28 rounded-full" />
|
|
71
72
|
</div>
|
|
72
73
|
</div>
|
|
73
|
-
<div class="flex flex-col gap-
|
|
74
|
-
<USkeleton class="h-5 w-
|
|
75
|
-
<
|
|
76
|
-
<USkeleton class="h-10 w-28 rounded-full" />
|
|
77
|
-
<USkeleton class="h-10 w-24 rounded-full" />
|
|
78
|
-
</div>
|
|
74
|
+
<div class="flex flex-col gap-3">
|
|
75
|
+
<USkeleton class="h-5 w-28" />
|
|
76
|
+
<USkeleton v-for="row in 4" :key="row" class="h-7 w-full" />
|
|
79
77
|
</div>
|
|
80
78
|
</div>
|
|
81
79
|
<template v-else-if="productDetails?.configurator">
|
|
@@ -84,16 +82,16 @@ const onAddToCart = () => emit("product-added");
|
|
|
84
82
|
:c="productDetails.configurator"
|
|
85
83
|
@variant-switched="onVariantSwitched"
|
|
86
84
|
/>
|
|
87
|
-
<ProductCrossSelling
|
|
88
|
-
v-if="associationItems.length > 0"
|
|
89
|
-
:associations="associationItems"
|
|
90
|
-
@extras-selected="onExtras"
|
|
91
|
-
/>
|
|
92
85
|
<ProductDeselectIngredient
|
|
93
86
|
v-if="selectedProduct"
|
|
94
87
|
:product="selectedProduct"
|
|
95
88
|
@ingredients-deselected="onIngredientsDeselected"
|
|
96
89
|
/>
|
|
90
|
+
<ProductCrossSelling
|
|
91
|
+
v-if="associationItems.length > 0"
|
|
92
|
+
:associations="associationItems"
|
|
93
|
+
@extras-selected="onExtras"
|
|
94
|
+
/>
|
|
97
95
|
</template>
|
|
98
96
|
|
|
99
97
|
<div
|
|
@@ -61,10 +61,11 @@ function onVariantSelected(variant: Schemas["Product"]) {
|
|
|
61
61
|
{{ description }}
|
|
62
62
|
</template>
|
|
63
63
|
<template #body>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
<!-- Diet badges only: the ingredients are listed once, in the
|
|
65
|
+
deselectable "Zutaten" section of ProductDetail. -->
|
|
66
|
+
<div class="flex flex-wrap gap-1.5 empty:hidden">
|
|
67
|
+
<ProductCardDietBadges :sorted-properties="sortedProperties" />
|
|
68
|
+
</div>
|
|
68
69
|
<ProductDetail
|
|
69
70
|
v-if="product"
|
|
70
71
|
:key="product.id"
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Quick view: compact options and extras
|
|
2
|
+
|
|
3
|
+
The product quick view (`Product/QuickView.vue` → `Product/Detail.vue`) needed
|
|
4
|
+
a lot of scrolling for products with many extras. Measured on the demo shop
|
|
5
|
+
(Pizza Romana: 2 sizes, 8 extras, 6 ingredients, 390×844 viewport) the drawer
|
|
6
|
+
body was 775 px high with 598 px visible. Menus imported from Lieferando often
|
|
7
|
+
have 20–40 extras per product.
|
|
8
|
+
|
|
9
|
+
## Causes
|
|
10
|
+
|
|
11
|
+
- The ingredients were listed three times: in the description, as chips at the
|
|
12
|
+
top of the body and again as the "Ohne" buttons at the bottom.
|
|
13
|
+
- Every extra was a pill with label and price. The pills were wider than half
|
|
14
|
+
the drawer, so each one took a full row (~47 px).
|
|
15
|
+
- After scrolling, the customer no longer saw what they had chosen.
|
|
16
|
+
|
|
17
|
+
## Changes
|
|
18
|
+
|
|
19
|
+
- The body shows only the diet badges at the top. Ingredients are listed once,
|
|
20
|
+
in the deselectable "Zutaten" section (`DeselectIngredient.vue`), placed
|
|
21
|
+
before the extras.
|
|
22
|
+
- `CrossSelling.vue`: every cross-selling group is a collapsible section whose
|
|
23
|
+
header summarises the selection ("2 gewählt · +2,10 €"). Only the first group
|
|
24
|
+
starts open. Extras are checkbox rows with the price right-aligned. A group
|
|
25
|
+
with more than 8 entries shows the first 6 plus "Alle N anzeigen", and more
|
|
26
|
+
than 15 entries add a search field.
|
|
27
|
+
- `Detail.vue` fills the drawer body, so the add-to-cart button sits at the
|
|
28
|
+
bottom of the desktop side panel.
|
|
29
|
+
|
|
30
|
+
Result on the demo product: 681 px body height (was 775). With 24 extras and a
|
|
31
|
+
second group (mocked response) the body is 727 px, and 1490 px once all 24
|
|
32
|
+
extras are shown.
|
|
33
|
+
|
|
34
|
+
## No height jumps
|
|
35
|
+
|
|
36
|
+
The phone drawer is as high as its content (up to 92vh), so anything that
|
|
37
|
+
changes the content height while choosing makes it jump:
|
|
38
|
+
|
|
39
|
+
- A first version showed a summary line above the button ("+ Extra Käse ·
|
|
40
|
+
ohne Salami"). It appeared with the first choice and grew the drawer by
|
|
41
|
+
31 px. It was removed; the choices stay visible in the ingredient chips and
|
|
42
|
+
in the extras group header.
|
|
43
|
+
- Deselected ingredient chips used to gain an X icon, which made the chip wider
|
|
44
|
+
and could wrap the row. Both states now carry an icon of the same size (X to
|
|
45
|
+
remove, plus to add back).
|
|
46
|
+
|
|
47
|
+
Checked on the production menu of La Fattoria (12 pizzas with up to 34 extras, 360
|
|
48
|
+
and 390 px wide): toggling every ingredient and ticking an extra keeps the
|
|
49
|
+
drawer height constant.
|
|
50
|
+
|
|
51
|
+
## Performance and hydration
|
|
52
|
+
|
|
53
|
+
Measured against a `main` build with the same settings:
|
|
54
|
+
|
|
55
|
+
- JS on the first load of `/speisekarte/`: unchanged (326.6 KB gzip both).
|
|
56
|
+
- Entry CSS: +114 B gzip (UCheckbox theme).
|
|
57
|
+
- Quick view chunk loaded when the drawer opens: +2.4 KB raw (~0.9 KB gzip).
|
|
58
|
+
- Only the first 6 extras of a long group are rendered initially.
|
|
59
|
+
|
|
60
|
+
Opening `/speisekarte/?produkt=LF-27` directly reports the same two hydration
|
|
61
|
+
mismatches on `main` and on this branch (built with `debug.hydration`): the
|
|
62
|
+
`useId`-based id of the account dropdown in the header and a fragment node.
|
|
63
|
+
They are not caused by the quick view changes.
|
package/package.json
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import ProductCrossSelling from "~/components/Product/CrossSelling.vue";
|
|
4
|
+
import type { AssociationItem } from "~/types/Association";
|
|
5
|
+
|
|
6
|
+
mockNuxtImport("useCommercePrice", () => () => ({
|
|
7
|
+
getFormattedPrice: (price: number) => `${price.toFixed(2)} €`,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const group = (label: string, count: number): AssociationItem => ({
|
|
11
|
+
label,
|
|
12
|
+
products: Array.from({ length: count }, (_, index) => ({
|
|
13
|
+
label: `${label} ${index + 1}`,
|
|
14
|
+
value: `${label}-${index + 1}`,
|
|
15
|
+
price: "1.00 €",
|
|
16
|
+
unitPrice: 1,
|
|
17
|
+
})),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const rows = (wrapper: Awaited<ReturnType<typeof mountSuspended>>) =>
|
|
21
|
+
wrapper.findAll('[role="checkbox"]');
|
|
22
|
+
|
|
23
|
+
describe("ProductCrossSelling", () => {
|
|
24
|
+
it("opens only the first group", async () => {
|
|
25
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
26
|
+
props: { associations: [group("Extras", 3), group("Saucen", 2)] },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const toggles = wrapper.findAll("button[aria-expanded]");
|
|
30
|
+
expect(toggles.map((toggle) => toggle.attributes("aria-expanded"))).toEqual(
|
|
31
|
+
["true", "false"],
|
|
32
|
+
);
|
|
33
|
+
expect(rows(wrapper)).toHaveLength(3);
|
|
34
|
+
|
|
35
|
+
await toggles[1]!.trigger("click");
|
|
36
|
+
expect(rows(wrapper)).toHaveLength(5);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("shows every entry of a short list", async () => {
|
|
40
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
41
|
+
props: { associations: [group("Extras", 8)] },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(rows(wrapper)).toHaveLength(8);
|
|
45
|
+
expect(wrapper.text()).not.toContain("anzeigen");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("shows the first entries of a long list and the rest on request", async () => {
|
|
49
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
50
|
+
props: { associations: [group("Extras", 12)] },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(rows(wrapper)).toHaveLength(6);
|
|
54
|
+
const showAll = wrapper
|
|
55
|
+
.findAll("button")
|
|
56
|
+
.find((button) => button.text().includes("Alle 12 anzeigen"));
|
|
57
|
+
await showAll!.trigger("click");
|
|
58
|
+
expect(rows(wrapper)).toHaveLength(12);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("offers a search field for very long lists", async () => {
|
|
62
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
63
|
+
props: { associations: [group("Extras", 20)] },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const search = wrapper.find('input[aria-label="Extras durchsuchen"]');
|
|
67
|
+
await search.setValue("extras 1");
|
|
68
|
+
// "Extras 1" and "Extras 10" … "Extras 19"
|
|
69
|
+
expect(rows(wrapper)).toHaveLength(11);
|
|
70
|
+
|
|
71
|
+
await search.setValue("nichts");
|
|
72
|
+
expect(rows(wrapper)).toHaveLength(0);
|
|
73
|
+
expect(wrapper.text()).toContain("Keine Treffer");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("emits the selection and summarises it in the group header", async () => {
|
|
77
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
78
|
+
props: { associations: [group("Extras", 3), group("Saucen", 2)] },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(wrapper.text()).toContain("optional");
|
|
82
|
+
await rows(wrapper)[0]!.trigger("click");
|
|
83
|
+
await rows(wrapper)[2]!.trigger("click");
|
|
84
|
+
|
|
85
|
+
const emitted = wrapper.emitted("extras-selected")!;
|
|
86
|
+
expect(emitted.at(-1)![0]).toMatchObject([
|
|
87
|
+
{ value: "Extras-1" },
|
|
88
|
+
{ value: "Extras-3" },
|
|
89
|
+
]);
|
|
90
|
+
expect(wrapper.find("button[aria-expanded]").text()).toContain(
|
|
91
|
+
"2 gewählt · +2.00 €",
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await rows(wrapper)[0]!.trigger("click");
|
|
95
|
+
expect(wrapper.emitted("extras-selected")!.at(-1)![0]).toMatchObject([
|
|
96
|
+
{ value: "Extras-3" },
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
});
|