Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Commit d529a1e

Browse files
committed
Add the ValueTypeDropdown value to the state
+ Added valueRelation enum type into the store + Added actions, mutations, setters and getters for valueTypeRelation + Modifed existing unit tests for mutations and actions by adding valueTypeRelation to the test Bug: T267736
1 parent a065dda commit d529a1e

File tree

10 files changed

+50
-35
lines changed

10 files changed

+50
-35
lines changed

src/components/QueryBuilder.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
:error="fieldErrors.property"
1717
/>
1818
<ValueTypeDropDown
19-
@input="onInput"
19+
v-model="selectedPropertyValueRelation"
2020
/>
2121
<TextInput
2222
class="querybuilder__rule__value"
@@ -51,6 +51,7 @@ import ValueTypeDropDown from '@/components/ValueTypeDropDown.vue';
5151
import QueryResult from '@/components/QueryResult.vue';
5252
import SearchResult from '@/data-access/SearchResult';
5353
import Property from '@/data-model/Property';
54+
import PropertyValueRelation from '@/data-model/PropertyValueRelation';
5455
import Error from '@/data-model/Error';
5556
import buildQuery from '@/sparql/buildQuery';
5657
import Validator from '@/form/Validator';
@@ -65,17 +66,14 @@ export default Vue.extend( {
6566
property: null as null | Error,
6667
value: null as null | Error,
6768
},
68-
selectedOption: '',
6969
};
7070
},
7171
methods: {
72-
onInput( value: string ): void {
73-
this.selectedOption = value;
74-
},
7572
validate(): void {
7673
const formValues = {
7774
property: this.selectedProperty,
7875
value: this.textInputValue,
76+
relation: this.selectedPropertyValueRelation,
7977
};
8078
const validator = new Validator( formValues );
8179
const validationResult = validator.validate();
@@ -103,6 +101,14 @@ export default Vue.extend( {
103101
this.$store.dispatch( 'updateProperty', selectedProperty );
104102
},
105103
},
104+
selectedPropertyValueRelation: {
105+
get(): PropertyValueRelation {
106+
return this.$store.getters.propertyValueRelation;
107+
},
108+
set( selectedPropertyValueRelation: string ): void {
109+
this.$store.dispatch( 'updatePropertyValueRelation', selectedPropertyValueRelation );
110+
},
111+
},
106112
textInputValue: {
107113
get(): string { return this.$store.getters.value; },
108114
set( value: string ): void { this.$store.dispatch( 'updateValue', value ); },

src/components/ValueTypeDropDown.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
<template>
2-
<select class="querybuilder__dropdown">
2+
<select
3+
class="querybuilder__dropdown"
4+
v-model="selected"
5+
>
36
<option
47
class="querybuilder__dropdown-option"
58
v-for="(optionItem, index) in optionItems"
6-
:value="optionItem.value"
9+
:value="optionItem"
710
:key="index"
8-
@click="$emit( 'input', optionItem.value )"
911
>
10-
{{ optionItem.value }}
12+
{{ optionItem }}
1113
</option>
1214
</select>
1315
</template>
1416

1517
<script lang="ts">
1618
import Vue from 'vue';
19+
import PropertyValueRelation from '@/data-model/PropertyValueRelation';
1720
1821
export default Vue.extend( {
1922
name: 'ValueTypeDropDown',
2023
data() {
2124
return {
22-
selected: null,
23-
optionItems: [
24-
{ value: 'matching' },
25-
{ value: 'regardless of value' },
26-
{ value: 'without' },
27-
],
25+
selected: '',
26+
optionItems: PropertyValueRelation,
2827
};
2928
},
3029
props: {
@@ -33,6 +32,14 @@ export default Vue.extend( {
3332
default: null,
3433
},
3534
},
35+
watch: {
36+
selected(): void {
37+
this.$emit( 'input', this.selected );
38+
},
39+
value( selectedOption: PropertyValueRelation ): void {
40+
this.selected = selectedOption;
41+
},
42+
},
3643
} );
3744
</script>
3845
<style scoped lang="scss">

src/store/RootState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ConditionRow {
1414
valueData: {
1515
value: string;
1616
};
17-
propertyValueRelation: {
17+
propertyValueRelationData: {
1818
value: PropertyValueRelation;
1919
};
2020
}

src/store/actions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default ( searchEntityRepository: SearchEntityRepository ) => ( {
1818
updateProperty( context: ActionContext<RootState, RootState>, property: Property ): void {
1919
context.commit( 'setProperty', property );
2020
},
21+
updatePropertyValueRelation( context: ActionContext<RootState, RootState>, propertyValueRelation: string ): void {
22+
context.commit( 'setPropertyValueRelation', propertyValueRelation );
23+
},
2124
setErrors( context: ActionContext<RootState, RootState>, errors: Error[] ): void {
2225
context.commit( 'setErrors', errors );
2326
},

src/store/getters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
condition: {
1111
propertyId: rootState.conditionRow.propertyData.id,
1212
value: rootState.conditionRow.valueData.value,
13-
propertyValueRelation: rootState.conditionRow.propertyValueRelation.value,
13+
propertyValueRelation: rootState.conditionRow.propertyValueRelationData.value,
1414
},
1515
};
1616
},
@@ -24,7 +24,7 @@ export default {
2424
return rootState.conditionRow.valueData.value;
2525
},
2626
propertyValueRelation( rootState: RootState ): PropertyValueRelation {
27-
return rootState.conditionRow.propertyValueRelation.value;
27+
return rootState.conditionRow.propertyValueRelationData.value;
2828
},
2929
getErrors( rootState: RootState ): Error[] {
3030
return rootState.errors;

src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function createStore( services: QueryBuilderServices ): Store<RootState>
2222
valueData: {
2323
value: '',
2424
},
25-
propertyValueRelation: {
25+
propertyValueRelationData: {
2626
value: PropertyValueRelation.Matching,
2727
},
2828
},

src/store/mutations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import RootState from './RootState';
22
import Property from '@/data-model/Property';
3+
import PropertyValueRelation from '@/data-model/PropertyValueRelation';
34
import Error from '@/data-model/Error';
45

56
export default {
@@ -9,6 +10,9 @@ export default {
910
setProperty( state: RootState, property: Property ): void {
1011
state.conditionRow.propertyData = property;
1112
},
13+
setPropertyValueRelation( state: RootState, propertyValueRelation: PropertyValueRelation ): void {
14+
state.conditionRow.propertyValueRelationData.value = propertyValueRelation;
15+
},
1216
setErrors( state: RootState, errors: Error[] ): void {
1317
state.errors = errors;
1418
},
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import Vue from 'vue';
22
import ValueTypeDropDown from '@/components/ValueTypeDropDown.vue';
3+
import PropertyValueRelation from '@/data-model/PropertyValueRelation';
34
import { shallowMount } from '@vue/test-utils';
45

56
describe( 'ValueTypeDropDown.vue', () => {
67
it( 'emits an `input` event containing the selected option item upon selection', async () => {
7-
const optionItems = [
8-
{ value: 'matching' },
9-
{ value: 'regardless of value' },
10-
];
8+
const optionItems = PropertyValueRelation;
9+
const wrapper = shallowMount( ValueTypeDropDown );
1110

12-
const wrapper = shallowMount( ValueTypeDropDown, { propsData: {
13-
value: null,
14-
} } );
15-
16-
wrapper.setData( { optionItems } );
11+
wrapper.setData( {
12+
selected: optionItems.Matching,
13+
optionItems: optionItems,
14+
} );
1715

1816
await Vue.nextTick();
1917

20-
const selectedItem = 1;
21-
wrapper.findAll( '.querybuilder__dropdown-option' ).at( selectedItem ).element.click();
22-
23-
expect( wrapper.emitted( 'input' )![ 0 ] ).toEqual( [ optionItems[ selectedItem ].value ] );
18+
expect( wrapper.emitted( 'input' )![ 0 ][ 0 ] ).toEqual( optionItems.Matching );
2419
} );
2520
} );

tests/unit/store/getters.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe( 'getters', () => {
1010
conditionRow: {
1111
valueData: { value: 'foo' },
1212
propertyData: { id: 'P123', label: 'abc' },
13-
propertyValueRelation: { value: PropertyValueRelation.Matching },
13+
propertyValueRelationData: { value: PropertyValueRelation.Matching },
1414
},
1515
errors: [],
1616
};

tests/unit/store/mutations.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe( 'mutations', () => {
1010
conditionRow: {
1111
valueData: { value: 'foo' },
1212
propertyData: { id: 'P123', label: 'abc' },
13-
propertyValueRelation: { value: PropertyValueRelation.Matching },
13+
propertyValueRelationData: { value: PropertyValueRelation.Matching },
1414
},
1515
errors: [],
1616
};
@@ -26,7 +26,7 @@ describe( 'mutations', () => {
2626
conditionRow: {
2727
valueData: { value: 'foo' },
2828
propertyData: { id: 'P123', label: 'abc' },
29-
propertyValueRelation: { value: PropertyValueRelation.Matching },
29+
propertyValueRelationData: { value: PropertyValueRelation.Matching },
3030
},
3131
errors: [],
3232
};

0 commit comments

Comments
 (0)