Skip to content

Commit

Permalink
Add owner search test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Mar 25, 2024
1 parent 840534b commit b5c6b25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
30 changes: 16 additions & 14 deletions web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default function (mirageConfig) {
let facets = requestBody?.facets ?? [];

if (requestBody) {
console.log("requestBody", requestBody);
const { facetQuery, query } = requestBody;
let { facetFilters } = requestBody;

Expand Down Expand Up @@ -153,41 +152,44 @@ export default function (mirageConfig) {
* "index-name/facets/owners/query"
*/
const facetName = request.params["*"].split("/")[2];
let uniqueHits: string[] = [];
let facetHits: Array<{ value: string }> = [];

console.log(facetName, facetQuery);

switch (facetName) {
case FacetName.Owners:
let ownerMatches = docModels.filter((doc) => {
return doc.attrs.owners[0].includes(facetQuery);
return doc.attrs.owners[0]
.toLowerCase()
.includes(facetQuery.toLowerCase());
});

facetHits = ownerMatches.map((doc) => {
return { value: doc.attrs.owners[0] };
ownerMatches.forEach((doc) => {
const owner = doc.attrs.owners[0];
if (!uniqueHits.includes(owner)) {
uniqueHits.push(owner);
}
});
break;

case FacetName.Product:
let uniqueProducts: string[] = [];
let productMatches = docModels.filter((doc) => {
console.log("doc.attrs.product", doc.attrs.product);
return doc.attrs.product
.toLowerCase()
.includes(facetQuery.toLowerCase());
});

productMatches.forEach((doc) => {
if (!uniqueProducts.includes(doc.attrs.product)) {
uniqueProducts.push(doc.attrs.product);
if (!uniqueHits.includes(doc.attrs.product)) {
uniqueHits.push(doc.attrs.product);
}
});

facetHits = uniqueProducts.map((product) => {
return { value: product };
});
break;
}

facetHits = uniqueHits.map((product) => {
return { value: product };
});

return new Response(200, {}, { facetHits });
} else if (query !== undefined) {
/**
Expand Down
16 changes: 14 additions & 2 deletions web/tests/acceptance/authenticated/documents-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { click, visit } from "@ember/test-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test, todo } from "qunit";
import { authenticateSession } from "ember-simple-auth/test-support";
import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support";
import { getPageTitle } from "ember-page-title/test-support";
import { FacetLabel } from "hermes/helpers/get-facet-label";
import { TEST_USER_EMAIL } from "hermes/mirage/utils";
import { TEST_USER_2_EMAIL, TEST_USER_EMAIL } from "hermes/mirage/utils";

const TABLE_HEADER_CREATED_SELECTOR =
"[data-test-sortable-table-header][data-test-attribute=createdTime]";
Expand All @@ -16,6 +16,8 @@ const FILTERED_DOC_COUNT = "[data-test-filtered-doc-count]";
const ACTIVE_FILTER_LINK = "[data-test-active-filter-link]";
const CLEAR_ALL_LINK = "[data-test-clear-all-filters-link]";
const OWNER_LINK = "[data-test-owner-link]";
const OWNERS_INPUT = `[data-test-search-owners-input]`;
const OWNER_MATCH = "[data-test-x-dropdown-list-item-link-to]";

interface AuthenticatedDocumentsRouteTestContext extends MirageTestContext {}
module("Acceptance | authenticated/documents", function (hooks) {
Expand Down Expand Up @@ -64,6 +66,7 @@ module("Acceptance | authenticated/documents", function (hooks) {

this.server.createList("document", 2, {
docType: "PRD",
owners: [TEST_USER_2_EMAIL],
});

await visit("/documents");
Expand All @@ -87,6 +90,15 @@ module("Acceptance | authenticated/documents", function (hooks) {
await click(ACTIVE_FILTER_LINK);

assert.dom(DOC_LINK).exists({ count: 4 });

await fillIn(OWNERS_INPUT, TEST_USER_2_EMAIL);

assert.dom(OWNER_MATCH).containsText(TEST_USER_2_EMAIL);

await click(OWNER_MATCH);

assert.dom(DOC_LINK).exists({ count: 2 });
assert.dom(ACTIVE_FILTER_LINK).containsText(TEST_USER_2_EMAIL);
});

test("owners are clickable", async function (this: AuthenticatedDocumentsRouteTestContext, assert) {
Expand Down

0 comments on commit b5c6b25

Please sign in to comment.