Skip to content

Commit

Permalink
Merge pull request #172 from NIAEFEUP/feature/improve-search-function…
Browse files Browse the repository at this point in the history
…ality

Improve Search Functionality
  • Loading branch information
TiagooGomess authored May 24, 2022
2 parents 0da434a + b004555 commit 0458ebc
Show file tree
Hide file tree
Showing 20 changed files with 572 additions and 282 deletions.
9 changes: 8 additions & 1 deletion src/actions/searchOffersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const OfferSearchTypes = Object.freeze({
SET_JOB_FIELDS: "SET_JOB_FIELDS",
SET_JOB_TECHS: "SET_JOB_TECHS",
SET_OFFERS_SEARCH_RESULT: "SET_OFFERS_SEARCH_RESULT",
SET_SEARCH_QUERY_TOKEN: "SET_SEARCH_QUERY_TOKEN",
SET_OFFERS_LOADING: "SET_OFFERS_LOADING",
SET_SEARCH_OFFERS_ERROR: "SET_SEARCH_OFFERS_ERROR",
SET_JOB_DURATION_TOGGLE: "SET_JOB_DURATION_TOGGLE",
Expand All @@ -21,9 +22,15 @@ export const setLoadingOffers = (loading) => ({
loading,
});

export const setSearchOffers = (offers) => ({
export const setSearchOffers = (offers, accumulate) => ({
type: OfferSearchTypes.SET_OFFERS_SEARCH_RESULT,
offers,
accumulate,
});

export const setSearchQueryToken = (queryToken) => ({
type: OfferSearchTypes.SET_SEARCH_QUERY_TOKEN,
queryToken,
});

export const setOffersFetchError = (error) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import React from "react";
import AdvancedSearchDesktop from "./AdvancedSearchDesktop";
import JobOptions from "../../../utils/offers/JobOptions";
import { render, screen } from "../../../../test-utils";
import { renderWithStoreAndTheme, screen } from "../../../../test-utils";
import { AdvancedSearchControllerContext, AdvancedSearchController } from "../SearchArea";
import { fireEvent } from "@testing-library/dom";
import useComponentController from "../../../../hooks/useComponentController";
import FieldOptions from "../../../utils/offers/FieldOptions";
import TechOptions from "../../../utils/offers/TechOptions";
import { INITIAL_JOB_DURATION, INITIAL_JOB_TYPE } from "../../../../reducers/searchOffersReducer";
import { createTheme } from "@material-ui/core/styles";

const AdvancedSearchWrapper = ({
children, enableAdvancedSearchDefault, showJobDurationSlider, setShowJobDurationSlider, jobMinDuration = INITIAL_JOB_DURATION,
Expand Down Expand Up @@ -36,13 +37,18 @@ const AdvancedSearchWrapper = ({
};

describe("AdvancedSearchDesktop", () => {

const theme = createTheme();
const initialState = {};

describe("render", () => {
it("should render a job selector with all job types", () => {

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper enableAdvancedSearchDefault>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

fireEvent.mouseDown(screen.getByLabelText("Job Type"));
Expand All @@ -60,7 +66,7 @@ describe("AdvancedSearchDesktop", () => {

it("should toggle job duration slider (on)", () => {
const setShowJobDurationSliderMock = jest.fn();
render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
jobMinDuration={1}
Expand All @@ -69,7 +75,8 @@ describe("AdvancedSearchDesktop", () => {
setShowJobDurationSlider={setShowJobDurationSliderMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

expect(screen.getByText("Job Duration: 1 - 2 months")).not.toBeVisible();
Expand All @@ -81,7 +88,7 @@ describe("AdvancedSearchDesktop", () => {

it("should toggle job duration slider (off)", () => {
const setShowJobDurationSliderMock = jest.fn();
render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
jobMinDuration={1}
Expand All @@ -90,7 +97,8 @@ describe("AdvancedSearchDesktop", () => {
setShowJobDurationSlider={setShowJobDurationSliderMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);


Expand All @@ -101,10 +109,11 @@ describe("AdvancedSearchDesktop", () => {

it("should render a fields selector with all field types", () => {

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper enableAdvancedSearchDefault>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

fireEvent.mouseDown(screen.getByLabelText("Fields", { selector: "input" }));
Expand All @@ -126,10 +135,11 @@ describe("AdvancedSearchDesktop", () => {

it("should render a technologies selector with all technology types", () => {

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper enableAdvancedSearchDefault>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

fireEvent.mouseDown(screen.getByLabelText("Technologies", { selector: "input" }));
Expand All @@ -151,26 +161,28 @@ describe("AdvancedSearchDesktop", () => {

it("should disable reset button if no advanced field is set", () => {

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

expect(screen.getByRole("button", { name: "Reset Advanced Fields" })).toBeDisabled();
});

it("should enable reset button if some advanced field is set", () => {

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
fields={[Object.keys(FieldOptions)[0]]}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

expect(screen.getByRole("button", { name: "Reset Advanced Fields" })).not.toBeDisabled();
Expand All @@ -184,14 +196,15 @@ describe("AdvancedSearchDesktop", () => {

const setFieldsMock = jest.fn();

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
fields={[Object.keys(FieldOptions)[0]]}
setFields={setFieldsMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

expect(screen.getAllByTestId("chip-option", {})).toHaveLength(1);
Expand All @@ -213,14 +226,15 @@ describe("AdvancedSearchDesktop", () => {

const setTechsMock = jest.fn();

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
technologies={[Object.keys(TechOptions)[0]]}
setTechs={setTechsMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

expect(screen.getAllByTestId("chip-option", {})).toHaveLength(1);
Expand All @@ -241,7 +255,7 @@ describe("AdvancedSearchDesktop", () => {
it("should call resetAdvancedSearch when Reset button is clicked", () => {
const resetFn = jest.fn();

render(
renderWithStoreAndTheme(
<AdvancedSearchWrapper
enableAdvancedSearchDefault
setJobType={() => {}}
Expand All @@ -253,7 +267,8 @@ describe("AdvancedSearchDesktop", () => {
technologies={[Object.keys(TechOptions)[0]]} // Must have something set to be able to click reset
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</AdvancedSearchWrapper>,
{ initialState, theme }
);

fireEvent.click(screen.getByRole("button", { name: "Reset Advanced Fields" }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,19 @@ const AdvancedSearchMobile = () => {
};

AdvancedSearchMobile.propTypes = {
open: PropTypes.bool.isRequired,
close: PropTypes.func.isRequired,
searchValue: PropTypes.string.isRequired,
submitForm: PropTypes.func.isRequired,
setSearchValue: PropTypes.func.isRequired,
resetAdvancedSearch: PropTypes.func.isRequired,
FieldsSelectorProps: PropTypes.object.isRequired,
TechsSelectorProps: PropTypes.object.isRequired,
JobTypeSelectorProps: PropTypes.object.isRequired,
JobDurationSwitchProps: PropTypes.object.isRequired,
ResetButtonProps: PropTypes.object.isRequired,
JobDurationSliderText: PropTypes.string.isRequired,
JobDurationCollapseProps: PropTypes.object.isRequired,
JobDurationSwitchLabel: PropTypes.string.isRequired,
JobDurationSliderProps: PropTypes.object.isRequired,
searchValue: PropTypes.string,
submitForm: PropTypes.func,
setSearchValue: PropTypes.func,
resetAdvancedSearch: PropTypes.func,
FieldsSelectorProps: PropTypes.object,
TechsSelectorProps: PropTypes.object,
JobTypeSelectorProps: PropTypes.object,
JobDurationSwitchProps: PropTypes.object,
ResetButtonProps: PropTypes.object,
JobDurationSliderText: PropTypes.string,
JobDurationCollapseProps: PropTypes.object,
JobDurationSwitchLabel: PropTypes.string,
JobDurationSliderProps: PropTypes.object,
onMobileClose: PropTypes.func,
};

Expand Down
Loading

0 comments on commit 0458ebc

Please sign in to comment.