Skip to content

Commit

Permalink
fix tests and display teams when cohort is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
shema-surge committed Nov 21, 2024
1 parent ebe5758 commit 242008d
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 301 deletions.
16 changes: 3 additions & 13 deletions src/components/BulkRatingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const BulkRatingModal = ({ setBulkRateModal }: {setBulkRateModal: React.Dispatch
</button>
</div>
{
formData.cohortId ?
teams ?
<>
<hr className="mt-5 border-b" />
<div className="flex flex-col gap-3 p-3 rounded-md text-sm bg-neutral-700">
Expand All @@ -265,19 +265,9 @@ const BulkRatingModal = ({ setBulkRateModal }: {setBulkRateModal: React.Dispatch
<select data-testid="select-team" className="p-1 text-sm text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary" defaultValue={""} onChange={(e) => setSelectedTeam(e.target.value)}>
<option data-testid="team-default-option">Choose a team</option>
{
teams && teams.getTeamsByCohort.length > 0 ?
teams.getTeamsByCohort.length > 0 ?
teams.getTeamsByCohort.map((team: any) => <option data-testid={`team-option-${team.id}`} key={team.id} value={team.id}>{team.name}</option>)
: ''
}
{
loadingTeams ?
<option data-testid="team-loading-option">Loading...</option>
: ''
}
{
teamsError ?
<option data-testid="team-error-option">No teams found...</option>
: ''
: <option data-testid="team-empty-option" value="">No teams found...</option>
}
</select>
<button data-testid="download-button" type="button" onClick={downloadTeamFile} className="py-1 px-2 text-white rounded-lg bg-green-700 text-sm font-serif font-semibold">Download</button>
Expand Down
20 changes: 12 additions & 8 deletions tests/components/BulkRatingModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ afterEach(() => {
})

describe("BulkRatingModal", () => {
const setBulkRateModel = jest.fn()
const setBulkRateModal: React.Dispatch<React.SetStateAction<boolean>> = jest.fn()
it("displays all cohorts", async() => {
render(
<MockedProvider mocks={[getUserCohorts, getRatingsByCohort, getTeamsByCohort]} addTypename={false}>
<BulkRatingModal
setBulkRateModal={setBulkRateModel}
setBulkRateModal={setBulkRateModal}
></BulkRatingModal>
</MockedProvider>
)
Expand All @@ -209,7 +209,7 @@ describe("BulkRatingModal", () => {
render(
<MockedProvider mocks={[getUserCohorts, getRatingsByCohort, getTeamsByCohort]} addTypename={false}>
<BulkRatingModal
setBulkRateModal={setBulkRateModel}
setBulkRateModal={setBulkRateModal}
></BulkRatingModal>
</MockedProvider>
)
Expand All @@ -228,7 +228,7 @@ describe("BulkRatingModal", () => {
render(
<MockedProvider mocks={[getUserCohorts, getRatingsByCohort, getTeamsByCohort]} addTypename={false}>
<BulkRatingModal
setBulkRateModal={setBulkRateModel}
setBulkRateModal={setBulkRateModal}
></BulkRatingModal>
</MockedProvider>
)
Expand All @@ -248,7 +248,7 @@ describe("BulkRatingModal", () => {
render(
<MockedProvider mocks={[getUserCohorts, getRatingsByCohort, getTeamsByCohort, addRatingsByFile]} addTypename={false}>
<BulkRatingModal
setBulkRateModal={setBulkRateModel}
setBulkRateModal={setBulkRateModal}
></BulkRatingModal>
</MockedProvider>
)
Expand Down Expand Up @@ -281,19 +281,23 @@ describe("BulkRatingModal", () => {
render(
<MockedProvider mocks={[getUserCohorts, getRatingsByCohort, getTeamsByCohort, addRatingsByFile]} addTypename={false}>
<BulkRatingModal
setBulkRateModal={setBulkRateModel}
setBulkRateModal={setBulkRateModal}
></BulkRatingModal>
</MockedProvider>
)
const cohortInput = screen.getByTestId("select-cohort")
const teamInput = screen.getByTestId("select-team")
const downloadButton = screen.getByTestId("download-button")
await waitFor(()=>{
fireEvent.change(cohortInput, {
target: {
value: "1"
}
})
const teamInput=screen.getByTestId("select-team")
const downloadButton=screen.getByTestId("download-button")
expect(teamInput).toBeInTheDocument()
expect(downloadButton).toBeInTheDocument()
expect(screen.getByTestId("team-option-1")).toBeInTheDocument()
expect(screen.getByTestId("team-option-2")).toBeInTheDocument()
fireEvent.change(teamInput, {
target: {
value: "1"
Expand Down
113 changes: 1 addition & 112 deletions tests/components/__snapshots__/AdminTraineeDashboard.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Array [
name="date"
readOnly={true}
type="text"
value="2024-11-19"
value="2024-11-21"
/>
</div>
<div
Expand Down Expand Up @@ -925,117 +925,6 @@ Array [
</div>
</div>
</div>,
<div
className="hidden h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 flex items-center justify-center px-4"
>
<div
className="w-full p-4 pb-8 bg-indigo-100 rounded-lg dark:bg-dark-bg sm:w-3/4 xl:w-4/12"
>
<div
className="flex flex-wrap items-center justify-center w-full card-title"
>
<h3
className="w-11/12 text-sm font-bold text-center dark:text-white"
>
Bulk Rating
</h3>
<hr
className="w-full my-3 border-b bg-primary"
/>
</div>
<div>
<form
className="flex flex-col gap-5"
data-testid="bulk-rating-form"
onSubmit={[Function]}
>
<div
className="flex flex-col gap-1"
>
<label>
Choose a cohort
</label>
<select
className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-cohort"
defaultValue=""
onChange={[Function]}
>
<option>
Choose a cohort
</option>
</select>
<label>
Choose a sprint
</label>
<select
className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-sprint"
defaultValue=""
onChange={[Function]}
>
<option>
Choose a sprint
</option>
</select>
</div>
<div
className="flex items-center justify-between"
>
<input
accept=".xlsx, .xls"
className="w-1/2 h-full bg-gray-600 rounded-md"
data-testid="file-input"
onChange={[Function]}
type="file"
/>
<div
className="flex gap-2"
>
<select
className="p-2 text-sm text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-team"
defaultValue=""
onChange={[Function]}
>
<option
data-testid="team-default-option"
>
Choose a team
</option>
</select>
<button
className="p-3 text-white rounded-lg bg-green-500 text-sm font-serif font-semibold"
data-testid="download-button"
onClick={[Function]}
type="button"
>
Download
</button>
</div>
</div>
<div />
<div
className="flex justify-between w-full"
>
<button
className="w-[40%] md:w-1/4 p-3 text-white rounded-lg bg-primary text-sm font-serif font-semibold"
onClick={[Function]}
type="button"
>
Cancel
</button>
<button
className="w-[40%] md:w-1/4 p-3 text-white rounded-lg bg-primary text-sm font-serif font-semibold"
type="submit"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>,
<div
className="flex flex-col"
>
Expand Down
113 changes: 1 addition & 112 deletions tests/pages/__snapshots__/AdminTraineeDashboard.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Array [
name="date"
readOnly={true}
type="text"
value="2024-11-19"
value="2024-11-21"
/>
</div>
<div
Expand Down Expand Up @@ -925,117 +925,6 @@ Array [
</div>
</div>
</div>,
<div
className="hidden h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 flex items-center justify-center px-4"
>
<div
className="w-full p-4 pb-8 bg-indigo-100 rounded-lg dark:bg-dark-bg sm:w-3/4 xl:w-4/12"
>
<div
className="flex flex-wrap items-center justify-center w-full card-title"
>
<h3
className="w-11/12 text-sm font-bold text-center dark:text-white"
>
Bulk Rating
</h3>
<hr
className="w-full my-3 border-b bg-primary"
/>
</div>
<div>
<form
className="flex flex-col gap-5"
data-testid="bulk-rating-form"
onSubmit={[Function]}
>
<div
className="flex flex-col gap-1"
>
<label>
Choose a cohort
</label>
<select
className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-cohort"
defaultValue=""
onChange={[Function]}
>
<option>
Choose a cohort
</option>
</select>
<label>
Choose a sprint
</label>
<select
className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-sprint"
defaultValue=""
onChange={[Function]}
>
<option>
Choose a sprint
</option>
</select>
</div>
<div
className="flex items-center justify-between"
>
<input
accept=".xlsx, .xls"
className="w-1/2 h-full bg-gray-600 rounded-md"
data-testid="file-input"
onChange={[Function]}
type="file"
/>
<div
className="flex gap-2"
>
<select
className="p-2 text-sm text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
data-testid="select-team"
defaultValue=""
onChange={[Function]}
>
<option
data-testid="team-default-option"
>
Choose a team
</option>
</select>
<button
className="p-3 text-white rounded-lg bg-green-500 text-sm font-serif font-semibold"
data-testid="download-button"
onClick={[Function]}
type="button"
>
Download
</button>
</div>
</div>
<div />
<div
className="flex justify-between w-full"
>
<button
className="w-[40%] md:w-1/4 p-3 text-white rounded-lg bg-primary text-sm font-serif font-semibold"
onClick={[Function]}
type="button"
>
Cancel
</button>
<button
className="w-[40%] md:w-1/4 p-3 text-white rounded-lg bg-primary text-sm font-serif font-semibold"
type="submit"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>,
<div
className="flex flex-col"
>
Expand Down
Loading

0 comments on commit 242008d

Please sign in to comment.