-
-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed Bug #2455 * Added test for interface
- Loading branch information
1 parent
6349f3f
commit 4713884
Showing
2 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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}> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters