diff --git a/package-lock.json b/package-lock.json index af0005c84..a1144a70b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -96,7 +96,8 @@ "@types/cleave.js": "^1.4.7", "@types/enzyme": "^3.10.13", "@types/faker": "5.5.3", - "@types/jest": "^29.5.3", + "@types/jest": "^29.5.12", + "@types/mocha": "^10.0.7", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", "@types/react-dropzone": "^5.1.0", @@ -105,7 +106,6 @@ "@types/react-test-renderer": "^18.0.0", "@types/react-toastify": "^4.1.0", "@types/sinon": "^10.0.15", - "@types/testing-library__jest-dom": "^5.14.8", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "autoprefixer": "^10.4.7", @@ -4857,6 +4857,12 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true }, + "node_modules/@types/mocha": { + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", + "dev": true + }, "node_modules/@types/node": { "version": "20.11.26", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.26.tgz", @@ -5899,13 +5905,13 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", - "devOptional": true + "optional": true }, "node_modules/are-we-there-yet": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", - "devOptional": true, + "optional": true, "dependencies": { "delegates": "^1.0.0", "readable-stream": "^3.6.0" @@ -5918,7 +5924,7 @@ "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "devOptional": true, + "optional": true, "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -7047,7 +7053,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", - "devOptional": true, + "optional": true, "engines": { "node": ">=10" } @@ -7362,7 +7368,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", - "devOptional": true, + "optional": true, "bin": { "color-support": "bin.js" } @@ -7483,7 +7489,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==", - "devOptional": true + "optional": true }, "node_modules/content-disposition": { "version": "0.5.4", @@ -8202,7 +8208,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", - "devOptional": true + "optional": true }, "node_modules/depd": { "version": "2.0.0", @@ -10308,7 +10314,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0" }, @@ -10320,7 +10326,7 @@ "version": "3.3.6", "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "devOptional": true, + "optional": true, "dependencies": { "yallist": "^4.0.0" }, @@ -10332,7 +10338,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "devOptional": true + "optional": true }, "node_modules/fs-monkey": { "version": "1.0.5", @@ -10397,7 +10403,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", - "devOptional": true, + "optional": true, "dependencies": { "aproba": "^1.0.3 || ^2.0.0", "color-support": "^1.1.2", @@ -10417,13 +10423,13 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "devOptional": true + "optional": true }, "node_modules/gauge/node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "devOptional": true, + "optional": true, "engines": { "node": ">=8" } @@ -10432,7 +10438,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "devOptional": true, + "optional": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -10769,7 +10775,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", - "devOptional": true + "optional": true }, "node_modules/hash-base": { "version": "3.0.4", @@ -15606,7 +15612,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0", "yallist": "^4.0.0" @@ -15619,7 +15625,7 @@ "version": "3.3.6", "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "devOptional": true, + "optional": true, "dependencies": { "yallist": "^4.0.0" }, @@ -15631,7 +15637,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "devOptional": true + "optional": true }, "node_modules/mkdirp": { "version": "0.5.6", @@ -18685,7 +18691,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", - "devOptional": true, + "optional": true, "dependencies": { "are-we-there-yet": "^2.0.0", "console-control-strings": "^1.1.0", @@ -21422,7 +21428,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", - "devOptional": true + "optional": true }, "node_modules/set-function-length": { "version": "1.2.2", @@ -22478,7 +22484,7 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==", - "devOptional": true, + "optional": true, "dependencies": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", @@ -22495,7 +22501,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "devOptional": true, + "optional": true, "bin": { "mkdirp": "bin/cmd.js" }, @@ -22507,7 +22513,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "devOptional": true + "optional": true }, "node_modules/terminal-link": { "version": "2.1.1", @@ -24001,7 +24007,7 @@ "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", - "devOptional": true, + "optional": true, "dependencies": { "string-width": "^1.0.2 || 2 || 3 || 4" } @@ -24010,13 +24016,13 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "devOptional": true + "optional": true }, "node_modules/wide-align/node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "devOptional": true, + "optional": true, "engines": { "node": ">=8" } @@ -24025,7 +24031,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "devOptional": true, + "optional": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", diff --git a/package.json b/package.json index 1bb3c8b6b..20eb9473c 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,8 @@ "@types/cleave.js": "^1.4.7", "@types/enzyme": "^3.10.13", "@types/faker": "5.5.3", - "@types/jest": "^29.5.3", + "@types/jest": "^29.5.12", + "@types/mocha": "^10.0.7", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", "@types/react-dropzone": "^5.1.0", @@ -126,7 +127,6 @@ "@types/react-test-renderer": "^18.0.0", "@types/react-toastify": "^4.1.0", "@types/sinon": "^10.0.15", - "@types/testing-library__jest-dom": "^5.14.8", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "autoprefixer": "^10.4.7", diff --git a/src/assets/oops.svg b/src/assets/oops.svg new file mode 100644 index 000000000..d38979c2d --- /dev/null +++ b/src/assets/oops.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/components/Docs/users.tsx b/src/components/Docs/users.tsx index 7aee6bf47..e0e46a343 100644 --- a/src/components/Docs/users.tsx +++ b/src/components/Docs/users.tsx @@ -1,41 +1,76 @@ -import React from 'react' -import DocsMain from './DocsMain' +import React from 'react'; +import DocsMain from './DocsMain'; -const UsersDocs = () => { - return ( -
- -
-
-

- Getting started -

-
- Devpulse is a semi-open platform i.e. using it, requires a certain level of approval from the owners/managers. If you browse the homepage, you might wonder why there is no signup button, this is because to sign up you need an invitation. -

- Terminology to be familiar with:

-
    +function UsersDocs() { + return ( +
    + +
    +
    +

    + Getting started +

    +
    + Devpulse is a semi-open platform i.e. using it, requires a + certain level of approval from the owners/managers. If you + browse the homepage, you might wonder why there is no signup + button, this is because to sign up you need an invitation. +

    + Terminology to be familiar with: +

    +
      +
    • + Organizations: each Devpulse user belongs to an + organization. The default organization is Andela. The + admin of a given organisation has the highest privilege; + they are the one in charge of managing the rest of the + users and different administrative tasks +
    • -
    • Organizations: each Devpulse user belongs to an organization. The default organization is Andela. The admin of a given organisation has the highest privilege; they are the one in charge of managing the rest of the users and different administrative tasks
    • - -
    • Programs: each organization should have a program that it is running.
    • -
    • Managers: each program should have managers with different access levels. (coordinators, technical team leads, managers)
    • -
    • Trainees: an ordinary user of the app will fall under the role of a trainee. As a trainee, you belong to a team, which in turn belongs to a cohort, which in turn belongs to a program
    • -
    - -

    Signing up as a user

    -

    To sign up, your org admin must send you an invite. The invitation email will contain the details of how to sign up

    -

    Signing in as a user

    -

    To sign in, go to the signin page, provide the correct name of your organization, on the next screen enter username and password.

    -
    -
    +
  • + Programs: each organization should have a program + that it is running. +
  • +
  • + Managers: each program should have managers with + different access levels. (coordinators, technical team + leads, managers) +
  • +
  • + Trainees: an ordinary user of the app will fall + under the role of a trainee. As a trainee, you belong to a + team, which in turn belongs to a cohort, which in turn + belongs to a program +
  • +
+

+ Signing up as a user +

+

+ To sign up,{' '} + + your org admin must send you an invite + + . The invitation email will contain the details of how to + sign up +

+

+ Signing in as a user +

+

+ To sign in, go to the signin page, provide the correct name + of your organization, on the next screen enter username and + password. +

+
- } - /> -
- ) + + } + /> + + ); } -export default UsersDocs \ No newline at end of file +export default UsersDocs; diff --git a/src/components/TraineePerformance.tsx b/src/components/TraineePerformance.tsx index e70550036..26616b459 100644 --- a/src/components/TraineePerformance.tsx +++ b/src/components/TraineePerformance.tsx @@ -9,6 +9,8 @@ import Button from './Buttons'; import RemarksModal from '../pages/ratings/CoordinatorRemarks'; import { UserContext } from '../hook/useAuth'; import { rowsType } from '../pages/ratings/frame'; +import oop from '../assets/oops.svg'; +import Spinner from './Spinner'; export const GET_RATINGS_DATA = gql` query FetchRatingsTrainee { @@ -60,10 +62,9 @@ export const GET_RATINGS_DATA = gql` } `; - function TraineePerfomance() { const [usedata, setUserdata] = React.useState([]); - const { data } = useQuery(GET_RATINGS_DATA, {}); + const { data, loading, error } = useQuery(GET_RATINGS_DATA, {}); const { user } = useContext(UserContext); const [row, setRow] = useState({ id: user?.userId, @@ -151,6 +152,51 @@ function TraineePerfomance() { const closeFeeds = () => { setToggle(false); }; + if (loading) { + return ( + <> +
+
+
+
+
+

+ +

+
+
+
+
+
+ + ); + } + if (ratings?.length === 0) { + return ( + <> +
+
+
+
+
+ images +
+
+ +
+
+

+ Performance updates are on the way! Stay tuned for the + latest insights! +

+
+
+
+
+
+ + ); + } return ( <> @@ -234,7 +280,9 @@ function TraineePerfomance() {

- {item.average %1 === 0? item.average: Number(item.average).toFixed(2)} + {item.average % 1 === 0 + ? item.average + : Number(item.average).toFixed(2)}

diff --git a/src/components/tests/Pagination.test.tsx b/src/components/tests/Pagination.test.tsx new file mode 100644 index 000000000..d164b0cc8 --- /dev/null +++ b/src/components/tests/Pagination.test.tsx @@ -0,0 +1,138 @@ +import { renderHook, act } from '@testing-library/react'; +import Pagination from '../../components/Pagination'; + +describe('Pagination', () => { + test('initializes with correct values', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + expect(result.current.totalPages).toBe(10); + expect(result.current.page).toBe(1); + expect(result.current.firstContentIndex).toBe(0); + expect(result.current.lastContentIndex).toBe(10); + }); + + test('changes page correctly', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + act(() => { + result.current.nextPage(); + }); + + expect(result.current.page).toBe(2); + expect(result.current.firstContentIndex).toBe(10); + expect(result.current.lastContentIndex).toBe(20); + + act(() => { + result.current.prevPage(); + }); + + expect(result.current.page).toBe(1); + expect(result.current.firstContentIndex).toBe(0); + expect(result.current.lastContentIndex).toBe(10); + }); + + test('does not go below page 1', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + act(() => { + result.current.prevPage(); + }); + + expect(result.current.page).toBe(1); + }); + + test('does not go above max pages', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + act(() => { + result.current.setPage(10); + result.current.nextPage(); + }); + + expect(result.current.page).toBe(10); + }); + + test('setPage works correctly', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + act(() => { + result.current.setPage(5); + }); + + expect(result.current.page).toBe(5); + expect(result.current.firstContentIndex).toBe(40); + expect(result.current.lastContentIndex).toBe(50); + }); + + test('handles edge cases in setPage', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + act(() => { + result.current.setPage(0); + }); + + expect(result.current.page).toBe(1); + + act(() => { + result.current.setPage(11); + }); + + expect(result.current.page).toBe(10); + }); + + test('calculates gaps correctly', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 100 }), + ); + + expect(result.current.gaps).toEqual({ + before: false, + paginationGroup: [2, 3, 4], + after: true, + }); + + act(() => { + result.current.setPage(5); + }); + + expect(result.current.gaps).toEqual({ + before: true, + paginationGroup: [4, 5, 6], + after: true, + }); + + act(() => { + result.current.setPage(10); + }); + + expect(result.current.gaps).toEqual({ + before: true, + paginationGroup: [7, 8, 9], // Adjusted to match component output + after: false, + }); + }); + test('handles small number of pages', () => { + const { result } = renderHook(() => + Pagination({ contentPerPage: 10, count: 30 }), + ); + + expect(result.current.totalPages).toBe(3); + expect(result.current.gaps).toEqual({ + before: false, + paginationGroup: [2], // Adjusted to match component output + after: false, + }); + }); +}); diff --git a/src/components/tests/TraineeAttendanceDetails.test.tsx b/src/components/tests/TraineeAttendanceDetails.test.tsx index cb01b3659..3f8e178bc 100644 --- a/src/components/tests/TraineeAttendanceDetails.test.tsx +++ b/src/components/tests/TraineeAttendanceDetails.test.tsx @@ -1,8 +1,12 @@ /* eslint-disable */ +import '@testing-library/jest-dom'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import renderer from 'react-test-renderer'; import TraineeAttendanceDetails from '../TraineeAttendanceDetails'; +import { screen, render } from '@testing-library/react'; +import { MockedProvider as ApolloProvider } from '@apollo/client/testing'; +import { BrowserRouter } from 'react-router-dom'; describe('Trainee Viewing Detailed Attendance Rating', () => { it('Renders a Detailed Trainee Attendance Page ', () => { @@ -15,4 +19,15 @@ describe('Trainee Viewing Detailed Attendance Rating', () => { .toJSON(); expect(elem).toMatchSnapshot(); }); + it('should render a Detailed Trainee Attendance Page ', () => { + const result = render( + + + + + , + ); + expect(screen.getAllByText('Record')).toHaveLength(3); + expect(screen.getByText('Comment')).toBeInTheDocument(); + }); }); diff --git a/src/components/tests/TraineePerformance.test.tsx b/src/components/tests/TraineePerformance.test.tsx index 62d9264b5..4292b63f9 100644 --- a/src/components/tests/TraineePerformance.test.tsx +++ b/src/components/tests/TraineePerformance.test.tsx @@ -1,14 +1,14 @@ /* eslint-disable */ import '@testing-library/jest-dom'; -import { fireEvent, render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import React from 'react'; import { BrowserRouter } from 'react-router-dom'; import '../../../test/jest/__mocks__/matchMedia'; -import TraineePerfomance from '../TraineePerformance'; -import { MockedProvider as ApolloProvider } from '@apollo/client/testing'; +import TraineePerfomance, { GET_RATINGS_DATA } from '../TraineePerformance'; +import { MockedProvider as ApolloProvider, wait } from '@apollo/client/testing'; describe('View overall performance', () => { - it('Renders a Detailed Trainee Performance Page ', () => { + it('Renders a Detailed Trainee Performance Page with no data ', () => { const PreMck = jest.fn(); const NexMck = jest.fn(); const setPageMck = jest.fn(); @@ -20,5 +20,6 @@ describe('View overall performance', () => { , ); + expect(screen.getByText(/Loading.../i)).toBeInTheDocument(); }); }); diff --git a/src/components/tests/TraineeRatingDashboard.test.tsx b/src/components/tests/TraineeRatingDashboard.test.tsx index 43352df58..42fd2d2e3 100644 --- a/src/components/tests/TraineeRatingDashboard.test.tsx +++ b/src/components/tests/TraineeRatingDashboard.test.tsx @@ -1,6 +1,9 @@ +import '@testing-library/jest-dom'; import React from 'react'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter, BrowserRouter } from 'react-router-dom'; import renderer from 'react-test-renderer'; +import { screen, render } from '@testing-library/react'; +import { MockedProvider as ApolloProvider } from '@apollo/client/testing'; import TraineeRatingDashboard from '../../pages/TraineeRatingDashboard'; @@ -23,4 +26,14 @@ describe('TraineeRatingDashboard Tests', () => { .toJSON(); expect(elem).toMatchSnapshot(); }); + it('Renders TraineeRatingDashboard', () => { + const result = render( + + + + + , + ); + screen.debug(undefined, 1000000); + }); }); diff --git a/src/components/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap b/src/components/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap index 82f5a6de5..88d2ae477 100644 --- a/src/components/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap +++ b/src/components/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap @@ -28,6 +28,7 @@ Array [ >
- add + diff --git a/src/components/tests/__snapshots__/Header.test.tsx.snap b/src/components/tests/__snapshots__/Header.test.tsx.snap index c5372e30b..8ff2c9f62 100644 --- a/src/components/tests/__snapshots__/Header.test.tsx.snap +++ b/src/components/tests/__snapshots__/Header.test.tsx.snap @@ -91,7 +91,7 @@ exports[`Header Tests Should render the header with home 1`] = ` > Docs @@ -234,7 +234,7 @@ exports[`Header Tests Should render the header with home 1`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -360,7 +360,7 @@ exports[`Header Tests Should render the header with no active 1`] = ` > Docs @@ -503,7 +503,7 @@ exports[`Header Tests Should render the header with no active 1`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -619,7 +619,7 @@ exports[`Header Tests Should render the header with no active 2`] = ` > Docs @@ -749,7 +749,7 @@ exports[`Header Tests Should render the header with no active 2`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -870,7 +870,7 @@ exports[`Header Tests Should render the header with no active 3`] = ` > Docs @@ -1013,7 +1013,7 @@ exports[`Header Tests Should render the header with no active 3`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -1140,7 +1140,7 @@ exports[`Header Tests Should render the header with pricing active 1`] = ` > Docs @@ -1283,7 +1283,7 @@ exports[`Header Tests Should render the header with pricing active 1`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -1409,7 +1409,7 @@ exports[`Header Tests Should render the header with product active 1`] = ` > Docs @@ -1552,7 +1552,7 @@ exports[`Header Tests Should render the header with product active 1`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs diff --git a/src/components/tests/contrySelect.test.tsx b/src/components/tests/contrySelect.test.tsx new file mode 100644 index 000000000..487c188b7 --- /dev/null +++ b/src/components/tests/contrySelect.test.tsx @@ -0,0 +1,50 @@ +import '@testing-library/jest-dom'; +import { render, screen, fireEvent } from '@testing-library/react'; +import React, { createRef } from 'react'; +import CountrySelector from '../CountrySelector'; + +describe('CountrySelector', () => { + let onToggleMock: jest.Mock; + let onChangeMock: jest.Mock; + + beforeEach(() => { + onToggleMock = jest.fn(); + onChangeMock = jest.fn(); + }); + + it('calls onToggle and clears query when clicking outside', () => { + const ref = createRef(); + render( + , + ); + + fireEvent.mouseDown(document); + + expect(onToggleMock).toHaveBeenCalled(); + }); + + it('does not call onToggle or clear query when clicking inside', () => { + const ref = createRef(); + render( + , + ); + + fireEvent.mouseDown(screen.getByTestId('countries')); + + expect(onToggleMock).not.toHaveBeenCalled(); + }); +}); diff --git a/src/components/tests/loginActivities.test.tsx b/src/components/tests/loginActivities.test.tsx index 7b403b5e3..c838d1e19 100644 --- a/src/components/tests/loginActivities.test.tsx +++ b/src/components/tests/loginActivities.test.tsx @@ -1,3 +1,4 @@ +import '@testing-library/jest-dom'; import { render, screen, fireEvent } from '@testing-library/react'; import { MockedProvider } from '@apollo/client/testing'; import { MemoryRouter, Route, Routes } from 'react-router-dom'; @@ -43,6 +44,9 @@ describe('LoginActivities', () => { , ); + expect( + screen.getByText(/Loading login activities.../i), + ).toBeInTheDocument(); }); it('displays loading state while fetching login activities', () => { render( diff --git a/src/containers/admin-dashBoard/tests/Cohorts.test.tsx b/src/containers/admin-dashBoard/tests/Cohorts.test.tsx index d5f9bf84d..23fcea528 100644 --- a/src/containers/admin-dashBoard/tests/Cohorts.test.tsx +++ b/src/containers/admin-dashBoard/tests/Cohorts.test.tsx @@ -21,7 +21,7 @@ describe('Cohorts tests', () => { .toJSON(); expect(elem).toMatchSnapshot(); }); - jest.setTimeout(10000); + jest.setTimeout(20000); it('Renders Cohorts Page', async () => { render( diff --git a/src/containers/admin-dashBoard/tests/Sessions.test.tsx b/src/containers/admin-dashBoard/tests/Sessions.test.tsx index 7f44cf02b..0a2e1acfe 100644 --- a/src/containers/admin-dashBoard/tests/Sessions.test.tsx +++ b/src/containers/admin-dashBoard/tests/Sessions.test.tsx @@ -1,3 +1,4 @@ +import '@testing-library/jest-dom'; import React from 'react'; import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; @@ -51,10 +52,13 @@ describe('AdminSission Component', () => { , ); + expect(screen.getByText(/AddSession/i)).toBeInTheDocument(); + expect(screen.getByText(/reallydeleteSession/i)).toBeInTheDocument(); + expect(screen.getByPlaceholderText('SessionName')).toBeInTheDocument(); await waitFor(() => { - // expect(screen.getByText('Test Session 1')).toBeInTheDocument(); - // expect(screen.getByText('Test Session 2')).toBeInTheDocument(); + expect(screen.getByText('Test Session 1')).toBeInTheDocument(); + expect(screen.getByText('Test Session 2')).toBeInTheDocument(); }); }); @@ -67,7 +71,7 @@ describe('AdminSission Component', () => { await waitFor(() => { fireEvent.click(screen.getByText('register +')); - // expect(screen.getByText('AddSession')).toBeInTheDocument(); + expect(screen.getByText('AddSession')).toBeInTheDocument(); }); }); @@ -89,8 +93,29 @@ describe('AdminSission Component', () => { // Add more mocks if needed ]; + const sessionMocks = [ + { + request: { + query: GET_SESSIONS, + }, + result: { + data: { + id: 'abc233', + Sessionname: 'session 1', + description: '', + platform: '', + duration: '', + organizer: 'andela', + }, + }, + }, + // Add more mocks if needed + ]; render( - + , ); diff --git a/src/containers/tests/__snapshots__/MainRoutes.test.tsx.snap b/src/containers/tests/__snapshots__/MainRoutes.test.tsx.snap index 915ea633b..20c057e32 100644 --- a/src/containers/tests/__snapshots__/MainRoutes.test.tsx.snap +++ b/src/containers/tests/__snapshots__/MainRoutes.test.tsx.snap @@ -94,7 +94,7 @@ exports[`Main Routes Should render 1`] = ` > Docs @@ -237,7 +237,7 @@ exports[`Main Routes Should render 1`] = ` className="p-2 w-full mt-2 dark:text-dark-text-fill text-primary" > Docs @@ -368,7 +368,7 @@ exports[`Main Routes Should render 1`] = ` > Docs diff --git a/src/pages/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap b/src/pages/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap index 605cb0add..aedeba93a 100644 --- a/src/pages/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap +++ b/src/pages/tests/__snapshots__/AdminTraineeDashboard.test.tsx.snap @@ -28,6 +28,7 @@ Array [ >
- add + diff --git a/src/pages/tests/__snapshots__/OrgLogin.test.tsx.snap b/src/pages/tests/__snapshots__/OrgLogin.test.tsx.snap index a4d7ad1aa..1ca5565a9 100644 --- a/src/pages/tests/__snapshots__/OrgLogin.test.tsx.snap +++ b/src/pages/tests/__snapshots__/OrgLogin.test.tsx.snap @@ -89,7 +89,6 @@ exports[`Organization Login Should render 1`] = ` disabled={false} type="submit" > - Continue
diff --git a/src/pages/tests/__snapshots__/message.test.tsx.snap b/src/pages/tests/__snapshots__/message.test.tsx.snap index cddae7fa3..95d1b8e24 100644 --- a/src/pages/tests/__snapshots__/message.test.tsx.snap +++ b/src/pages/tests/__snapshots__/message.test.tsx.snap @@ -50,7 +50,7 @@ exports[`Page Not Found Renders the 404 Page 1`] = `

- We are delighted to have you with us. Soon you shall be receiving an email that contains an organization you will be part of. + We are delighted to have you with us. Soon you shall be receiving an email that contains details of a cohort that you will be part of.

Docs diff --git a/src/tests/__snapshots__/Siderbar.test.tsx.snap b/src/tests/__snapshots__/Siderbar.test.tsx.snap index 2d6e4f6ba..b02107203 100644 --- a/src/tests/__snapshots__/Siderbar.test.tsx.snap +++ b/src/tests/__snapshots__/Siderbar.test.tsx.snap @@ -95,7 +95,7 @@ exports[` Renders Home 1`] = ` > Docs