From e21ec0b428f93136ea7ba2912ece23eb4d59da06 Mon Sep 17 00:00:00 2001 From: Shema Date: Tue, 29 Oct 2024 00:51:07 +0200 Subject: [PATCH] changes to getTeamsByUserRole and getRatingsByUserCohort --- src/Mutations/Ratings.tsx | 9 +- src/Mutations/teamMutation.tsx | 6 +- src/components/BulkRatingModal.tsx | 61 +- tests/components/BulkRatingModal.test.tsx | 140 + .../AdminTraineeDashboard.test.tsx.snap | 109 +- .../__snapshots__/DashHeader.test.tsx.snap | 2 +- .../__snapshots__/Header.test.tsx.snap | 126 +- .../__snapshots__/Cohorts.test.tsx.snap | 154 +- tests/pages/__snapshots__/About.test.tsx.snap | 29 +- .../AdminTraineeDashboard.test.tsx.snap | 109 +- .../__snapshots__/Admindash.test.tsx.snap | 154 +- .../__snapshots__/GradingSystem.test.tsx.snap | 186 +- .../pages/__snapshots__/Profile.test.tsx.snap | 3346 +++++++++++++++-- .../TraineeRatingDashboard.test.tsx.snap | 170 +- .../UpdateTraineeRating.test.tsx.snap | 186 +- .../__snapshots__/userRegister.test.tsx.snap | 2 +- 16 files changed, 3839 insertions(+), 950 deletions(-) create mode 100644 tests/components/BulkRatingModal.test.tsx diff --git a/src/Mutations/Ratings.tsx b/src/Mutations/Ratings.tsx index 299054c18..2474c5257 100644 --- a/src/Mutations/Ratings.tsx +++ b/src/Mutations/Ratings.tsx @@ -180,10 +180,13 @@ export const REJECT_RATING = gql` } `; -export const FETCH_SPRINTS = gql` - query fetchSprints($orgToken: String!){ - fetchSprints(orgToken: $orgToken) +export const GET_RATINGS_BY_USER_COHORT = gql` + query getRatingsByUserCohort($orgToken: String!){ + getRatingsByUserCohort(orgToken: $orgToken){ + id + sprint } +} ` export const ADD_RATINGS_BY_FILE = gql` diff --git a/src/Mutations/teamMutation.tsx b/src/Mutations/teamMutation.tsx index bb1700e30..7f7de1094 100644 --- a/src/Mutations/teamMutation.tsx +++ b/src/Mutations/teamMutation.tsx @@ -53,9 +53,9 @@ export const DeleteTeam = gql` } `; -export const GET_TEAMS_BY_ROLE = gql` - query getTeamsByRole($orgToken: String!) { - getTeamsByRole(orgToken: $orgToken){ +export const GET_TEAMS_BY_USER_ROLE = gql` + query getTeamsByUserRole($orgToken: String!) { + getTeamsByUserRole(orgToken: $orgToken){ id name members { diff --git a/src/components/BulkRatingModal.tsx b/src/components/BulkRatingModal.tsx index 2d5752b71..c1e199f63 100644 --- a/src/components/BulkRatingModal.tsx +++ b/src/components/BulkRatingModal.tsx @@ -2,9 +2,9 @@ import { useLazyQuery, useMutation } from "@apollo/client" import React, { useEffect, useState } from "react" import { useTranslation } from "react-i18next" import * as XLSX from "xlsx" -import { ADD_RATINGS_BY_FILE, FETCH_SPRINTS } from "../Mutations/Ratings" +import { ADD_RATINGS_BY_FILE, GET_RATINGS_BY_USER_COHORT } from "../Mutations/Ratings" import { toast } from "react-toastify" -import { GET_TEAMS_BY_ROLE } from "../Mutations/teamMutation" +import { GET_TEAMS_BY_USER_ROLE } from "../Mutations/teamMutation" type BulkRatingModalProps = { bulkRateModal: boolean, @@ -20,19 +20,19 @@ const orgToken = localStorage.getItem('orgToken') const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalProps) => { const { t } = useTranslation() - const [fetchSprints, { data: sprints, loading: loadingSprints, error: sprintsError }] = useLazyQuery(FETCH_SPRINTS, { + const [getRatingsByUserCohort, { data: ratings, loading: loadingRatings, error: ratingsError }] = useLazyQuery(GET_RATINGS_BY_USER_COHORT, { variables: { orgToken }, fetchPolicy: 'network-only', }) - const [getTeamsByRole, {data: teams, loading: loadingTeams, error: teamsError}] = useLazyQuery(GET_TEAMS_BY_ROLE, { + const [getTeamsByUserRole, {data: teams, loading: loadingTeams, error: teamsError}] = useLazyQuery(GET_TEAMS_BY_USER_ROLE, { variables: { orgToken }, fetchPolicy: 'network-only', }) - const [addRatingsByFile, { data: ratings, loading: loadingRatings, error: ratingsError }] = useMutation(ADD_RATINGS_BY_FILE) + const [addRatingsByFile, { data: bulkRatings, loading: loadingBulkRatings, error: bulkRatingsError }] = useMutation(ADD_RATINGS_BY_FILE) const [formData, setFormData] = useState({ sprint: '', file: null @@ -51,7 +51,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro orgToken }, }) - fetchSprints() + getRatingsByUserCohort() toast.success("Rating completed succefully") } catch (err: any) { toast.error(err?.message) @@ -61,7 +61,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro const downloadTeamFile = async(e: any)=>{ try{ if(selectedTeam === '') throw new Error("No Team was selected") - const team = teams.getTeamsByRole.find((team:any)=>team.id === selectedTeam) + const team = teams.getTeamsByUserRole.find((team:any)=>team.id === selectedTeam) const rows: any = [] team.members.forEach((member: any)=>{ console.log(member) @@ -91,8 +91,8 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro } useEffect(() => { - fetchSprints() - getTeamsByRole() + getRatingsByUserCohort() + getTeamsByUserRole() }, []) return ( @@ -105,10 +105,10 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
-
+
-
{ const file = e.target.files?.[0] setFormData({ ...formData, file: file ? file : null }) }} + accept=".xlsx, .xls" >
- setSelectedTeam(e.target.value)}> + { - teams && teams.getTeamsByRole.length > 0 ? - teams.getTeamsByRole.map((team: any)=>) + teams && teams.getTeamsByUserRole.length > 0 ? + teams.getTeamsByUserRole.map((team: any)=>) : '' } - +
{ - ratings && ratings.addRatingsByFile.RejectedRatings.length > 0 ? + bulkRatings && bulkRatings.addRatingsByFile.RejectedRatings.length > 0 ?
- {ratings.addRatingsByFile?.RejectedRatings.map((rating: any, index: number) => + {bulkRatings.addRatingsByFile?.RejectedRatings.map((rating: any, index: number) => diff --git a/tests/components/BulkRatingModal.test.tsx b/tests/components/BulkRatingModal.test.tsx new file mode 100644 index 000000000..ef47aa0fc --- /dev/null +++ b/tests/components/BulkRatingModal.test.tsx @@ -0,0 +1,140 @@ +import React from "react" +import "@testing-library/jest-dom" +import { MockedProvider, MockedResponse } from "@apollo/client/testing" +import { render, fireEvent, screen, cleanup, waitFor } from "@testing-library/react" +import BulkRatingModal from "../../src/components/BulkRatingModal" +import { GET_RATINGS_BY_USER_COHORT } from "../../src/Mutations/Ratings" +import { GET_TEAMS_BY_USER_ROLE } from "../../src/Mutations/teamMutation" + +const getRatingsByUserCohort: MockedResponse = { + request:{ + query: GET_RATINGS_BY_USER_COHORT, + // variables: { + // orgToken: 'mocked_org_token' + // } + }, + variableMatcher: () => true, + result:{ + data: { + getRatingsByUserCohort: [ + { + id: "1", + sprint: 1, + }, + { + id: "2", + sprint: 2, + } + ] + } + } +} + +const getTeamsByUserRole = { + request: { + query: GET_TEAMS_BY_USER_ROLE, + // variables: { + // orgToken: "mocked_org_token" + // } + }, + variableMatcher: () => true, + result:{ + data: { + getTeamsByUserRole: [ + { + id: "1", + name: "Team I", + members:[ + { + email: "test@gmail.com", + role: "trainee" + }, + { + email: "test2@gmail.com", + role: "ttl" + }, + { + email: "test3@gmail.com", + role: "trainee" + }, + ] + }, + { + id: "2", + name: "Team II", + members:[ + { + email: "test4@gmail.com", + role: "trainee" + }, + { + email: "test5@gmail.com", + role: "ttl" + }, + { + email: "test6@gmail.com", + role: "trainee" + }, + ] + } + ] + } + } +} + +jest.mock('react-toastify', () => ({ + toast: { + success: jest.fn(), + error: jest.fn(), + } +})) + +beforeEach(() => { + localStorage.setItem('auth_token', 'mocked_auth_token') + localStorage.setItem('orgToken', 'mocked_org_token') + localStorage.setItem('auth', JSON.stringify({ + auth: true, + email: "testing@gmail.com", + firstName: "Jack", + role: "admin", + userId: "1" + })) +}) + +afterEach(() => { + localStorage.clear() + cleanup() +}) + +describe("BulkRatingModal", () => { + const setBulkRateModel = jest.fn() + + it("displays all sprints", async() => { + render( + + + + ) + await waitFor(()=>{ + expect(screen.getByTestId("sprint-option-1")).toBeInTheDocument() + expect(screen.getByTestId("sprint-option-2")).toBeInTheDocument() + }) + }) + it("displays teams", async() => { + render( + + + + ) + await waitFor(()=>{ + expect(screen.getByTestId("team-option-1")).toBeInTheDocument() + expect(screen.getByTestId("team-option-2")).toBeInTheDocument() + }) + }) +}) \ No newline at end of file diff --git a/tests/components/__snapshots__/AdminTraineeDashboard.test.tsx.snap b/tests/components/__snapshots__/AdminTraineeDashboard.test.tsx.snap index 36f807f1b..50066f148 100644 --- a/tests/components/__snapshots__/AdminTraineeDashboard.test.tsx.snap +++ b/tests/components/__snapshots__/AdminTraineeDashboard.test.tsx.snap @@ -463,7 +463,7 @@ Array [ name="date" readOnly={true} type="text" - value="2024-10-06" + value="2024-10-28" />
, +
+
+
+

+ Bulk Rating +

+
+
+
+ +
+ + +
+
+ +
+ + +
+
+
+
+ + +
+ +
+
+
,
@@ -955,15 +1053,6 @@ Array [ + -
-
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + +
    +
  • @@ -272,7 +277,7 @@ exports[`Header Tests Should render the header with home 1`] = ` exports[`Header Tests Should render the header with no active 1`] = `
  • -
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + +
    +
  • @@ -541,7 +551,7 @@ exports[`Header Tests Should render the header with no active 1`] = ` exports[`Header Tests Should render the header with no active 2`] = `
  • -
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + + +
  • @@ -781,7 +796,7 @@ exports[`Header Tests Should render the header with no active 2`] = ` exports[`Header Tests Should render the header with no active 3`] = `
  • -
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + + +
  • @@ -1051,7 +1071,7 @@ exports[`Header Tests Should render the header with no active 3`] = ` exports[`Header Tests Should render the header with pricing active 1`] = `
  • -
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + + +
  • @@ -1321,7 +1346,7 @@ exports[`Header Tests Should render the header with pricing active 1`] = ` exports[`Header Tests Should render the header with product active 1`] = `
  • -
  • - - Docs - -
  • +

    + Docs +

    + + ▼ + + +
  • diff --git a/tests/containers/admin-dashboard/__snapshots__/Cohorts.test.tsx.snap b/tests/containers/admin-dashboard/__snapshots__/Cohorts.test.tsx.snap index 2843aa57f..d496ad235 100644 --- a/tests/containers/admin-dashboard/__snapshots__/Cohorts.test.tsx.snap +++ b/tests/containers/admin-dashboard/__snapshots__/Cohorts.test.tsx.snap @@ -1026,14 +1026,14 @@ Array [ colSpan={6} >
    diff --git a/tests/pages/__snapshots__/About.test.tsx.snap b/tests/pages/__snapshots__/About.test.tsx.snap index 539be8335..7df40910f 100644 --- a/tests/pages/__snapshots__/About.test.tsx.snap +++ b/tests/pages/__snapshots__/About.test.tsx.snap @@ -170,7 +170,6 @@ exports[`About page renders the about page 1`] = ` > Come shape the future together -
    - I'm extremely impressed with Pulse and their performance management platform. - Since using their services, it has been a game-changer for our organization. - The platform is intuitive, easy to navigate, and packed with powerful features. + Content1

    - I'm delighted to share my positive experience with Pulse and their exceptional - performance management platform. Implementing their services has led to remarkable - improvements in our performance tracking and management processes. + Content2

    - - We are thrilled with the services provided by Pulse. Their performance management platform - has exceeded our expectations in every way. The user-friendly interface and comprehensive - features have made tracking and monitoring our performance metrics a breeze. - + Content3

    - I'm extremely impressed with Pulse and their performance management platform. - Since using their services, it has been a game-changer for our organization. - The platform is intuitive, easy to navigate, and packed with powerful features. + Content1

    - I'm delighted to share my positive experience with Pulse and their exceptional - performance management platform. Implementing their services has led to remarkable - improvements in our performance tracking and management processes. + Content2

    - - We are thrilled with the services provided by Pulse. Their performance management platform - has exceeded our expectations in every way. The user-friendly interface and comprehensive - features have made tracking and monitoring our performance metrics a breeze. - + Content3

    diff --git a/tests/pages/__snapshots__/AdminTraineeDashboard.test.tsx.snap b/tests/pages/__snapshots__/AdminTraineeDashboard.test.tsx.snap index cdb28ed1f..e09e8f87e 100644 --- a/tests/pages/__snapshots__/AdminTraineeDashboard.test.tsx.snap +++ b/tests/pages/__snapshots__/AdminTraineeDashboard.test.tsx.snap @@ -463,7 +463,7 @@ Array [ name="date" readOnly={true} type="text" - value="2024-10-06" + value="2024-10-28" />
    , +
    +
    +
    +

    + Bulk Rating +

    +
    +
    +
    +
    +
    + + +
    +
    + +
    + + +
    +
    +
    +
    + + +
    + +
    +
    +
    ,
    @@ -955,15 +1053,6 @@ Array [ + -
    diff --git a/tests/pages/__snapshots__/GradingSystem.test.tsx.snap b/tests/pages/__snapshots__/GradingSystem.test.tsx.snap index ce701c773..6dc4578ab 100644 --- a/tests/pages/__snapshots__/GradingSystem.test.tsx.snap +++ b/tests/pages/__snapshots__/GradingSystem.test.tsx.snap @@ -369,7 +369,7 @@ Array [ className="max-w-full" >
  • - - - - -
    @@ -181,7 +188,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
    {rating.email ? rating.email : "null"} {rating.quantity ? rating.quantity : "null"}
    -   - -
    -
    - -

    - - No records available - -

    -
    - + No records available +

    @@ -504,14 +484,14 @@ Array [ colSpan={3} >
    diff --git a/tests/pages/__snapshots__/Profile.test.tsx.snap b/tests/pages/__snapshots__/Profile.test.tsx.snap index 50a62de3d..da0515bac 100644 --- a/tests/pages/__snapshots__/Profile.test.tsx.snap +++ b/tests/pages/__snapshots__/Profile.test.tsx.snap @@ -165,16 +165,17 @@ Object { >
    -