Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(example): restore slider for vue example #6529

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions examples/vue/e-commerce/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@
</template>
</ais-panel>

<ais-panel>
<template #header> Price </template>

<template #default>
<ais-range-input attribute="price">
<template
#default="{ currentRefinement, range, refine, canRefine }"
>
<vue-slider
:min="range.min"
:max="range.max"
:value="toValue(currentRefinement, range)"
:disabled="!canRefine"
:lazy="true"
:use-keyboard="true"
:enable-cross="false"
tooltip="always"
:duration="0"
@change="refine({ min: $event[0], max: $event[1] })"
>
<template #dot="{ index, value }">
<div
:aria-valuemin="range.min"
:aria-valuemax="range.max"
:aria-valuenow="value"
:data-handle-key="index"
class="vue-slider-dot-handle"
role="slider"
tabindex="0"
/>
</template>
<template #tooltip="{ value }">
{{ formatNumber(value) }}
</template>
</vue-slider>
</template>
</ais-range-input>
</template>
</ais-panel>

<ais-panel>
<template #header> Free shipping </template>

Expand Down Expand Up @@ -450,6 +490,7 @@

<script>
import { liteClient as algoliasearch } from 'algoliasearch/lite';
import VueSlider from 'vue-slider-component';
import getRouting from './routing';
import { formatNumber } from './utils';
Expand All @@ -458,6 +499,7 @@ import NoResults from './widgets/NoResults.vue';
export default {
components: {
VueSlider,
ClearRefinements,
NoResults,
},
Expand Down
5 changes: 5 additions & 0 deletions examples/vue/e-commerce/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ import commonjs from 'vite-plugin-commonjs';

export default defineConfig({
plugins: [commonjs(), vue()],
build: {
commonjsOptions: {
requireReturnsDefault: 'preferred',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
},
});
54 changes: 23 additions & 31 deletions tests/e2e/specs/initial-state-from-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,25 @@ export function createInitialStateFromRouteTestSuite(flavor: string) {
expect(brand).toEqual('KitchenAid');
});

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

expect(lowerPrice).toEqual(50);
expect(upperPrice).toEqual(350);
});
expect(lowerPrice).toEqual(50);
expect(upperPrice).toEqual(350);
});

it('must have free shipping box checked', async () => {
const freeShipping = await browser.getToggleRefinementStatus();
it('must have free shipping box checked', async () => {
const freeShipping = await browser.getToggleRefinementStatus();

expect(freeShipping).toEqual(true);
});
expect(freeShipping).toEqual(true);
});

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

expect(rating).toEqual('4 & up');
});
}
expect(rating).toEqual('4 & up');
});

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

if (flavor !== 'vue') {
it('sets lower price to $250 and the upper price to $1250 in the price range', async () => {
// Depending of the steps calculation there can be a difference between
// the wanted value and the actual value of the slider, so we store
// the actual value to use it in for subsequent tests
priceBounds.lower = await browser.dragRangeSliderLowerBoundTo(250);
priceBounds.upper = await browser.dragRangeSliderUpperBoundTo(1250);
});
}
it('sets lower price to $250 and the upper price to $1250 in the price range', async () => {
// Depending of the steps calculation there can be a difference between
// the wanted value and the actual value of the slider, so we store
// the actual value to use it in for subsequent tests
priceBounds.lower = await browser.dragRangeSliderLowerBoundTo(250);
priceBounds.upper = await browser.dragRangeSliderUpperBoundTo(1250);
});

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

const range =
flavor === 'vue' ||
searchParams.get('price') ===
`${priceBounds.lower}:${priceBounds.upper}`;

return (
pathname ===
`/${root}search/Appliances%2FRanges%2C+Cooktops+%26+Ovens/` &&
searchParams.get('query') === 'cooktop' &&
searchParams.get('page') === '2' &&
searchParams.get('brands') === 'Whirlpool' &&
searchParams.get('rating') === '3' &&
range &&
searchParams.get('price') ===
`${priceBounds.lower}:${priceBounds.upper}` &&
searchParams.get('sortBy') === 'instant_search_price_asc' &&
searchParams.get('hitsPerPage') === '64'
);
Expand Down
5 changes: 0 additions & 5 deletions tests/e2e/specs/price-range.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export function createPriceRangeTestSuite(flavor: string) {
const root = `examples/${flavor}/e-commerce/`;

if (flavor === 'vue') {
// currently no slider on Vue
return;
}

describe('search on specific price range', () => {
let lowerBound: number;
let upperBound: number;
Expand Down
Loading