Skip to content

Commit

Permalink
fature/CE-205 (#187)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
marqueone-ps and afwilcox authored Nov 4, 2023
1 parent 34991d8 commit 4b4b703
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,16 @@ export class AllegationComplaintService {
searchMap = async (
model: SearchPayload
): Promise<Array<AllegationComplaint>> => {
const { query } = model;

//-- build generic wildlife query
let builder = this._getAllegationQuery();

//-- apply search
if (query) {
builder = this._applySearch(builder, query);
}

//-- apply filters
builder = this._applyAllegationQueryFilters(
builder,
Expand Down
7 changes: 7 additions & 0 deletions backend/src/v1/hwcr_complaint/hwcr_complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,16 @@ export class HwcrComplaintService {
};

searchMap = async (model: SearchPayload): Promise<HwcrComplaint[]> => {
const { query } = model;

//-- build generic wildlife query
let builder = this._getWildlifeQuery();

//-- apply search
if (query) {
builder = this._applySearch(builder, query);
}

//-- apply filters
builder = this._applyWildlifeQueryFilters(builder, model as SearchPayload);

Expand Down
195 changes: 128 additions & 67 deletions frontend/cypress/e2e/complaint-search.v2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,98 +49,159 @@ describe("Complaint Search Functionality", () => {
});

it("Can search Allegations for 'RAPP'", () => {
cy.visit("/");
cy.waitForSpinner();
cy.visit("/");
cy.waitForSpinner();

//-- load the Enforcement conflicts
cy.get(complaintTypes[1]).click({ force: true });
//-- load the Enforcement conflicts
cy.get(complaintTypes[1]).click({ force: true });

//-- verify correct tab
cy.get("#ers-tab").should("contain.text", "Enforcement");
//-- verify correct tab
cy.get("#ers-tab").should("contain.text", "Enforcement");

//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-status-filter").should("not.exist");
//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-status-filter").should("not.exist");

//-- there should be 33 complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 33);
//-- there should be 33 complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 33);

//-- search for RAPP and verify there's siz complaints
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("RAPP{enter}"); //-- {enter} will perform an enter keypress
//-- search for RAPP and verify there's siz complaints
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("RAPP{enter}"); //-- {enter} will perform an enter keypress

//-- verify one complaint, and verify complaint-id
cy.get("#complaint-list tbody").find("tr").should("have.length", 6);
});
//-- verify one complaint, and verify complaint-id
cy.get("#complaint-list tbody").find("tr").should("have.length", 6);
});

it("Search should clear when switching tabs", () => {
cy.visit("/");
cy.waitForSpinner();
it("Search should clear when switching tabs", () => {
cy.visit("/");
cy.waitForSpinner();

//-- load the Enforcement conflicts
cy.get(complaintTypes[1]).click({ force: true });
//-- load the Enforcement conflicts
cy.get(complaintTypes[1]).click({ force: true });

//-- verify correct tab
cy.get("#ers-tab").should("contain.text", "Enforcement");
//-- verify correct tab
cy.get("#ers-tab").should("contain.text", "Enforcement");

//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-status-filter").should("not.exist");
//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-status-filter").should("not.exist");

//-- there should be 33 complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 33);
//-- there should be 33 complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 33);

//-- search for RAPP and verify there's siz complaints
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("RAPP{enter}"); //-- {enter} will perform an enter keypress
//-- search for RAPP and verify there's siz complaints
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("RAPP{enter}"); //-- {enter} will perform an enter keypress

//-- verify one complaint, and verify complaint-id
cy.get("#complaint-list tbody").find("tr").should("have.length", 6);
//-- verify one complaint, and verify complaint-id
cy.get("#complaint-list tbody").find("tr").should("have.length", 6);

//-- switch tabs
cy.get(complaintTypes[0]).click({ force: true });
//-- switch tabs
cy.get(complaintTypes[0]).click({ force: true });

//-- verify empty search
cy.get("#complaint-search").should('have.value', '');
});
//-- verify empty search
cy.get("#complaint-search").should("have.value", "");
});

it("Can't search Wildlife complaints for 'Zebra'", () => {
cy.visit("/");
cy.waitForSpinner();
it("Can't search Wildlife complaints for 'Zebra'", () => {
cy.visit("/");
cy.waitForSpinner();

//-- load the human wildlife conflicts
cy.get(complaintTypes[0]).click({ force: true });
//-- load the human wildlife conflicts
cy.get(complaintTypes[0]).click({ force: true });

//-- verify correct tab
cy.get("#hwcr-tab").should("contain.text", "Human Wildlife Conflicts");
//-- verify correct tab
cy.get("#hwcr-tab").should("contain.text", "Human Wildlife Conflicts");

//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-zone-filter").click({ force: true });
//-- remove filters
cy.get("#comp-status-filter").click({ force: true });
cy.get("#comp-zone-filter").click({ force: true });

cy.get("#comp-status-filter").should("not.exist");
cy.get("#comp-zone-filter").should("not.exist");
cy.get("#comp-status-filter").should("not.exist");
cy.get("#comp-zone-filter").should("not.exist");

//-- open the filter tab
cy.get("#complaint-filter-image-id").click({ force: true });
//-- open the filter tab
cy.get("#complaint-filter-image-id").click({ force: true });

//-- select 70 mile house community
cy.selectItemById("community-select-id", "70 Mile House");

cy.get("#comp-community-filter").should("exist");
//-- select 70 mile house community
cy.selectItemById("community-select-id", "70 Mile House");

//-- close the filter
cy.get("#complaint-filter-image-id").click({ force: true });
cy.get("#comp-community-filter").should("exist");

//-- there should be 3 complaints
// cy.get("#complaint-list tbody").find("tr").should("have.length", 3);
//-- close the filter
cy.get("#complaint-filter-image-id").click({ force: true });

//-- search for sibling and verify there's one complaint
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("Zebra{enter}"); //-- {enter} will perform an enter keypress
//-- search for sibling and verify there's one complaint
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("Zebra{enter}"); //-- {enter} will perform an enter keypress

//-- verify no complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 0);
});
//-- verify no complaints
cy.get("#complaint-list tbody").find("tr").should("have.length", 0);
});

it("Can search wildlife map complaints by complaint-id: 23-031562", () => {
cy.visit("/");
cy.waitForSpinner();

//-- load the human wildlife conflicts
cy.get(complaintTypes[0]).click({ force: true });

//-- verify correct tab
cy.get("#hwcr-tab").should("contain.text", "Human Wildlife Conflicts");

//-- search for sibling and verify there's one complaint
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("23-031562{enter}"); //-- {enter} will perform an enter keypress

//-- verify only one complaint
cy.get("#complaint-list tbody").find("tr").should("have.length", 1);

cy.get("#map_toggle_id").click({ force: true });
cy.verifyMapMarkerExists(true);

cy.get("#multi-point-map")
.find(".leaflet-marker-icon")
.should(({ length }) => {
expect(length).to.eq(1);
});
});

it("Can search multiple allegation map complaints: ", () => {
cy.visit("/");
cy.waitForSpinner();

//-- load the human wildlife conflicts
cy.get(complaintTypes[1]).click({ force: true });

//-- verify correct tab
cy.get("#ers-tab").should("contain.text", "Enforcement"); //comp-zone-filter

//-- remove the zone filter
cy.get("#comp-zone-filter").click({ force: true });
cy.get("#comp-zone-filter").should("not.exist");

//-- open the filter tab
cy.get("#complaint-filter-image-id").click({ force: true });

//-- select east kootenay zone
cy.selectItemById("zone-select-id", "East Kootenay");
cy.get("#comp-zone-filter").should("exist");

cy.get("#complaint-filter-image-id").click({ force: true });

//-- search for fire and verify there's multiple complaints
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("fire{enter}"); //-- {enter} will perform an enter keypress

cy.get("#map_toggle_id").click({ force: true });
cy.verifyMapMarkerExists(true);

cy.get("#multi-point-map")
.find("div.leaflet-marker-icon")
.should(({ length }) => {
console.log(length);
expect(length).to.eq(5);
});
});
});
62 changes: 44 additions & 18 deletions frontend/src/app/components/common/search-input.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { ChangeEvent, FC, KeyboardEvent, useContext, useState, useEffect } from "react";
import {
ChangeEvent,
FC,
KeyboardEvent,
useContext,
useState,
useEffect,
} from "react";
import { InputGroup } from "react-bootstrap";
import { ComplaintFilterContext } from "../../providers/complaint-filter-provider";
import { getComplaints } from "../../store/reducers/complaints";
import { generateComplaintRequestPayload } from "../containers/complaints/complaint-list";
import { useAppDispatch } from "../../hooks/hooks";
import { SORT_TYPES } from "../../constants/sort-direction";
import { getComplaintsOnMap } from "../../store/reducers/complaint-locations";
import { generateMapComplaintRequestPayload } from "../containers/complaints/complaint-map";

type Props = {
complaintType: string;
viewType: "map" | "list";
searchQuery: string | undefined;
applySearchQuery: Function;
};

const SearchInput: FC<Props> = ({
complaintType,
viewType,
searchQuery,
applySearchQuery,
}) => {
Expand All @@ -22,28 +33,43 @@ const SearchInput: FC<Props> = ({

const [input, setInput] = useState<string>("");

useEffect(() => {
if(!searchQuery){
setInput("")
}
}, [searchQuery])
useEffect(() => {
if (!searchQuery) {
setInput("");
}
}, [searchQuery]);

const handleSearch = () => {
if (input.length >= 3) {
applySearchQuery(input);

let payload = generateComplaintRequestPayload(
complaintType,
filters,
1,
50,
"incident_reported_utc_timestmp",
SORT_TYPES.DESC
);
if (viewType === "list") {
let payload = generateComplaintRequestPayload(
complaintType,
filters,
1,
50,
"incident_reported_utc_timestmp",
SORT_TYPES.DESC
);

payload = { ...payload, query: input };

dispatch(getComplaints(complaintType, payload));
} else {
let payload = generateMapComplaintRequestPayload(
complaintType,
filters,
"",
""
);

payload = { ...payload, query: input };
if (searchQuery) {
payload = { ...payload, query: searchQuery };
}

dispatch(getComplaints(complaintType, payload));
dispatch(getComplaintsOnMap(complaintType, payload));
}
}
};

Expand All @@ -70,8 +96,8 @@ const SearchInput: FC<Props> = ({

if (!value) {
handleClear();
}
}

setInput(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const ComplaintFilterBar: FC<Props> = ({ viewType, toggleViewType, compla
)}

<div className="comp-filter-search">
<SearchInput complaintType={complaintType} searchQuery={searchQuery} applySearchQuery={applySearchQuery}/>
<SearchInput viewType={viewType} complaintType={complaintType} searchQuery={searchQuery} applySearchQuery={applySearchQuery} />
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 4b4b703

Please sign in to comment.