Skip to content

Commit

Permalink
Merge pull request #361 from OnroerendErfgoed/develop
Browse files Browse the repository at this point in the history
release 2.2.0
  • Loading branch information
cedrikv authored Jan 29, 2025
2 parents 2d374c4 + c0bf34d commit 7e19908
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ typings/
dist/*
.DS_Store
storybook-static/*

# cypress
cypress/screenshots
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "./dist/vue-components.umd.js",
"module": "./dist/vue-components.es.js",
"typings": "./dist/src/main.d.ts",
"version": "2.1.0",
"version": "2.2.0",
"exports": {
".": {
"import": "./dist/vue-components.es.js",
Expand Down
97 changes: 76 additions & 21 deletions src/__tests__/FilterGemeente.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable vue/one-component-per-file */
import FilterGemeente from '../components/smart/FilterGemeente.vue';
import { defineComponent, ref } from 'vue';
import type { IGemeente } from '@models/locatie';
import { Niscode } from '@models/niscode.enum';

describe('FilterGemeente', () => {
describe('default', () => {
Expand All @@ -21,32 +23,85 @@ describe('FilterGemeente', () => {
const onUpdateValueSpy = cy.spy().as('onUpdateValueSpy');

cy.mount(TestComponent, { props: { 'onUpdate:value': onUpdateValueSpy } }).then(({ component }) => {
cy.wait('@dataGetGemeentenVlaamsGewest').then(() => {
cy.dataCy('filter-gemeente').click().find('.multiselect__input').type('Bertem');
cy.dataCy('filter-gemeente')
.find('.multiselect__element')
.click()
.then(() => {
expect(component.gemeenteValue).to.deep.equal({
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
});
cy.dataCy('filter-gemeente').click().find('.multiselect__input').type('Bertem');
cy.dataCy('filter-gemeente')
.find('.multiselect__element')
.click()
.then(() => {
expect(component.gemeenteValue).to.deep.equal({
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
});
});

cy.get('@onUpdateValueSpy').should('always.have.been.calledWith', {
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
cy.get('@onUpdateValueSpy').should('always.have.been.calledWith', {
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
});
});
});
});

describe('gewest prop', () => {
const TestComponent = defineComponent({
components: { FilterGemeente },
setup() {
const gemeenteValue = ref<IGemeente>();
const setValue = (value: IGemeente) => (gemeenteValue.value = value);
const gewest = Niscode.VlaamsGewest;
return { gemeenteValue, gewest, setValue };
},
template:
'<filter-gemeente api="https://test-geo.onroerenderfgoed.be/" :value="gemeenteValue" :gewest="gewest" @update:value="setValue"/>',
});

beforeEach(() => cy.mockAdressenregister());

it('fetches gemeenten with gewest constraint, search and assign an available gemeente', () => {
const onUpdateValueSpy = cy.spy().as('onUpdateValueSpy');

cy.mount(TestComponent, { props: { 'onUpdate:value': onUpdateValueSpy } }).then(({ component }) => {
cy.dataCy('filter-gemeente').click().find('.multiselect__input').type('Bertem');
cy.dataCy('filter-gemeente')
.find('.multiselect__element')
.click()
.then(() => {
expect(component.gemeenteValue).to.deep.equal({
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
});
});

cy.get('@onUpdateValueSpy').should('always.have.been.calledWith', {
niscode: '24009',
naam: 'Bertem',
provincie: {
niscode: '20001',
},
status: 'inGebruik',
});
});
});

it('fetches gemeenten with gewest constraint and search for unavailable gemeente', () => {
cy.mount(TestComponent).then(() => {
cy.dataCy('filter-gemeente').click().find('.multiselect__input').type('Brussel');
cy.dataCy('filter-gemeente')
.find('.multiselect__option span').first()
.should('have.text', 'Geen resultaten gevonden...')
});
});
});
});
18 changes: 16 additions & 2 deletions src/components/smart/FilterGemeente.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
<script setup lang="ts">
import { VlMultiselect } from '@govflanders/vl-ui-design-system-vue3';
import { computed, onBeforeMount, ref } from 'vue';
import { type IFilterGemeenteProps, Niscode } from '@models/index';
import { CrabApiService } from '@services/crab-api.service';
import type { IFilterGemeenteProps } from '@models/index';
import type { IGemeente } from '@models/locatie';
const props = withDefaults(defineProps<IFilterGemeenteProps>(), {
api: '',
value: undefined,
gewest: undefined,
});
const emit = defineEmits(['update:value']);
Expand All @@ -42,6 +43,19 @@ const gemeenten = ref<IGemeente[]>([]);
const customGemeenteLabel = (option: IGemeente) => option.naam;
onBeforeMount(async () => {
gemeenten.value = await crabApiService.getGemeenten();
const data = await crabApiService.getGemeenten();
switch (props.gewest) {
case Niscode.VlaamsGewest:
gemeenten.value = crabApiService.vlaamseGemeenten;
break;
case Niscode.WaalsGewest:
gemeenten.value = crabApiService.waalseGemeenten;
break;
case Niscode.BrusselsHoofdstedelijkGewest:
gemeenten.value = crabApiService.brusselseGemeenten;
break;
default:
gemeenten.value = data;
}
});
</script>
2 changes: 2 additions & 0 deletions src/models/filter-input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IGemeente } from './locatie';
import { Niscode } from './niscode.enum';

export type TFilterInput = string | IGemeente;

Expand Down Expand Up @@ -43,6 +44,7 @@ export interface IFilterInputRadioProps {
export interface IFilterGemeenteProps {
api: string;
value?: string;
gewest?: Niscode;
}

export interface IFilterActorProps {
Expand Down
18 changes: 17 additions & 1 deletion src/stories/smart-components/filter-gemeente.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@/scss/main.scss';
import FilterGemeente from '@components/smart/FilterGemeente.vue';
import type { Meta, StoryObj } from '@storybook/vue3';
import type { IGemeente } from '@models/locatie';
import { Niscode } from '@models/niscode.enum';

// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
const meta: Meta<typeof FilterGemeente> = {
Expand All @@ -20,12 +21,20 @@ const meta: Meta<typeof FilterGemeente> = {
},
tags: ['autodocs'],
argTypes: {
gewest: {
control: 'text',
description: 'Gewest niscode',
table: {
type: { summary: 'Niscode' },
defaultValue: { summary: undefined },
},
},
value: {
control: 'text',
description: 'Current niscode',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
defaultValue: { summary: undefined },
},
},
api: {
Expand Down Expand Up @@ -72,3 +81,10 @@ export const Default: Story = {
api: 'https://test-geo.onroerenderfgoed.be/',
},
};

export const WithGewestConstraint: Story = {
args: {
api: 'https://test-geo.onroerenderfgoed.be/',
gewest: Niscode.VlaamsGewest,
},
};

0 comments on commit 7e19908

Please sign in to comment.