Skip to content

Commit 64a958f

Browse files
authored
chore(example): restore slider for vue example (#6529)
* chore(example): show slider * Revert "chore(vue example): remove price range (#6527)" This reverts commit 220e79f.
1 parent 220e79f commit 64a958f

File tree

4 files changed

+70
-36
lines changed

4 files changed

+70
-36
lines changed

examples/vue/e-commerce/src/App.vue

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,46 @@
115115
</template>
116116
</ais-panel>
117117

118+
<ais-panel>
119+
<template #header> Price </template>
120+
121+
<template #default>
122+
<ais-range-input attribute="price">
123+
<template
124+
#default="{ currentRefinement, range, refine, canRefine }"
125+
>
126+
<vue-slider
127+
:min="range.min"
128+
:max="range.max"
129+
:value="toValue(currentRefinement, range)"
130+
:disabled="!canRefine"
131+
:lazy="true"
132+
:use-keyboard="true"
133+
:enable-cross="false"
134+
tooltip="always"
135+
:duration="0"
136+
@change="refine({ min: $event[0], max: $event[1] })"
137+
>
138+
<template #dot="{ index, value }">
139+
<div
140+
:aria-valuemin="range.min"
141+
:aria-valuemax="range.max"
142+
:aria-valuenow="value"
143+
:data-handle-key="index"
144+
class="vue-slider-dot-handle"
145+
role="slider"
146+
tabindex="0"
147+
/>
148+
</template>
149+
<template #tooltip="{ value }">
150+
{{ formatNumber(value) }}
151+
</template>
152+
</vue-slider>
153+
</template>
154+
</ais-range-input>
155+
</template>
156+
</ais-panel>
157+
118158
<ais-panel>
119159
<template #header> Free shipping </template>
120160

@@ -450,6 +490,7 @@
450490

451491
<script>
452492
import { liteClient as algoliasearch } from 'algoliasearch/lite';
493+
import VueSlider from 'vue-slider-component';
453494
454495
import getRouting from './routing';
455496
import { formatNumber } from './utils';
@@ -458,6 +499,7 @@ import NoResults from './widgets/NoResults.vue';
458499
459500
export default {
460501
components: {
502+
VueSlider,
461503
ClearRefinements,
462504
NoResults,
463505
},

examples/vue/e-commerce/vite.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ import commonjs from 'vite-plugin-commonjs';
44

55
export default defineConfig({
66
plugins: [commonjs(), vue()],
7+
build: {
8+
commonjsOptions: {
9+
requireReturnsDefault: 'preferred',
10+
},
11+
},
712
});

tests/e2e/specs/initial-state-from-route.spec.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,25 @@ export function createInitialStateFromRouteTestSuite(flavor: string) {
3939
expect(brand).toEqual('KitchenAid');
4040
});
4141

42-
if (flavor !== 'vue') {
43-
it('must have lower price set to $50 and the upper price set to $350 in the price range', async () => {
44-
const lowerPrice = await browser.getRangeSliderLowerBoundValue();
45-
const upperPrice = await browser.getRangeSliderUpperBoundValue();
42+
it('must have lower price set to $50 and the upper price set to $350 in the price range', async () => {
43+
const lowerPrice = await browser.getRangeSliderLowerBoundValue();
44+
const upperPrice = await browser.getRangeSliderUpperBoundValue();
4645

47-
expect(lowerPrice).toEqual(50);
48-
expect(upperPrice).toEqual(350);
49-
});
46+
expect(lowerPrice).toEqual(50);
47+
expect(upperPrice).toEqual(350);
48+
});
5049

51-
it('must have free shipping box checked', async () => {
52-
const freeShipping = await browser.getToggleRefinementStatus();
50+
it('must have free shipping box checked', async () => {
51+
const freeShipping = await browser.getToggleRefinementStatus();
5352

54-
expect(freeShipping).toEqual(true);
55-
});
53+
expect(freeShipping).toEqual(true);
54+
});
5655

57-
it('must have rating "4 & up" selected in the rating menu', async () => {
58-
const rating = await browser.getSelectedRatingMenuItem();
56+
it('must have rating "4 & up" selected in the rating menu', async () => {
57+
const rating = await browser.getSelectedRatingMenuItem();
5958

60-
expect(rating).toEqual('4 & up');
61-
});
62-
}
59+
expect(rating).toEqual('4 & up');
60+
});
6361

6462
it('must have "Price descending" selected in the sort select', async () => {
6563
const sortBy = await browser.getSortByValue();
@@ -129,15 +127,13 @@ export function createInitialStateFromRouteTestSuite(flavor: string) {
129127
await browser.setSortByValue('Price ascending');
130128
});
131129

132-
if (flavor !== 'vue') {
133-
it('sets lower price to $250 and the upper price to $1250 in the price range', async () => {
134-
// Depending of the steps calculation there can be a difference between
135-
// the wanted value and the actual value of the slider, so we store
136-
// the actual value to use it in for subsequent tests
137-
priceBounds.lower = await browser.dragRangeSliderLowerBoundTo(250);
138-
priceBounds.upper = await browser.dragRangeSliderUpperBoundTo(1250);
139-
});
140-
}
130+
it('sets lower price to $250 and the upper price to $1250 in the price range', async () => {
131+
// Depending of the steps calculation there can be a difference between
132+
// the wanted value and the actual value of the slider, so we store
133+
// the actual value to use it in for subsequent tests
134+
priceBounds.lower = await browser.dragRangeSliderLowerBoundTo(250);
135+
priceBounds.upper = await browser.dragRangeSliderUpperBoundTo(1250);
136+
});
141137

142138
it('selects "64 hits per page" in the hits per page select', async () => {
143139
await browser.setHitsPerPage('64 hits per page');
@@ -153,19 +149,15 @@ export function createInitialStateFromRouteTestSuite(flavor: string) {
153149
const url = await browser.getUrl();
154150
const { pathname, searchParams } = new URL(url);
155151

156-
const range =
157-
flavor === 'vue' ||
158-
searchParams.get('price') ===
159-
`${priceBounds.lower}:${priceBounds.upper}`;
160-
161152
return (
162153
pathname ===
163154
`/${root}search/Appliances%2FRanges%2C+Cooktops+%26+Ovens/` &&
164155
searchParams.get('query') === 'cooktop' &&
165156
searchParams.get('page') === '2' &&
166157
searchParams.get('brands') === 'Whirlpool' &&
167158
searchParams.get('rating') === '3' &&
168-
range &&
159+
searchParams.get('price') ===
160+
`${priceBounds.lower}:${priceBounds.upper}` &&
169161
searchParams.get('sortBy') === 'instant_search_price_asc' &&
170162
searchParams.get('hitsPerPage') === '64'
171163
);

tests/e2e/specs/price-range.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
export function createPriceRangeTestSuite(flavor: string) {
22
const root = `examples/${flavor}/e-commerce/`;
33

4-
if (flavor === 'vue') {
5-
// currently no slider on Vue
6-
return;
7-
}
8-
94
describe('search on specific price range', () => {
105
let lowerBound: number;
116
let upperBound: number;

0 commit comments

Comments
 (0)