11import React from 'react' ;
2- import { describe , it , expect , vi , beforeEach } from 'vitest' ;
2+ import { describe , it , expect , vi , beforeEach , suite } from 'vitest' ;
33import { render , screen , fireEvent , waitFor } from '@testing-library/react' ;
44import userEvent from '@testing-library/user-event' ;
55import { MockedProvider } from '@apollo/client/testing' ;
@@ -8,10 +8,7 @@ import i18n from 'i18next';
88import { toast } from 'react-toastify' ;
99
1010import OrgUpdate from './OrgUpdate' ;
11- import {
12- GET_ORGANIZATION_BASIC_DATA ,
13- ORGANIZATIONS_LIST_BASIC ,
14- } from 'GraphQl/Queries/Queries' ;
11+ import { GET_ORGANIZATION_BASIC_DATA } from 'GraphQl/Queries/Queries' ;
1512import { UPDATE_ORGANIZATION_MUTATION } from 'GraphQl/Mutations/mutations' ;
1613
1714vi . mock ( 'react-toastify' , ( ) => ( {
@@ -47,10 +44,6 @@ i18n.init({
4744 Location : 'Location' ,
4845 'Enter Organization location' : 'Enter Organization location' ,
4946 } ,
50- errors : {
51- organizationNameAlreadyExists :
52- 'The given organization name already exists' ,
53- } ,
5447 } ,
5548 } ,
5649} ) ;
@@ -74,31 +67,6 @@ const mockOrgData = {
7467 } ,
7568} ;
7669
77- const organizationsListMock = {
78- request : {
79- query : ORGANIZATIONS_LIST_BASIC ,
80- } ,
81- result : {
82- data : {
83- organizations : [
84- {
85- __typename : 'Organization' ,
86- id : '2' ,
87- name : 'Existing Org' ,
88- description : 'Existing Description' ,
89- addressLine1 : '456 Existing St' ,
90- addressLine2 : 'Suite 200' ,
91- city : 'Existing City' ,
92- state : 'Existing State' ,
93- postalCode : '67890' ,
94- countryCode : 'US' ,
95- avatarURL : null ,
96- } ,
97- ] ,
98- } ,
99- } ,
100- } ;
101-
10270describe ( 'OrgUpdate Component' , ( ) => {
10371 const mocks = [
10472 {
@@ -150,7 +118,6 @@ describe('OrgUpdate Component', () => {
150118 } ,
151119 } ,
152120 } ,
153- organizationsListMock ,
154121 ] ;
155122
156123 beforeEach ( ( ) => {
@@ -278,7 +245,7 @@ describe('OrgUpdate Component', () => {
278245 } ;
279246
280247 render (
281- < MockedProvider mocks = { [ queryMock , errorMock , organizationsListMock ] } >
248+ < MockedProvider mocks = { [ queryMock , errorMock ] } >
282249 < I18nextProvider i18n = { i18n } >
283250 < OrgUpdate orgId = "1" />
284251 </ I18nextProvider >
@@ -348,7 +315,7 @@ describe('OrgUpdate Component', () => {
348315 } ) ;
349316 } ) ;
350317
351- describe ( 'OrgUpdate Loading and Error States - Initial Tests ' , ( ) => {
318+ describe ( 'OrgUpdate Loading and Error States' , ( ) => {
352319 const mockOrgData = {
353320 organization : {
354321 __typename : 'Organization' ,
@@ -420,7 +387,7 @@ describe('OrgUpdate Component', () => {
420387 } ;
421388
422389 render (
423- < MockedProvider mocks = { [ loadingMock , organizationsListMock ] } >
390+ < MockedProvider mocks = { [ loadingMock ] } >
424391 < I18nextProvider i18n = { i18n } >
425392 < OrgUpdate orgId = "1" />
426393 </ I18nextProvider >
@@ -448,7 +415,7 @@ describe('OrgUpdate Component', () => {
448415 } ;
449416
450417 render (
451- < MockedProvider mocks = { [ errorMock , organizationsListMock ] } >
418+ < MockedProvider mocks = { [ errorMock ] } >
452419 < I18nextProvider i18n = { i18n } >
453420 < OrgUpdate orgId = "1" />
454421 </ I18nextProvider >
@@ -536,7 +503,7 @@ describe('OrgUpdate Component', () => {
536503 ] ;
537504
538505 render (
539- < MockedProvider mocks = { [ ... successMocks , organizationsListMock ] } >
506+ < MockedProvider mocks = { successMocks } >
540507 < I18nextProvider i18n = { i18n } >
541508 < OrgUpdate orgId = "1" />
542509 </ I18nextProvider >
@@ -632,7 +599,7 @@ describe('OrgUpdate Component', () => {
632599 ] ;
633600
634601 render (
635- < MockedProvider mocks = { [ ... errorMocks , organizationsListMock ] } >
602+ < MockedProvider mocks = { errorMocks } >
636603 < I18nextProvider i18n = { i18n } >
637604 < OrgUpdate orgId = "1" />
638605 </ I18nextProvider >
@@ -655,86 +622,6 @@ describe('OrgUpdate Component', () => {
655622 ) ;
656623 } ) ;
657624 } ) ;
658-
659- it ( 'shows error toast when organization name already exists' , async ( ) => {
660- const existingOrgMock = {
661- request : {
662- query : ORGANIZATIONS_LIST_BASIC ,
663- } ,
664- result : {
665- data : {
666- organizations : [
667- {
668- __typename : 'Organization' ,
669- id : '2' ,
670- name : 'Existing Org' ,
671- description : 'Existing Description' ,
672- addressLine1 : '456 Existing St' ,
673- addressLine2 : 'Suite 200' ,
674- city : 'Existing City' ,
675- state : 'Existing State' ,
676- postalCode : '67890' ,
677- countryCode : 'US' ,
678- avatarURL : null ,
679- } ,
680- ] ,
681- } ,
682- } ,
683- } ;
684-
685- const duplicateNameMock = {
686- request : {
687- query : UPDATE_ORGANIZATION_MUTATION ,
688- variables : {
689- input : {
690- id : '1' ,
691- name : 'Existing Org' ,
692- description : 'Test Description' ,
693- addressLine1 : '123 Test St' ,
694- addressLine2 : 'Suite 100' ,
695- city : 'Test City' ,
696- state : 'Test State' ,
697- postalCode : '12345' ,
698- countryCode : 'US' ,
699- isUserRegistrationRequired : false ,
700- } ,
701- } ,
702- } ,
703- error : new Error ( 'The given organization name already exists' ) ,
704- } ;
705-
706- render (
707- < MockedProvider
708- mocks = { [
709- ...mocks ,
710- existingOrgMock ,
711- organizationsListMock ,
712- duplicateNameMock ,
713- ] }
714- >
715- < I18nextProvider i18n = { i18n } >
716- < OrgUpdate orgId = "1" />
717- </ I18nextProvider >
718- </ MockedProvider > ,
719- ) ;
720-
721- await waitFor ( ( ) => {
722- expect ( screen . getByDisplayValue ( 'Test Org' ) ) . toBeInTheDocument ( ) ;
723- } ) ;
724-
725- fireEvent . change ( screen . getByDisplayValue ( 'Test Org' ) , {
726- target : { value : 'Existing Org' } ,
727- } ) ;
728-
729- const saveButton = screen . getByTestId ( 'save-org-changes-btn' ) ;
730- fireEvent . click ( saveButton ) ;
731-
732- await waitFor ( ( ) => {
733- expect ( toast . error ) . toHaveBeenCalledWith (
734- 'The given organization name already exists' ,
735- ) ;
736- } ) ;
737- } ) ;
738625 } ) ;
739626
740627 describe ( 'OrgUpdate Form Switch Controls' , ( ) => {
@@ -767,7 +654,6 @@ describe('OrgUpdate Component', () => {
767654 data : mockOrgData ,
768655 } ,
769656 } ,
770- organizationsListMock ,
771657 ] ;
772658
773659 beforeEach ( ( ) => {
@@ -841,10 +727,9 @@ describe('OrgUpdate Component', () => {
841727 } ) ;
842728 } ) ;
843729
844- describe ( 'OrgUpdate Loading and Error States' , ( ) => {
730+ it ( 'OrgUpdate Loading and Error States' , ( ) => {
845731 const mockOrgData = {
846732 organization : {
847- __typename : 'Organization' ,
848733 id : '1' ,
849734 name : 'Test Org' ,
850735 description : 'Test Description' ,
@@ -857,7 +742,6 @@ describe('OrgUpdate Component', () => {
857742 avatarURL : null ,
858743 createdAt : '2024-02-24T00:00:00Z' ,
859744 updatedAt : '2024-02-24T00:00:00Z' ,
860- isUserRegistrationRequired : false ,
861745 creator : {
862746 id : '1' ,
863747 name : 'Test Creator' ,
@@ -875,7 +759,7 @@ describe('OrgUpdate Component', () => {
875759 vi . clearAllMocks ( ) ;
876760 } ) ;
877761
878- it ( 'handles empty response from update mutation' , async ( ) => {
762+ suite ( 'handles empty response from update mutation' , async ( ) => {
879763 const mocks = [
880764 {
881765 request : {
@@ -911,7 +795,7 @@ describe('OrgUpdate Component', () => {
911795 ] ;
912796
913797 render (
914- < MockedProvider mocks = { [ ... mocks , organizationsListMock ] } >
798+ < MockedProvider mocks = { mocks } >
915799 < I18nextProvider i18n = { i18n } >
916800 < OrgUpdate orgId = "1" />
917801 </ I18nextProvider >
@@ -941,30 +825,30 @@ describe('OrgUpdate Component', () => {
941825 expect ( saveButton ) . not . toBeDisabled ( ) ;
942826 expect ( saveButton ) . toHaveTextContent ( 'Save Changes' ) ;
943827 } ) ;
828+ } ) ;
944829
945- it ( 'updates address line1 when input changes' , async ( ) => {
946- render (
947- < MockedProvider mocks = { mocks } >
948- < I18nextProvider i18n = { i18n } >
949- < OrgUpdate orgId = "1" />
950- </ I18nextProvider >
951- </ MockedProvider > ,
952- ) ;
830+ it ( 'updates address line1 when input changes' , async ( ) => {
831+ render (
832+ < MockedProvider mocks = { mocks } >
833+ < I18nextProvider i18n = { i18n } >
834+ < OrgUpdate orgId = "1" />
835+ </ I18nextProvider >
836+ </ MockedProvider > ,
837+ ) ;
953838
954- await waitFor ( ( ) => {
955- expect ( screen . getByDisplayValue ( '123 Test St' ) ) . toBeInTheDocument ( ) ;
956- } ) ;
839+ await waitFor ( ( ) => {
840+ expect ( screen . getByDisplayValue ( '123 Test St' ) ) . toBeInTheDocument ( ) ;
841+ } ) ;
957842
958- const addressInput = screen . getByPlaceholderText (
959- 'Enter Organization location' ,
960- ) ;
961- expect ( addressInput ) . toBeInTheDocument ( ) ;
843+ const addressInput = screen . getByPlaceholderText (
844+ 'Enter Organization location' ,
845+ ) ;
846+ expect ( addressInput ) . toBeInTheDocument ( ) ;
962847
963- expect ( addressInput ) . toHaveValue ( '123 Test St' ) ;
848+ expect ( addressInput ) . toHaveValue ( '123 Test St' ) ;
964849
965- fireEvent . change ( addressInput , { target : { value : 'New Address Line' } } ) ;
850+ fireEvent . change ( addressInput , { target : { value : 'New Address Line' } } ) ;
966851
967- expect ( addressInput ) . toHaveValue ( 'New Address Line' ) ;
968- } ) ;
852+ expect ( addressInput ) . toHaveValue ( 'New Address Line' ) ;
969853 } ) ;
970854} ) ;
0 commit comments