Skip to content

Commit

Permalink
add test for unknown type / tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Nov 18, 2020
1 parent bee03aa commit b28c441
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export function SearchBar({
const rawParams = parseSearchParams(searchValue);
const tagIds =
taggingApi && rawParams.filters.tags
? rawParams.filters.tags
.map((tagName) => taggingApi.ui.getTagIdFromName(tagName))
.filter((tagId): tagId is string => tagId !== undefined)
? rawParams.filters.tags.map(
(tagName) => taggingApi.ui.getTagIdFromName(tagName) ?? '__unknown__'
)
: undefined;
const searchParams: GlobalSearchFindParams = {
term: rawParams.term,
Expand Down
15 changes: 8 additions & 7 deletions x-pack/test/functional/page_objects/navigational_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,27 @@ export function NavigationalSearchProvider({ getService, getPageObjects }: FtrPr
await options[index].click();
}

async waitForResultsLoaded() {
async waitForResultsLoaded(waitUntil: number = 3000) {
await testSubjects.exists('nav-search-option');
// results are emitted in multiple batches. Each individual batch causes a re-render of
// the component, causing the current elements to become stale. We can't perform DOM access
// without heavy flakiness in this situation.
// there is NO ui indication of any kind to detect when all the emissions are done,
// so we are forced to fallback to awaiting a given amount of time once the first options are displayed.
await delay(3000);
await delay(waitUntil);
}

async getDisplayedResults() {
const resultElements = await testSubjects.findAll('nav-search-option');
return Promise.all(resultElements.map((el) => this.convertResultElement(el)));
}

async isNoResultsPlaceholderDisplayed(checkAfter: number = 3000) {
// see comment in `waitForResultsLoaded`
await delay(checkAfter);
return testSubjects.exists('nav-search-no-results');
}

private async convertResultElement(resultEl: WebElementWrapper): Promise<SearchResult> {
const labelEl = await find.allDescendantDisplayedByCssSelector(
'.euiSelectableTemplateSitewide__listItemTitle',
Expand All @@ -85,10 +91,5 @@ export function NavigationalSearchProvider({ getService, getPageObjects }: FtrPr
}
}

// nav-search-popover
// nav-search-option
// euiSelectableTemplateSitewide__listItemTitle
// euiSelectableTemplateSitewide__optionMeta

return new NavigationalSearch();
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

expect(results.map((result) => result.label)).to.eql(['My awesome vis (tag-4)']);
});

it('returns no results when searching for an unknown tag', async () => {
await navigationalSearch.searchFor('tag:unknown');

expect(await navigationalSearch.isNoResultsPlaceholderDisplayed()).to.eql(true);
});

it('returns no results when searching for an unknown type', async () => {
await navigationalSearch.searchFor('type:unknown');

expect(await navigationalSearch.isNoResultsPlaceholderDisplayed()).to.eql(true);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
}, t);
};

describe('TOTO GlobalSearch - SavedObject provider', function () {
describe('GlobalSearch - SavedObject provider', function () {
before(async () => {
await esArchiver.load('global_search/basic');
});
Expand Down

0 comments on commit b28c441

Please sign in to comment.