From 14b3c154cce2a840964ed37e55baa529b9b524fb Mon Sep 17 00:00:00 2001 From: Vividh Pandey Date: Sun, 4 Feb 2024 18:28:46 +0530 Subject: [PATCH] Org: fixed edit org if website or github isn't provided Signed-off-by: Vividh Pandey --- src/components/form/schema.ts | 6 +++-- .../__tests__/EditOrgModal.spec.tsx | 23 ++++++++++++++++++- .../widgetViews/organization/EditOrgModal.tsx | 6 ++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/components/form/schema.ts b/src/components/form/schema.ts index d8589227..a88aad76 100644 --- a/src/components/form/schema.ts +++ b/src/components/form/schema.ts @@ -9,6 +9,7 @@ import { import { FormField } from './utils'; const strValidator = Yup.string().trim().required('Required'); +const optionalValidator = Yup.string().trim().nullable(); const strValidatorNotRequired = Yup.string().trim(); const badgeObjectStrValidator = Yup.object().shape({ value: strValidator @@ -823,7 +824,7 @@ export const organizationSchema: FormField[] = [ name: 'website', label: 'Website', type: 'text', - validator: strValidator, + validator: optionalValidator, style: { gridArea: '2 / 1 / 3 / 2', height: '85px' @@ -837,7 +838,7 @@ export const organizationSchema: FormField[] = [ label: 'Github repo', type: 'text', prepend: 'https://github.com/', - validator: strValidator, + validator: optionalValidator, style: { gridArea: '3 / 1 / 4 / 2', height: '85px' @@ -850,6 +851,7 @@ export const organizationSchema: FormField[] = [ name: 'description', label: 'Description', type: 'textarea', + validator: Yup.string().optional(), style: { height: '202px', gridArea: '1 / 2 / 4 / 3' diff --git a/src/people/widgetViews/__tests__/EditOrgModal.spec.tsx b/src/people/widgetViews/__tests__/EditOrgModal.spec.tsx index 5597ed79..26597483 100644 --- a/src/people/widgetViews/__tests__/EditOrgModal.spec.tsx +++ b/src/people/widgetViews/__tests__/EditOrgModal.spec.tsx @@ -1,6 +1,6 @@ import '@testing-library/jest-dom'; import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import { Organization } from 'store/main'; import EditOrgModal from '../organization/EditOrgModal'; @@ -65,4 +65,25 @@ describe('EditOrgModal Component', () => { render(); expect(screen.getByText(/Delete Organization/i)).toBeInTheDocument(); }); + + test('Save button is enabled if name have a value, and website, github, logo, description are empty', async () => { + render(); + + fireEvent.change(screen.getByLabelText(/Organization Name/i) as HTMLInputElement, { + target: { value: 'Updated Org' } + }); + + await waitFor(() => { + fireEvent.change(screen.getByLabelText(/Description/i) as HTMLInputElement, { + target: { value: '' } + }); + fireEvent.change(screen.getByLabelText(/Website/i) as HTMLInputElement, { + target: { value: '' } + }); + fireEvent.change(screen.getByLabelText(/Github repo/i) as HTMLInputElement, { + target: { value: '' } + }); + expect(screen.getByText(/Save changes/i)).toBeEnabled(); + }); + }); }); diff --git a/src/people/widgetViews/organization/EditOrgModal.tsx b/src/people/widgetViews/organization/EditOrgModal.tsx index 0ea7bf02..eb0bdb2f 100644 --- a/src/people/widgetViews/organization/EditOrgModal.tsx +++ b/src/people/widgetViews/organization/EditOrgModal.tsx @@ -218,9 +218,9 @@ const EditOrgModal = (props: EditOrgModalProps) => { name: body.name || org.name, owner_pubkey: org.owner_pubkey, img: img || org.img, - description: body.description || org?.description, - github: body.github || org?.github, - website: body.website || org?.website, + description: body.description !== undefined ? body.description : org?.description || null, + github: body.github !== undefined ? body.github : org?.github || null, + website: body.website !== undefined ? body.website : org?.website || null, created: org.created, updated: org.updated, show: body?.show !== undefined ? body.show : org.show,