Skip to content

Commit

Permalink
fix filterable mixin and FiltersInline component
Browse files Browse the repository at this point in the history
  • Loading branch information
4dr1en committed Jul 23, 2024
1 parent 2aea040 commit a4ab342
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/synapse-bridge/src/mixins/filterable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { defineComponent } from 'vue'
import type { PropType } from 'vue'

import { FilterItem } from './types.ts'
import type { FilterItem } from './types.ts'

import { deepCopy } from '../../helpers/deepCopy'

import { ChipItem } from '../../elements/ChipList/types'
import type { ChipItem } from '../../elements/ChipList/types'

import slugify from 'slugify'

Expand Down Expand Up @@ -148,6 +148,7 @@ export const Filterable = defineComponent({
: undefined

filter.value = newValue
this.updateValue();

return
}
Expand All @@ -160,17 +161,20 @@ export const Filterable = defineComponent({

if (isPeriodField) {
filter.value = undefined
this.updateValue();

return
}

delete typedValue[chipValue]
filter.value = typedValue
}
this.updateValue();
},

resetFilter(filter: FilterItem): void {
filter.value = undefined
this.updateValue();
},

resetAllFilters(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ export default defineComponent({
@remove="removeChip(filter, $event)"
@reset="resetFilter(filter)"
/>

<slot
:attrs="{
modelValue: filter.value,
'onUpdate:modelValue': (value: ChipItem) =>
(filter['value'] = value),
'onUpdate:modelValue': (value: ChipItem) => {
filter.value = value
updateValue()
}
}"
:name="`${formatFilterName(filter.name)}`"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { describe, it, expect } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import { shallowMount, mount } from '@vue/test-utils'
import { vuetify } from '@tests/unit/setup'
import FiltersInline from '../'
import { locales } from '../locales'
import { defineComponent } from 'vue'
import { VTextField } from 'vuetify/lib/components/index.mjs'

describe('FiltersInline', () => {
it('renders correctly', () => {
Expand Down Expand Up @@ -65,6 +67,73 @@ describe('FiltersInline', () => {

expect(wrapper).toMatchSnapshot()
})

it ('immediately emit an update:modelValue event when a filter is added', async () => {
const testComponent = defineComponent({
components: {
FiltersInline,
VTextField,
},
template: `
<div>
<FiltersInline v-model="filters">
<template #name="{ attrs }">
<VTextField
v-bind="attrs"
label="Nom"
/>
</template>
<template #profession="{ attrs }">
<VTextField
v-bind="attrs"
label="Profession"
/>
</template>
</FiltersInline>
</div>
`,

data() {
return {
filters: [
{
name: 'name',
label: 'Nom'
},
{
name: 'profession',
label: 'Profession'
}
],
}
},
})

const wrapper = mount(testComponent, {
global: {
plugins: [vuetify],
}
})

await wrapper.find('button').trigger('click')
const FilterInlineComponent = wrapper.findComponent(FiltersInline)
const TextInput = wrapper.findComponent(VTextField)

await TextInput.setValue('John Doe')

expect(FilterInlineComponent.emitted('update:modelValue')?.[0]).toEqual([
[
{
name: 'name',
label: 'Nom',
value: 'John Doe',
}, {
name: 'profession',
label: 'Profession',
}
],
])
});
})

describe('FiltersInline locales', () => {
Expand Down

0 comments on commit a4ab342

Please sign in to comment.