From 8e8cd3ce4be732b4d6ade1143f0851e1e482aef5 Mon Sep 17 00:00:00 2001 From: Amit Bora Date: Sat, 28 Dec 2024 21:04:14 +0530 Subject: [PATCH] Refactor: src/screens/BlockUser from Jest to Vitest (#2606) * Add BlockUser component tests and update package.json dependencies * Fix: Move @testing-library/dom to devDependencies * Add BlockUser component tests and update package.json dependencies * Fix: Move @testing-library/dom to devDependencies * fix: format fail --------- Co-authored-by: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> --- package-lock.json | 116 ++----- package.json | 1 + ...{BlockUser.test.tsx => BlockUser.spec.tsx} | 301 ++---------------- 3 files changed, 52 insertions(+), 366 deletions(-) rename src/screens/BlockUser/{BlockUser.test.tsx => BlockUser.spec.tsx} (52%) diff --git a/package-lock.json b/package-lock.json index 9c801aa1c0..7f115d04df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -80,6 +80,7 @@ "@babel/preset-env": "^7.26.0", "@babel/preset-react": "^7.25.7", "@babel/preset-typescript": "^7.26.0", + "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^12.1.10", @@ -4048,17 +4049,6 @@ "node": ">=6.0.0" } }, - "node_modules/@jridgewell/source-map": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", - "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", - "optional": true, - "peer": true, - "dependencies": { - "@jridgewell/gen-mapping": "^0.3.0", - "@jridgewell/trace-mapping": "^0.3.9" - } - }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", @@ -4610,6 +4600,7 @@ "version": "2.5.0", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.0.tgz", "integrity": "sha512-i0GV1yJnm2n3Yq1qw6QrUrd/LI9bE8WEBOTtOkpCXHHdyN3TAGgqAK/DAT05z4fq2x04cARXt2pDmjWjL92iTQ==", + "dev": true, "hasInstallScript": true, "optional": true, "dependencies": { @@ -4648,6 +4639,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "android" @@ -4667,6 +4659,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "darwin" @@ -4686,6 +4679,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "darwin" @@ -4705,6 +4699,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "freebsd" @@ -4724,6 +4719,7 @@ "cpu": [ "arm" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4743,6 +4739,7 @@ "cpu": [ "arm" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4762,6 +4759,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4781,6 +4779,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4800,6 +4799,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4819,6 +4819,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -4838,6 +4839,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "win32" @@ -4857,6 +4859,7 @@ "cpu": [ "ia32" ], + "dev": true, "optional": true, "os": [ "win32" @@ -4876,6 +4879,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "win32" @@ -5891,7 +5895,7 @@ "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.0.tgz", "integrity": "sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ==", "dev": true, - "peer": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", @@ -5911,7 +5915,6 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, - "peer": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -5928,7 +5931,6 @@ "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", "dev": true, - "peer": true, "dependencies": { "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", @@ -5943,7 +5945,6 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", "dev": true, - "peer": true, "engines": { "node": ">=10" }, @@ -5955,8 +5956,7 @@ "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true, - "peer": true + "dev": true }, "node_modules/@testing-library/jest-dom": { "version": "6.6.3", @@ -6041,8 +6041,7 @@ "version": "5.0.4", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", - "dev": true, - "peer": true + "dev": true }, "node_modules/@types/babel__core": { "version": "7.20.5", @@ -6125,18 +6124,6 @@ "resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-3.0.3.tgz", "integrity": "sha512-2p6olUZ4w3s+07q3Tm2dbiMZy5pCDfYwtLXXHUnVzXgQlZ/OyPtUz6OL382BkOuGlLXqfT+wqv8Fw2v8/0geBw==" }, - "node_modules/@types/eslint": { - "version": "8.44.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.0.tgz", - "integrity": "sha512-gsF+c/0XOguWgaOgvFs+xnnRqt9GwgTvIks36WpE6ueeI4KCEHHd8K/CKHqhOqrJKsYH8m27kRzQEvWXAwXUTw==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -9649,6 +9636,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==", + "dev": true, "optional": true, "bin": { "detect-libc": "bin/detect-libc.js" @@ -9722,8 +9710,7 @@ "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", - "dev": true, - "peer": true + "dev": true }, "node_modules/dom-align": { "version": "1.12.4", @@ -9925,16 +9912,6 @@ "node": ">= 0.8" } }, - "node_modules/encoding": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", - "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "optional": true, - "peer": true, - "dependencies": { - "iconv-lite": "^0.6.2" - } - }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -12180,19 +12157,6 @@ "cross-fetch": "4.0.0" } }, - "node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "optional": true, - "peer": true, - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/icss-utils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz", @@ -12260,7 +12224,7 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/immutable/-/immutable-5.0.2.tgz", "integrity": "sha512-1NU7hWZDkV7hJ4PJ9dur9gTNQ4ePNPN4k9/0YhwjzykTi/+3Q5pF93YU5QoVj8BuOnhLgaY8gs0U2pj4kSYVcw==", - "devOptional": true + "dev": true }, "node_modules/import-fresh": { "version": "3.3.0", @@ -15482,7 +15446,6 @@ "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", "dev": true, - "peer": true, "bin": { "lz-string": "bin/bin.js" } @@ -15942,6 +15905,7 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "dev": true, "optional": true }, "node_modules/node-fetch": { @@ -19013,7 +18977,7 @@ "version": "1.80.7", "resolved": "https://registry.npmjs.org/sass/-/sass-1.80.7.tgz", "integrity": "sha512-MVWvN0u5meytrSjsU7AWsbhoXi1sc58zADXFllfZzbsBT1GHjjar6JwBINYPRrkx/zqnQ6uqbQuHgE95O+C+eQ==", - "devOptional": true, + "dev": true, "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", @@ -19033,7 +18997,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.1.tgz", "integrity": "sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==", - "devOptional": true, + "dev": true, "dependencies": { "readdirp": "^4.0.1" }, @@ -19048,7 +19012,7 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.0.2.tgz", "integrity": "sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==", - "devOptional": true, + "dev": true, "engines": { "node": ">= 14.16.0" }, @@ -19377,7 +19341,7 @@ "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "devOptional": true, + "dev": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -19387,7 +19351,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "devOptional": true, + "dev": true, "engines": { "node": ">=0.10.0" } @@ -19815,32 +19779,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/terser": { - "version": "5.32.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.32.0.tgz", - "integrity": "sha512-v3Gtw3IzpBJ0ugkxEX8U0W6+TnPKRRCWGh1jC/iM/e3Ki5+qvO1L1EAZ56bZasc64aXHwRHNIQEzm6//i5cemQ==", - "optional": true, - "peer": true, - "dependencies": { - "@jridgewell/source-map": "^0.3.3", - "acorn": "^8.8.2", - "commander": "^2.20.0", - "source-map-support": "~0.5.20" - }, - "bin": { - "terser": "bin/terser" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/terser/node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "optional": true, - "peer": true - }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", diff --git a/package.json b/package.json index 8e528c2ceb..257949ead6 100644 --- a/package.json +++ b/package.json @@ -120,6 +120,7 @@ "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^12.1.10", + "@testing-library/dom": "^10.4.0", "@types/inquirer": "^9.0.7", "@types/jest": "^26.0.24", "@types/js-cookie": "^3.0.6", diff --git a/src/screens/BlockUser/BlockUser.test.tsx b/src/screens/BlockUser/BlockUser.spec.tsx similarity index 52% rename from src/screens/BlockUser/BlockUser.test.tsx rename to src/screens/BlockUser/BlockUser.spec.tsx index c851470d9b..51d16a61f9 100644 --- a/src/screens/BlockUser/BlockUser.test.tsx +++ b/src/screens/BlockUser/BlockUser.spec.tsx @@ -1,4 +1,4 @@ -import React, { act } from 'react'; +import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; @@ -10,16 +10,15 @@ import { BLOCK_PAGE_MEMBER_LIST, ORGANIZATIONS_LIST, } from 'GraphQl/Queries/Queries'; -import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; -import { ToastContainer } from 'react-toastify'; import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import i18nForTest from 'utils/i18nForTest'; import BlockUser from './BlockUser'; +import { vi, describe, beforeEach, test, expect } from 'vitest'; let userQueryCalled = false; @@ -241,94 +240,22 @@ const MOCKS = [ }, }, ]; -const MOCKS_EMPTY = [ - { - request: { - query: ORGANIZATIONS_LIST, - variables: { - id: 'orgid', - }, - }, - result: { - data: { - organizations: [ - { - _id: 'orgid', - image: '', - creator: { - firstName: 'firstName', - lastName: 'lastName', - email: 'email', - }, - name: 'name', - description: 'description', - location: 'location', - members: { - _id: 'id', - firstName: 'firstName', - lastName: 'lastName', - email: 'email', - }, - admins: { - _id: 'id', - firstName: 'firstName', - lastName: 'lastName', - email: 'email', - }, - membershipRequests: { - _id: 'id', - user: { - firstName: 'firstName', - lastName: 'lastName', - email: 'email', - }, - }, - blockedUsers: { - _id: 'id', - firstName: 'firstName', - lastName: 'lastName', - email: 'email', - }, - }, - ], - }, - }, - }, - - { - request: { - query: BLOCK_PAGE_MEMBER_LIST, - variables: { - firstName_contains: 'Peter', - lastName_contains: '', - orgId: 'orgid', - }, - }, - result: { - data: { - organizationsMemberConnection: { - edges: [], - }, - }, - }, - }, -]; const link = new StaticMockLink(MOCKS, true); -const link2 = new StaticMockLink(MOCKS_EMPTY, true); async function wait(ms = 500): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + await new Promise((resolve) => { + setTimeout(resolve, ms); }); } -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: () => ({ orgId: 'orgid' }), -})); +vi.mock('react-router-dom', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...(actual as object), + useParams: () => ({ orgId: 'orgid' }), + }; +}); describe('Testing Block/Unblock user screen', () => { beforeEach(() => { @@ -336,7 +263,7 @@ describe('Testing Block/Unblock user screen', () => { }); test('Components should be rendered properly', async () => { - window.location.assign('/blockuser/orgid'); + window.history.pushState({}, 'Test page', '/blockuser/orgid'); render( @@ -354,11 +281,11 @@ describe('Testing Block/Unblock user screen', () => { expect(screen.getByText('Search By First Name')).toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); + expect(window.location.pathname).toBe('/blockuser/orgid'); }); test('Testing block user functionality', async () => { - window.location.assign('/blockuser/orgid'); + window.history.pushState({}, 'Test page', '/blockuser/orgid'); render( @@ -372,9 +299,7 @@ describe('Testing Block/Unblock user screen', () => { , ); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); + userEvent.click(screen.getByTestId('userFilter')); userEvent.click(screen.getByTestId('showMembers')); await wait(); @@ -387,11 +312,11 @@ describe('Testing Block/Unblock user screen', () => { expect(screen.getByTestId('blockUser123')).toBeInTheDocument(); expect(screen.getByTestId('unBlockUser456')).toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); + expect(window.location.pathname).toBe('/blockuser/orgid'); }); test('Testing unblock user functionality', async () => { - window.location.assign('/blockuser/orgid'); + window.history.pushState({}, 'Test page', '/blockuser/orgid'); render( @@ -404,9 +329,7 @@ describe('Testing Block/Unblock user screen', () => { , ); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); + userEvent.click(screen.getByTestId('userFilter')); userEvent.click(screen.getByTestId('showMembers')); await wait(); @@ -420,11 +343,11 @@ describe('Testing Block/Unblock user screen', () => { expect(screen.getByTestId('blockUser123')).toBeInTheDocument(); expect(screen.getByTestId('unBlockUser456')).toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); + expect(window.location.pathname).toBe('/blockuser/orgid'); }); test('Testing First Name Filter', async () => { - window.location.assign('/blockuser/orgid'); + window.history.pushState({}, 'Test page', '/blockuser/orgid'); render( @@ -437,9 +360,7 @@ describe('Testing Block/Unblock user screen', () => { , ); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); + userEvent.click(screen.getByTestId('userFilter')); userEvent.click(screen.getByTestId('showMembers')); await wait(); @@ -448,9 +369,7 @@ describe('Testing Block/Unblock user screen', () => { expect(screen.getByText('Sam Smith')).toBeInTheDocument(); // Open Dropdown - await act(async () => { - userEvent.click(screen.getByTestId('nameFilter')); - }); + userEvent.click(screen.getByTestId('nameFilter')); // Select option and enter first name userEvent.click(screen.getByTestId('searchByFirstName')); const firstNameInput = screen.getByPlaceholderText(/Search by First Name/i); @@ -461,11 +380,11 @@ describe('Testing Block/Unblock user screen', () => { expect(screen.getByText('John Doe')).toBeInTheDocument(); expect(screen.queryByText('Sam Smith')).not.toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); + expect(window.location.pathname).toBe('/blockuser/orgid'); }); test('Testing Last Name Filter', async () => { - window.location.assign('/blockuser/orgid'); + window.history.pushState({}, 'Test page', '/blockuser/orgid'); render( @@ -479,178 +398,6 @@ describe('Testing Block/Unblock user screen', () => { , ); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); - userEvent.click(screen.getByTestId('showMembers')); - - await wait(); - - expect(screen.getByText('John Doe')).toBeInTheDocument(); - expect(screen.getByText('Sam Smith')).toBeInTheDocument(); - - // Open Dropdown - await act(async () => { - userEvent.click(screen.getByTestId('nameFilter')); - }); - // Select option and enter last name - userEvent.click(screen.getByTestId('searchByLastName')); - const lastNameInput = screen.getByPlaceholderText(/Search by Last Name/i); - userEvent.type(lastNameInput, 'doe{enter}'); - - await wait(700); - - expect(lastNameInput).toHaveValue('doe'); - expect(screen.getByText('John Doe')).toBeInTheDocument(); - expect(screen.queryByText('Sam Smith')).not.toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); - }); - - test('Testing No Spammers Present', async () => { - window.location.assign('/blockuser/orgid'); - render( - - - - - - - - - , - ); - - await wait(); - expect(screen.getByText(/No spammer found/i)).toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); - }); - - test('Testing All Members', async () => { - window.location.assign('/blockuser/orgid'); - - render( - - - - - - - - - - , - ); - await wait(); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); - userEvent.click(screen.getByTestId('showMembers')); - - await wait(700); - - expect(screen.getByTestId(/userFilter/i)).toHaveTextContent('All Members'); - expect(screen.getByText('John Doe')).toBeInTheDocument(); - expect(screen.getByText('Sam Smith')).toBeInTheDocument(); - - expect(window.location).toBeAt('/blockuser/orgid'); - }); - - test('Testing Blocked Users', async () => { - window.location.assign('/blockuser/orgid'); - - render( - - - - - - - - - - , - ); - - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); - - userEvent.click(screen.getByTestId('showBlockedMembers')); - await wait(); - - expect(screen.getByText('John Doe')).toBeInTheDocument(); - expect(screen.queryByText('Sam Smith')).not.toBeInTheDocument(); - - expect(window.location).toBeAt('/blockuser/orgid'); - }); - - test('Testing table data getting rendered', async () => { - window.location.assign('/orglist/orgid'); - const link = new StaticMockLink(MOCKS, true); - render( - - - - - - - - - , - ); - await act(async () => { - userEvent.click(screen.getByTestId('userFilter')); - }); - userEvent.click(screen.getByTestId('showMembers')); - - await wait(); - - expect(screen.getByTestId(/userList/)).toBeInTheDocument(); - expect(screen.getAllByText('Block/Unblock')).toHaveLength(1); - expect(screen.getByText('John Doe')).toBeInTheDocument(); - expect(screen.getByText('Sam Smith')).toBeInTheDocument(); - }); - - test('Testing No Results Found', async () => { - window.location.assign('/blockuser/orgid'); - render( - - - - - - - - - , - ); - - const input = screen.getByPlaceholderText('Search By First Name'); - await act(async () => { - userEvent.type(input, 'Peter{enter}'); - }); - await wait(700); - expect( - screen.getByText(`No results found for "Peter"`), - ).toBeInTheDocument(); - expect(window.location).toBeAt('/blockuser/orgid'); - }); - - test('Testing Search functionality', async () => { - window.location.assign('/blockuser/orgid'); - - render( - - - - - - - - - - , - ); await wait(); const searchBar = screen.getByTestId(/searchByName/i); const searchBtn = screen.getByTestId(/searchBtn/i);