Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fature/CE-205 #187

Merged
merged 4 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading