Skip to content

Commit

Permalink
Merge de53368 into 63b6e06
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-dantas committed Oct 5, 2018
2 parents 63b6e06 + de53368 commit dd19ac0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
28 changes: 3 additions & 25 deletions src/api/__mocks__/POST/repository/douglas/repo1/analyze.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,9 @@
"update_id": 1,
"language": "en",
"msg": "My name is Douglas",
"answer": {
"intent": {
"name": "greet",
"confidence": 0.7424270364852223
},
"entities": [
{
"start": 11,
"end": 18,
"value": "Douglas",
"entity": "name",
"extractor": "ner_crf"
}
],
"intent_ranking": [
{
"name": "greet",
"confidence": 0.7424270364852223
},
{
"name": "affirm",
"confidence": 0.14410867735373414
}
],
"text": "My name is Douglas"
"intent": {
"confidence": 0.6926029544379818,
"name": "greet"
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/components/example/NewExampleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export default {
entities: [],
errors: {},
submitting: false,
debounceTime: 1000,
setTimeoutId: null,
};
},
computed: {
Expand Down Expand Up @@ -173,13 +175,40 @@ export default {
};
},
},
watch: {
text(value) {
this.clearTimeout();
this.setTimeoutId = setTimeout(() => {
if (value) {
this.analyze(value);
} else {
this.intent = '';
}
},
this.debounceTime);
},
},
methods: {
...mapActions([
'newExample',
'analyzeText',
]),
setTextSelected(value) {
this.textSelected = value;
},
async analyze(value) {
try {
const response = await this.analyzeText({
ownerNickname: this.repository.owner__nickname,
slug: this.repository.slug,
language: this.repository.language,
text: value,
});
this.intent = response.data.intent.name;
} catch (error) {
this.intent = '';
}
},
onEntityAdded() {
if (this.$refs.textInput.clearSelected) {
/* istanbul ignore next */
Expand Down Expand Up @@ -228,6 +257,12 @@ export default {
}
return false;
},
clearTimeout() {
if (this.setTimeoutId) {
clearTimeout(this.setTimeoutId);
this.setTimeoutId = null;
}
},
},
};
</script>
Expand Down
23 changes: 23 additions & 0 deletions test/unit/specs/components/example/NewExampleForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('NewExampleForm.vue', () => {
propsData: {
repository: {
uuid: '8511fd26-a3bc-4f74-9af1-176abca5401d',
owner__nickname: 'douglas',
slug: 'repo1',
language: 'en',
},
},
store,
Expand Down Expand Up @@ -171,4 +174,24 @@ describe('NewExampleForm.vue', () => {
expect(wrapper.vm.textSelected).toMatchObject(eventValue);
});
});

describe('text intent field autofill', () => {
beforeEach(async () => {
await wrapper.vm.analyze('My name is Douglas');
});

test('intent field was autocompleted', () => {
expect(wrapper.vm.intent).toBe('greet');
});
});

describe('intent autofill failed', () => {
beforeEach(async () => {
await wrapper.vm.analyze('i like pizza');
});

test('intent field dont receive value', () => {
expect(wrapper.vm.intent).toBe('');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`NewExampleForm.vue renders correctly 1`] = `
<div class="column is-three-fifths">
<bhfield-stub label="" errors="">
<exampletextwithhighlightedentitiesinput-stub entities="" availableentities="" formatters="textFormatters" size="medium" placeholder="Add a sentence">
<languageappendselectinput-stub class="language-append"></languageappendselectinput-stub>
<languageappendselectinput-stub value="en" class="language-append"></languageappendselectinput-stub>
</exampletextwithhighlightedentitiesinput-stub>
</bhfield-stub>
</div>
Expand Down

0 comments on commit dd19ac0

Please sign in to comment.