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

fix: adjust to vue 3 render function API #1596

Merged
merged 1 commit into from
Aug 14, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mount, Wrapper } from '@vue/test-utils';
import Vue from 'vue';
import { mount, VueWrapper } from '@vue/test-utils';
import { NumberRangeFilter } from '@empathyco/x-types';
import { getNumberRangeFilterStub } from '../../../../__stubs__/filters-stubs.factory';
import BasePriceFilterLabel from '../base-price-filter-label.vue';
Expand All @@ -10,7 +9,7 @@ function renderBasePriceLabel({
lessThan = 'Less than {max}',
from = 'More than {min}',
fromTo = 'From {min} to {max}'
}: RenderBasePriceLabelOptions): Wrapper<Vue> {
}: RenderBasePriceLabelOptions): VueWrapper {
return mount(
{
components: { BasePriceFilterLabel },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { SimpleFilter } from '@empathyco/x-types';
import Vue from 'vue';
import { mount, Wrapper } from '@vue/test-utils';
import { mount, VueWrapper } from '@vue/test-utils';
import { getSimpleFilterStub } from '../../../../__stubs__/filters-stubs.factory';
import { getDataTestSelector } from '../../../../__tests__/utils';
import BaseRatingFilterLabel from '../base-rating-filter-label.vue';

function renderBaseRatingLabel({
template = '<BaseRatingFilterLabel :filter="filter"/>',
filter = getSimpleFilterStub({ label: '3' })
}: RenderBaseRatingLabelOptions = {}): Wrapper<Vue> {
}: RenderBaseRatingLabelOptions = {}): VueWrapper {
return mount(
{
components: { BaseRatingFilterLabel },
Expand Down Expand Up @@ -37,23 +36,27 @@ describe('testing Base Rating Filter Label component', () => {
const widthFilledWrapper = `${(parseFloat(value) * 100) / max}%`;
const wrapper = renderBaseRatingLabel({ filter });

expect(wrapper.find(getDataTestSelector('rating-filled')).element.style.width).toEqual(
widthFilledWrapper
);
expect(
(wrapper.find(getDataTestSelector('rating-filled')).element as HTMLElement).style.width
).toEqual(widthFilledWrapper);
});

it('renders the default value 0 if the filter label is a negative number', () => {
const filter = getSimpleFilterStub({ label: '-2' });
const wrapper = renderBaseRatingLabel({ filter });

expect(wrapper.find(getDataTestSelector('rating-filled')).element.style.width).toEqual('0%');
expect(
(wrapper.find(getDataTestSelector('rating-filled')).element as HTMLElement).style.width
).toEqual('0%');
});

it('renders the default value 0 if the filter label is a not valid number string', () => {
const filter = getSimpleFilterStub({ label: 'abc' });
const wrapper = renderBaseRatingLabel({ filter });

expect(wrapper.find(getDataTestSelector('rating-filled')).element.style.width).toEqual('0%');
expect(
(wrapper.find(getDataTestSelector('rating-filled')).element as HTMLElement).style.width
).toEqual('0%');
});

it('renders the content overriding rating-icon-filled slot', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { computed, defineComponent, h, PropType, VNode } from 'vue';
import { computed, defineComponent, h, PropType } from 'vue';
import { RangeValue } from '@empathyco/x-types';
import BaseCurrency from '../../currency/base-currency.vue';

Expand Down Expand Up @@ -64,32 +64,26 @@
: props.fromTo;
});

const render = (): VNode => {
return () => {
const labelParts = label.value.split(/({min}|{max})/);

const children = labelParts.map(partMessage => {
if (partMessage === '{min}') {
return h('BaseCurrency', {
props: {
value: props.filter.range.min,
format: props.format
}
return h(BaseCurrency, {
value: props.filter.range.min as number,
format: props.format
});
} else if (partMessage === '{max}') {
return h('BaseCurrency', {
props: {
value: props.filter.range.max,
format: props.format
}
return h(BaseCurrency, {
value: props.filter.range.max as number,
format: props.format
});
}
return partMessage;
});

return h('span', { class: 'x-price-filter-label' }, children);
};

return render;
}
});
</script>
Expand Down
Loading