Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
abeglova committed Feb 7, 2024
1 parent 45d6ca8 commit ef8020b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 79 deletions.
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ export const LEARNING_RESOURCE_ENDPOINT = "resource"
export const CONTENT_FILE_ENDPOINT = "content_file"

export const COURSENUM_SORT_FIELD = "department_course_numbers.sort_coursenum"


70 changes: 19 additions & 51 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
InitialEntry
} from "history"

import {
LearningResourceType,
INITIAL_FACET_STATE
} from "./constants"
import { LearningResourceType, INITIAL_FACET_STATE } from "./constants"

import { useCourseSearch, useSearchInputs, useSyncUrlAndSearch } from "./index"
import { facetMap, wait } from "./test_util"
Expand Down Expand Up @@ -76,16 +73,15 @@ function TestComponent(props: any) {
onClick={(text: any) => acceptSuggestion(text)}
/>
<input onChange={updateText} value={text || ""} />
<select
className="sort"
onChange={updateSort}
value={sort || ""}
>
<select className="sort" onChange={updateSort} value={sort || ""}>
<option value="coursenum">Course number</option>
<option value="">Relevance</option>
</select>
<button onClick={() => updateUI("list")} className="ui"></button>
<button onClick={() => updateEndpoint("content_file")} className="endpoint"></button>
<button
onClick={() => updateEndpoint("content_file")}
className="endpoint"
></button>
<div className="submit" onClick={onSubmit} />
<FacetTestComponent
clearAllFilters={clearAllFilters}
Expand Down Expand Up @@ -186,7 +182,7 @@ describe("useCourseSearch", () => {
0,
"coursenum",
null,
null,
null
])
})

Expand All @@ -212,7 +208,7 @@ describe("useCourseSearch", () => {
0,
null,
null,
'content_file'
"content_file"
])
})

Expand Down Expand Up @@ -277,14 +273,7 @@ describe("useCourseSearch", () => {
null
])
wrapper.find(".clearAllFilters").simulate("click")
checkSearchCall(runSearch, [
"",
INITIAL_FACET_STATE,
0,
null,
null,
null
])
checkSearchCall(runSearch, ["", INITIAL_FACET_STATE, 0, null, null, null])
})

it("should let you accept a suggestion", async () => {
Expand All @@ -307,11 +296,7 @@ describe("useCourseSearch", () => {
const { wrapper, runSearch } = render()
act(() => {
// @ts-expect-error
wrapper.find(".toggleFacet").prop("onClick")(
"topic",
"mathematics",
true
)
wrapper.find(".toggleFacet").prop("onClick")("topic", "mathematics", true)
})
checkSearchCall(runSearch, [
"",
Expand Down Expand Up @@ -340,7 +325,7 @@ describe("useCourseSearch", () => {
"",
{
...INITIAL_FACET_STATE,
resource_type: [LearningResourceType.Program],
resource_type: [LearningResourceType.Program],
topic: ["mathematics"]
},
0,
Expand Down Expand Up @@ -455,14 +440,7 @@ describe("useCourseSearch", () => {
act(() => {
wrapper.find(".load-more").simulate("click")
})
checkSearchCall(runSearch, [
"",
INITIAL_FACET_STATE,
50,
null,
null,
null
])
checkSearchCall(runSearch, ["", INITIAL_FACET_STATE, 50, null, null, null])
})

it("should set the correct from value when searchPageSize is a function", async () => {
Expand All @@ -477,14 +455,7 @@ describe("useCourseSearch", () => {
act(() => {
wrapper.find(".load-more").simulate("click")
})
checkSearchCall(runSearch, [
"",
INITIAL_FACET_STATE,
50,
null,
null,
null
])
checkSearchCall(runSearch, ["", INITIAL_FACET_STATE, 50, null, null, null])
})
})

Expand All @@ -508,15 +479,13 @@ describe("useSearchInputs", () => {
activeFacets: { topic: ["math", "bio"] },
ui: "list",
endpoint: null

},
expected: {
text: "cat",
activeFacets: { ...INITIAL_FACET_STATE, topic: ["math", "bio"] },
ui: "list",
sort: null,
endpoint: null

}
},
{
Expand All @@ -528,7 +497,6 @@ describe("useSearchInputs", () => {
sort: "coursenum",
ui: null,
endpoint: null

}
}
])(
Expand Down Expand Up @@ -604,8 +572,8 @@ describe("useSearchInputs", () => {
text: "cat",
activeFacets: { topic: ["math", "bio"] },
ui: "list",
sort: "coursenum",
endpoint: "endpoint"
sort: "coursenum",
endpoint: "endpoint"
})}`
]
const history = createMemoryHistory({ initialEntries })
Expand All @@ -623,8 +591,8 @@ describe("useSearchInputs", () => {
text: "",
activeFacets: INITIAL_FACET_STATE,
sort: null,
ui: 'list',
endpoint: 'endpoint'
ui: "list",
endpoint: "endpoint"
})
expect(result.current.text).toEqual("")
})
Expand Down Expand Up @@ -656,8 +624,8 @@ describe("useSearchInputs", () => {
`?${serializeSearchParams({
text: "cat",
activeFacets: {
topic: ["math", "bio"],
level: ["beginner"],
topic: ["math", "bio"],
level: ["beginner"],
department: ["7", "8"]
}
})}`
Expand Down
11 changes: 5 additions & 6 deletions src/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ describe("buildSearchUrl", () => {
text: "The Best Course",
from: 10,
size: 20,
sort: 'sort',
sort: "sort",
activeFacets: {
platform: ['mitx', 'ocw'],
department: ['2']
platform: ["mitx", "ocw"],
department: ["2"]
},
aggregations: ['platform']
aggregations: ["platform"]
}


expect(buildSearchUrl('http://www.base.edu/', params)).toEqual(
expect(buildSearchUrl("http://www.base.edu/", params)).toEqual(
"http://www.base.edu/?q=The+Best+Course&offset=10&limit=20&sortby=sort&aggregations=platform&platform=mitx%2Cocw&department=2"
)
})
Expand Down
24 changes: 16 additions & 8 deletions src/test_util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export const wait = (millis: number): Promise<undefined> =>
new Promise(resolve => setTimeout(resolve, millis))

export const facetMap = new Map(
export const facetMap = new Map([
[
['topic', [
"topic",
[
{ key: "Physics", doc_count: 6568 },
{ key: "Engineering", doc_count: 5600 },
{ key: "Computer Science", doc_count: 5325 },
Expand Down Expand Up @@ -144,8 +145,11 @@ export const facetMap = new Map(
{ key: "Indigenous Studies", doc_count: 1 },
{ key: "Math", doc_count: 1 },
{ key: "Social Medicine", doc_count: 1 }
]],
['offered_by', [
]
],
[
"offered_by",
[
{ key: "OCW", doc_count: 8298 },
{ key: "CBMM", doc_count: 620 },
{ key: "MITx", doc_count: 411 },
Expand Down Expand Up @@ -174,10 +178,14 @@ export const facetMap = new Map(
{ key: "MIT LGO", doc_count: 10 },
{ key: "Department of Biology", doc_count: 8 },
{ key: "xPRO", doc_count: 4 }
]],
['resource_type', [
]
],
[
"resource_type",
[
{ key: "video", doc_count: 8156 },
{ key: "course", doc_count: 2508 },
{ key: "podcast", doc_count: 1180 }
]]
])
]
]
])
25 changes: 13 additions & 12 deletions src/url_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe("course search library", () => {
})
).toEqual({
activeFacets: {
platform: [],
offered_by: [],
platform: [],
offered_by: [],
topic: [
"Science",
"Physics",
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("course search library", () => {
department: [],
level: [],
course_feature: [],
resource_type: ['course'],
resource_type: ["course"],
content_feature_type: []
},
text: "",
Expand All @@ -114,15 +114,14 @@ describe("course search library", () => {
})
})


it("should deserialize level from the URL", () => {
expect(deserializeSearchParams({ search: "l=graduate" })).toEqual({
activeFacets: {
platform: [],
offered_by: [],
topic: [],
department: [],
level: ['graduate'],
level: ["graduate"],
course_feature: [],
resource_type: [],
content_feature_type: []
Expand All @@ -149,7 +148,11 @@ describe("course search library", () => {
level: [],
course_feature: [],
resource_type: [],
content_feature_type: ["Exams with Solutions", "Exams", "Media Assignments with Examples"]
content_feature_type: [
"Exams with Solutions",
"Exams",
"Media Assignments with Examples"
]
},
text: "",
sort: null,
Expand Down Expand Up @@ -194,7 +197,7 @@ describe("course search library", () => {
content_feature_type: []
},
text: "",
sort: '-coursenum',
sort: "-coursenum",
ui: null,
endpoint: null
})
Expand All @@ -219,7 +222,6 @@ describe("course search library", () => {
})
})


it("should deserialize the endpoint param", () => {
expect(deserializeSearchParams({ search: "e=endpoint" })).toEqual({
activeFacets: {
Expand All @@ -235,7 +237,7 @@ describe("course search library", () => {
text: "",
sort: null,
ui: null,
endpoint: 'endpoint'
endpoint: "endpoint"
})
})

Expand Down Expand Up @@ -353,7 +355,6 @@ describe("course search library", () => {
).toEqual("r=course")
})


it("should serialize course_feature", () => {
expect(
serializeSearchParams({
Expand Down Expand Up @@ -401,15 +402,15 @@ describe("course search library", () => {
it("should serialize sort", () => {
expect(
serializeSearchParams({
sort: 'sort'
sort: "sort"
})
).toEqual("s=sort")
})

it("should serialize endpoint", () => {
expect(
serializeSearchParams({
endpoint: 'endpoint'
endpoint: "endpoint"
})
).toEqual("e=endpoint")
})
Expand Down

0 comments on commit ef8020b

Please sign in to comment.