Skip to content

Commit

Permalink
Merge pull request #150 from VividhPandey003/editorg
Browse files Browse the repository at this point in the history
Fix#143: Enable ability to edit org if website or github isn't provided
  • Loading branch information
kevkevinpal authored Feb 7, 2024
2 parents fb4be0b + 14b3c15 commit 02be1c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/components/form/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
23 changes: 22 additions & 1 deletion src/people/widgetViews/__tests__/EditOrgModal.spec.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -65,4 +65,25 @@ describe('EditOrgModal Component', () => {
render(<EditOrgModal {...props} />);
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(<EditOrgModal {...props} />);

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();
});
});
});
6 changes: 3 additions & 3 deletions src/people/widgetViews/organization/EditOrgModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 02be1c8

Please sign in to comment.