Skip to content

Commit

Permalink
COMPENF-430 view summary details of a complaint while in the map view (
Browse files Browse the repository at this point in the history
…#137)

Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
barrfalk and afwilcox authored Sep 29, 2023
1 parent dfd5b14 commit 28c1f8d
Show file tree
Hide file tree
Showing 19 changed files with 707 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Complaint Change Status spec - Details View", () => {
cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get("#comp-details-status-text-id").contains("CLOSED").should("exist");
cy.get("#comp-details-status-text-id").contains("Closed").should("exist");

cy.get("#details-screen-update-status-button").click({ force: true });

Expand All @@ -44,7 +44,7 @@ describe("Complaint Change Status spec - Details View", () => {
cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get("#comp-details-status-text-id").contains("OPEN").should("exist");
cy.get("#comp-details-status-text-id").contains("Open").should("exist");
});
});
});
55 changes: 38 additions & 17 deletions frontend/cypress/e2e/complaints-on-map-view.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,60 @@
Test to verify that the status and assignment popover displays when clicking the vertical ellipsis on both the
HWLC and Enforcement list screens
*/
describe('Complaints on map tests', () => {
describe("Complaints on map tests", () => {
const complaintTypes = ["#hwcr-tab","#ers-tab"];

const complaintTypes = ['#ers-tab','#hwcr-tab'];

beforeEach(function() {
beforeEach(function () {
cy.viewport("macbook-16");
cy.kcLogout().kcLogin();
});

// perform the same test on each of the tabs (HWCR and ERS)
Cypress._.times(complaintTypes.length, ((index) => {

it('Switch to map view', () => {
Cypress._.times(complaintTypes.length, (index) => {
it("Switch to map view", () => {
cy.visit("/");

cy.wait(3000);
cy.get(complaintTypes[index]).click({ force: true });


cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get("#comp-status-filter").click({ force: true }); //clear status filter so this complaint is in the list view

cy.get('#list_toggle_id').should('exist');
cy.get('#map_toggle_id').should('exist'); //verifies that the list/map toggle button appears. Click the map view
cy.get('#map_toggle_id').click({force: true});
cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get("#list_toggle_id").should("exist");
cy.get("#map_toggle_id").should("exist"); //verifies that the list/map toggle button appears. Click the map view
cy.get("#map_toggle_id").click({ force: true });

// wait for the map to load
cy.get('.comp-loader-overlay').should('exist');
cy.get('.comp-loader-overlay').should('not.exist');
cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get("div.leaflet-container").should("exist");

cy.get('div.leaflet-container').should('exist');
cy.get(".leaflet-popup").should("not.exist");
cy.wait(1000);

cy.get(".leaflet-marker-icon").each(($marker, index) => {
// Click the first marker (index 0)
if (index === 0) {
cy.wrap($marker).click({ force: true });
}
});

// wait for the popup to load
cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");

cy.get(".leaflet-popup").should("exist");

// click the "view details" button to navigate to the complaint
cy.get("#view-complaint-details-button-id").click({ force: true });

cy.get(".comp-loader-overlay").should("exist");
cy.get(".comp-loader-overlay").should("not.exist");
});
}));
})
});
});
40 changes: 40 additions & 0 deletions frontend/src/app/common/methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import COMPLAINT_TYPES from "../types/app/complaint-types";
type Coordinate = number[] | string[] | undefined;

export const getAvatarInitials = (input: string): string => {

const tokens = input.split(" ");

if (tokens && tokens.length >= 1) {
Expand All @@ -18,6 +19,34 @@ export const getAvatarInitials = (input: string): string => {
}
};

export const getFirstInitialAndLastName = (fullName: string): string => {

const NOT_ASSIGNED = "Not Assigned";

if (NOT_ASSIGNED === fullName) {
return NOT_ASSIGNED;
}


// Split the full name into an array of words
const words = fullName.trim().split(' ');

if (words.length === 0) {
// If there are no words, return an empty string
return '';
} else if (words.length === 1) {
// If there is only one word, return the entire word as the last name
return words[0];
} else {
// Extract the first initial and last name
const firstInitial = words[0].charAt(0).toUpperCase();
const lastName = words[words.length - 1];

// Concatenate the first initial and last name with a space
return `${firstInitial}. ${lastName}`;
}
}

export const formatDate = (input: string | undefined): string => {
if (!input) {
return "";
Expand Down Expand Up @@ -112,3 +141,14 @@ export const renderCoordinates = (

return result === 0 ? <>{"Not Provided"}</> : <>{result}</>;
};

export const applyStatusClass = (state: string): string => {
switch (state.toLowerCase()) {
case "open":
return "comp-status-badge-open";
case "closed":
return "comp-status-badge-closed";
default:
return "";
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { ComplaintFilterContext } from "../../../providers/complaint-filter-prov
import { ComplaintFilters } from "../../../types/complaints/complaint-filters/complaint-filters";
import { ComplaintRequestPayload } from "../../../types/complaints/complaint-filters/complaint-reauest-payload";
import LeafletMapWithMultiplePoints from "../../mapping/leaflet-map-with-multiple-points";
import {
getComplaintsOnMap,
setComplaintsOnMap,
selectComplaintLocations,
} from "../../../store/reducers/complaints";
import { getComplaintsOnMap, selectComplaintLocations, setComplaintsOnMap } from "../../../store/reducers/complaint-locations";

type Props = {
type: string;
Expand Down Expand Up @@ -85,5 +81,5 @@ export const ComplaintMap: FC<Props> = ({ type }) => {
};
}, []);

return <LeafletMapWithMultiplePoints markers={coordinatesArray} />;
return <LeafletMapWithMultiplePoints complaint_type={type} markers={coordinatesArray} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import COMPLAINT_TYPES, {
complaintTypeToName,
} from "../../../types/app/complaint-types";
import { useAppDispatch, useAppSelector } from "../../../hooks/hooks";
import { selectTotalComplaintsByType, selectTotalComplaintsOnMapByType } from "../../../store/reducers/complaints";
import { selectTotalComplaintsByType } from "../../../store/reducers/complaints";
import { ComplaintFilter } from "./complaint-filter";
import { ComplaintList } from "./complaint-list";

Expand All @@ -23,6 +23,7 @@ import { selectDefaultZone, getOfficerDefaultZone, profileZoneDescription, profi
import { DropdownOption } from '../../../types/code-tables/option';
import { ComplaintMap } from "./complaint-map";
import { COMPLAINT_VIEW_TYPES } from "../../../constants/complaint-view-type";
import { selectTotalComplaintsOnMapByType } from "../../../store/reducers/complaint-locations";

type Props = {
defaultComplaintType: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../../../../common/methods";
import { Coordinates } from "../../../../types/app/coordinate-type";
import { ComplaintDetailsAttractant } from "../../../../types/complaints/details/complaint-attactant";
import { selectComplaintDeails } from "../../../../store/reducers/complaints";
import { selectComplaintDetails } from "../../../../store/reducers/complaints";
import COMPLAINT_TYPES from "../../../../types/app/complaint-types";
import { ComplaintDetails } from "../../../../types/complaints/details/complaint-details";

Expand All @@ -32,7 +32,7 @@ export const CallDetails: FC<ComplaintHeaderProps> = ({
attractants,
violationInProgress,
violationObserved,
} = useAppSelector(selectComplaintDeails(complaintType)) as ComplaintDetails;
} = useAppSelector(selectComplaintDetails(complaintType)) as ComplaintDetails;

return (
<div className="comp-complaint-details-block">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "../../../../common/methods";
import { Coordinates } from "../../../../types/app/coordinate-type";
import {
selectComplaintDeails,
selectComplaintDetails,
selectComplaintHeader,
selectComplaintCallerInformation,
selectComplaintSuspectWitnessDetails,
Expand Down Expand Up @@ -135,7 +135,7 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
attractants,
violationInProgress,
violationObserved,
} = useAppSelector(selectComplaintDeails(complaintType)) as ComplaintDetails;
} = useAppSelector(selectComplaintDetails(complaintType)) as ComplaintDetails;

const {
loggedDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import COMPLAINT_TYPES, {
import { useAppDispatch, useAppSelector } from "../../../../hooks/hooks";
import { selectComplaintHeader } from "../../../../store/reducers/complaints";
import {
applyStatusClass,
formatDate,
formatTime,
getAvatarInitials,
Expand Down Expand Up @@ -46,16 +47,7 @@ export const ComplaintHeader: FC<ComplaintHeaderProps> = ({

const dispatch = useAppDispatch();
const assignText = officerAssigned === 'Not Assigned' ? 'Assign' : 'Reassign';
const applyStatusClass = (state: string): string => {
switch (state.toLowerCase()) {
case "open":
return "comp-status-badge-open";
case "closed":
return "comp-status-badge-closed";
default:
return "";
}
};


const openStatusChangeModal = () => {
document.body.click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { FC } from "react";
import { useAppSelector } from "../../../../hooks/hooks";
import { FC, useEffect } from "react";
import { useAppDispatch, useAppSelector } from "../../../../hooks/hooks";
import {
selectComplaintDeails,
getComplaintLocation,
selectComplaintDetails,
selectComplaintLocation,
} from "../../../../store/reducers/complaints";
import LeafletMapWithPoint from "../../../mapping/leaflet-map-with-point";
Expand All @@ -20,18 +21,25 @@ type Props = {
*
*/
export const ComplaintLocation: FC<Props> = ({ complaintType, draggable, onMarkerMove }) => {

const { coordinates } = useAppSelector(
selectComplaintDeails(complaintType)
const dispatch = useAppDispatch();
const { coordinates, area, location } = useAppSelector(
selectComplaintDetails(complaintType)
) as ComplaintDetails;

useEffect(() => {
if (area) {
dispatch(getComplaintLocation(area, location));
}

}, [area, dispatch, location]);

const complaintLocation = useAppSelector(selectComplaintLocation);

// the lat and long of the marker we need to display on the map
// Initialized to 0. This will either be populated using the optionally supplied coordinates
// or they'll be derived using the complaint's location and/or community.
let lat = 0;
let lng = 0;

if (coordinates && isWithinBC(coordinates)) {
lat = +coordinates[Coordinates.Latitude];
lng = +coordinates[Coordinates.Longitude];
Expand Down
Loading

0 comments on commit 28c1f8d

Please sign in to comment.