diff options
author | Matt Watson <mattdangerw@gmail.com> | 2015-08-03 15:46:28 -0700 |
---|---|---|
committer | Matt Watson <mattdangerw@gmail.com> | 2015-08-06 14:01:54 -0700 |
commit | b867b717bb94804427cc4bba6b54c485cb92c352 (patch) | |
tree | fdcd6501aca7540ec4c7f23b8981ab83f47d0f77 | |
parent | 259f874fa34bf68c085eb7a404c2dec9d622dc14 (diff) |
search_box: add function to set text programmatically
This way we can set the search box text without triggering the
signals for settings autocomplete entries
[endlessm/eos-sdk#3442]
-rw-r--r-- | overrides/endless_private/search_box.js | 10 | ||||
-rw-r--r-- | test/Makefile.am.inc | 2 | ||||
-rw-r--r-- | test/endless/testSearchBox.js | 20 | ||||
-rw-r--r-- | test/utils.js | 6 |
4 files changed, 38 insertions, 0 deletions
diff --git a/overrides/endless_private/search_box.js b/overrides/endless_private/search_box.js index ea45531..f076962 100644 --- a/overrides/endless_private/search_box.js +++ b/overrides/endless_private/search_box.js @@ -141,6 +141,16 @@ const SearchBox = new Lang.Class({ return Gdk.EVENT_STOP; }, + /* Set the entry text without triggering the text-changed signal. + */ + set_text_programmatically: function (text) { + if (this.text === text) + return; + this._entry_changed_by_widget = true; + this.text = text; + this.set_position(-1); + }, + /* Set the menu items by providing an array of item objects: [ { diff --git a/test/Makefile.am.inc b/test/Makefile.am.inc index bfc0a11..211bd8f 100644 --- a/test/Makefile.am.inc +++ b/test/Makefile.am.inc @@ -52,10 +52,12 @@ javascript_tests = \ test/webhelper/testUpdateFontSize.js \ test/endless/testCustomContainer.js \ test/endless/testTopbarNavButton.js \ + test/endless/testSearchBox.js \ $(NULL) EXTRA_DIST += \ $(javascript_tests) \ test/tools/test.html \ + test/utils.js \ $(NULL) # Run tests when running 'make check' diff --git a/test/endless/testSearchBox.js b/test/endless/testSearchBox.js new file mode 100644 index 0000000..9d8686d --- /dev/null +++ b/test/endless/testSearchBox.js @@ -0,0 +1,20 @@ +const Endless = imports.gi.Endless; +const Gtk = imports.gi.Gtk; + +const Utils = imports.test.utils; + +Gtk.init(null); + +describe('SearchBox', function () { + let search_box; + + beforeEach(function () { + search_box = new Endless.SearchBox(); + }); + + it('emits no signal when you change the text programmatically', function () { + search_box.connect('text-changed', () => fail()); + search_box.set_text_programmatically('some text'); + Utils.update_gui(); + }); +}); diff --git a/test/utils.js b/test/utils.js new file mode 100644 index 0000000..2597fd8 --- /dev/null +++ b/test/utils.js @@ -0,0 +1,6 @@ +const Gtk = imports.gi.Gtk; + +function update_gui () { + while (Gtk.events_pending()) + Gtk.main_iteration(false); +} |