Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Bug #2455 #2991

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/screens/UserPortal/People/People.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Provider } from 'react-redux';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
import type { InterfaceMember } from './People';
import People from './People';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
Expand Down Expand Up @@ -167,6 +168,62 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryAllByText('Noble Mittal')).not.toBe([]);
});

function compareProperties(
expectedProps: string[],
actualObject: object,
): boolean {
const actualProps = Object.keys(actualObject);
return expectedProps.every((prop) => actualProps.includes(prop));
}

describe('InterfaceMember properties comparison', () => {
it('should have all required properties', () => {
const expectedProperties = [
'firstName',
'lastName',
'image',
'_id',
'email',
'__typename',
];

const mockValidData: InterfaceMember = {
firstName: 'John',
lastName: 'Doe',
image: 'https://example.com/john.jpg',
_id: '1',
email: '[email protected]',
__typename: 'User',
};

const result = compareProperties(expectedProperties, mockValidData);
expect(result).toBe(true);
});

it('should fail if __typename is replaced with username', () => {
const expectedProperties = [
'firstName',
'lastName',
'image',
'_id',
'email',
'__typename', // Expect this property
];

const mockInvalidData = {
firstName: 'John',
lastName: 'Doe',
image: 'https://example.com/john.jpg',
_id: '1',
email: '[email protected]',
username: 'Member', // Incorrect property
};

const result = compareProperties(expectedProperties, mockInvalidData);
expect(result).toBe(false);
});
});

it('Search works properly by pressing enter', async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down
6 changes: 3 additions & 3 deletions src/screens/UserPortal/People/People.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ interface InterfaceOrganizationCardProps {
sno: string;
}

interface InterfaceMember {
export interface InterfaceMember {
firstName: string;
lastName: string;
image: string;
_id: string;
email: string;
userType: string;
__typename: string;
}

/**
Expand Down Expand Up @@ -243,7 +243,7 @@ export default function people(): JSX.Element {
image: member.image,
id: member._id,
email: member.email,
role: member.userType,
role: member.__typename,
sno: (index + 1).toString(),
};
return <PeopleCard key={index} {...cardProps} />;
Expand Down
Loading