within the iframe"
);
await assertSuggestion(
commands,
{ query: "", firstPart: "ifram", state: "id" },
[
{
suggestion: "#iframe",
count: 1,
type: "id",
},
]
);
info(
"Suggestions for 'fo' with tag search, will match the class of the top
element"
);
await assertSuggestion(
commands,
{ query: "", firstPart: "fo", state: "tag" },
[
{
suggestion: ".foo",
count: 1,
type: "class",
},
]
);
info(
"Suggestions for classes, based on div elements, will match the two classes of top
element"
);
await assertSuggestion(
commands,
{ query: "div", firstPart: "", state: "class" },
[
{
suggestion: ".bar",
count: 1,
type: "class",
},
{
suggestion: ".foo",
count: 1,
type: "class",
},
]
);
info("Suggestion for non-existent tag names will return no suggestion");
await assertSuggestion(
commands,
{ query: "", firstPart: "marquee", state: "tag" },
[]
);
await commands.destroy();
});
async function assertSuggestion(
commands,
{ query, firstPart, state },
expectedSuggestions
) {
const suggestions = await commands.inspectorCommand.getSuggestionsForQuery(
query,
firstPart,
state
);
is(
suggestions.length,
expectedSuggestions.length,
"Got the expected number of suggestions"
);
for (let i = 0; i < expectedSuggestions.length; i++) {
info(` ## Asserting suggestion #${i}:`);
const expectedSuggestion = expectedSuggestions[i];
const [suggestion, count, type] = suggestions[i];
is(
suggestion,
expectedSuggestion.suggestion,
"The suggested string is valid"
);
is(count, expectedSuggestion.count, "The number of matches is valid");
is(type, expectedSuggestion.type, "The type of match is valid");
}
}