test(ui): autocomplete control
This commit is contained in:
parent
51dcf8fd47
commit
07b70c2bd9
2 changed files with 40 additions and 2 deletions
38
cypress/integration/control_autocomplete.js
Normal file
38
cypress/integration/control_autocomplete.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
context('Control Autocomplete', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.visit('/app/website');
|
||||
});
|
||||
|
||||
function get_dialog_with_autocomplete() {
|
||||
cy.visit('/app/website');
|
||||
return cy.dialog({
|
||||
title: 'Autocomplete',
|
||||
fields: [
|
||||
{
|
||||
'label': 'Select an option',
|
||||
'fieldname': 'autocomplete',
|
||||
'fieldtype': 'Autocomplete',
|
||||
'options': ['Option 1', 'Option 2', 'Option 3'],
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
it('should set the valid value', () => {
|
||||
get_dialog_with_autocomplete().as('dialog');
|
||||
|
||||
cy.get('.frappe-control[data-fieldname=autocomplete] input').focus().as('input');
|
||||
cy.wait(1000);
|
||||
cy.get('@input').type('2', { delay: 300 });
|
||||
cy.get('.frappe-control[data-fieldname=autocomplete]').findByRole('listbox').should('be.visible');
|
||||
cy.get('.frappe-control[data-fieldname=autocomplete] input').type('{enter}', { delay: 300 });
|
||||
cy.get('.frappe-control[data-fieldname=autocomplete] input').blur();
|
||||
cy.get('@dialog').then(dialog => {
|
||||
let value = dialog.get_value('autocomplete');
|
||||
expect(value).to.eq('Option 2');
|
||||
dialog.clear();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -11,7 +11,7 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
|
|||
set_options() {
|
||||
if (this.df.options) {
|
||||
let options = this.df.options || [];
|
||||
this._data = this.parse_options(options);
|
||||
this.set_data(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
|
|||
|
||||
this.$input.on('input', frappe.utils.debounce((e) => {
|
||||
const cached_options = this.$input.cache[this.doctype][this.df.fieldname][e.target.value];
|
||||
if (cached_options) {
|
||||
if (cached_options && cached_options.length) {
|
||||
this.set_data(cached_options);
|
||||
} else if (this.get_query || this.df.get_query) {
|
||||
this.execute_query_if_exists(e.target.value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue