mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(location): render the search field's open and searching state from the tray
LocationControls presents whether the search field is open and whether a lookup runs, and the dock renders its expanded and searching classes and calls toggleSearch(). The lookup, the navigation's settle, Escape and the location tray's collapse reach the field through the controls (setSearching, settleSearch, closeSearch) instead of writing its classes. LocationControls no longer takes searchToggle, LocationSearch takes setSearching and NavigationController takes settleSearch in place of searchInput.
This commit is contained in:
1 parent
b4ee2321cf
commit
0949f6a776
18 files changed
+238
-83
No files matched your search
@@ -57,10 +57,9 @@ function node() {
|
||||
},
|
||||
};
|
||||
}
|
||||
function fixture() {
|
||||
function fixture(options = {}) {
|
||||
const elements = {
|
||||
search: node(),
|
||||
searchToggle: node(),
|
||||
};
|
||||
const doc = node();
|
||||
doc.createElement = node;
|
||||
@@ -90,6 +89,7 @@ function fixture() {
|
||||
return id;
|
||||
},
|
||||
cancelFrame: (id) => cancelled.push(id),
|
||||
...options,
|
||||
});
|
||||
const view = () => views.at(-1);
|
||||
return { elements, doc, controls, calls, frames, cancelled, views, view };
|
||||
@@ -106,6 +106,8 @@ test('the tray presents its cities, empty status and no landmarks at first', ()
|
||||
poisExpanded: false,
|
||||
status: { city: '📍 Location: --', poi: 'Landmark: --' },
|
||||
searchError: null,
|
||||
searchExpanded: false,
|
||||
searching: false,
|
||||
orbit: null,
|
||||
});
|
||||
f.controls.highlightCity('b');
|
||||
@@ -199,3 +201,66 @@ test('typing clears a failed search error and closing the emptied field drops it
|
||||
f.elements.search.fire('blur');
|
||||
assert.deepEqual(f.calls, [['edit'], ['edit']]);
|
||||
});
|
||||
test('the search field opens and closes through the toggle and marks a lookup', () => {
|
||||
const f = fixture();
|
||||
const field = f.elements.search;
|
||||
f.controls.toggleSearch();
|
||||
assert.equal(f.view().searchExpanded, true);
|
||||
assert.equal(field.focused, true);
|
||||
f.controls.setSearching(true);
|
||||
assert.equal(f.view().searching, true);
|
||||
f.controls.toggleSearch();
|
||||
assert.equal(f.view().searchExpanded, false);
|
||||
f.controls.toggleSearch();
|
||||
field.value = 'Paris';
|
||||
f.controls.closeSearch();
|
||||
assert.equal(f.view().searchExpanded, false);
|
||||
assert.equal(field.value, '');
|
||||
});
|
||||
test('a lookup that found nothing keeps its query, the open field and focus', () => {
|
||||
const f = fixture();
|
||||
const field = f.elements.search;
|
||||
let selected = false;
|
||||
field.select = () => {
|
||||
selected = true;
|
||||
};
|
||||
f.controls.toggleSearch();
|
||||
f.controls.setSearching(true);
|
||||
field.value = 'Pariss';
|
||||
field.focused = false;
|
||||
f.controls.settleSearch({ keepQuery: true });
|
||||
assert.equal(f.view().searching, false);
|
||||
assert.equal(f.view().searchExpanded, true);
|
||||
assert.equal(field.value, 'Pariss');
|
||||
assert.equal(field.focused, true);
|
||||
assert.equal(selected, true);
|
||||
});
|
||||
test('a lookup that arrived clears and closes the field', () => {
|
||||
const f = fixture();
|
||||
const field = f.elements.search;
|
||||
let blurred = false;
|
||||
field.blur = () => {
|
||||
blurred = true;
|
||||
};
|
||||
f.controls.toggleSearch();
|
||||
f.controls.setSearching(true);
|
||||
field.value = 'Paris';
|
||||
f.controls.settleSearch();
|
||||
assert.equal(f.view().searching, false);
|
||||
assert.equal(f.view().searchExpanded, false);
|
||||
assert.equal(field.value, '');
|
||||
assert.equal(blurred, true);
|
||||
// Destroyed controls change nothing.
|
||||
f.controls.destroy();
|
||||
const after = f.views.length;
|
||||
f.controls.toggleSearch();
|
||||
f.controls.setSearching(true);
|
||||
f.controls.settleSearch();
|
||||
f.controls.closeSearch();
|
||||
assert.equal(f.views.length, after);
|
||||
});
|
||||
test('controls that replace others can start with the field open', () => {
|
||||
const f = fixture({ searchExpanded: true });
|
||||
assert.equal(f.controls.presentation().searchExpanded, true);
|
||||
assert.equal(f.elements.search.focused, undefined);
|
||||
});
|
||||
Reference in new issue
Block a user