-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increased dateformatter files coverage
- Loading branch information
Showing
7 changed files
with
102 additions
and
77 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
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
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
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 |
---|---|---|
@@ -1,78 +1,59 @@ | ||
import React from 'react'; | ||
import { MockedProvider } from '@apollo/react-testing'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import 'jest-location-mock'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { store } from 'state/store'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import OrganizationScreen from './OrganizationScreen'; | ||
import { ORGANIZATIONS_LIST } from 'GraphQl/Queries/Queries'; | ||
import { ORGANIZATION_EVENT_LIST } from 'GraphQl/Queries/Queries'; | ||
import { StaticMockLink } from 'utils/StaticMockLink'; | ||
import styles from './OrganizationScreen.module.css'; | ||
|
||
let mockID: string | undefined = '123'; | ||
const mockID: string | undefined = '123'; | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ orgId: mockID }), | ||
useMatch: () => ({ params: { eventId: 'event123', orgId: '123' } }), | ||
})); | ||
|
||
const MOCKS = [ | ||
{ | ||
request: { | ||
query: ORGANIZATIONS_LIST, | ||
query: ORGANIZATION_EVENT_LIST, | ||
variables: { id: '123' }, | ||
}, | ||
result: { | ||
data: { | ||
organizations: [ | ||
eventsByOrganization: [ | ||
{ | ||
_id: '123', | ||
image: null, | ||
creator: { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
}, | ||
name: 'Test Organization', | ||
description: 'Testing this organization', | ||
address: { | ||
city: 'Mountain View', | ||
countryCode: 'US', | ||
dependentLocality: 'Some Dependent Locality', | ||
line1: '123 Main Street', | ||
line2: 'Apt 456', | ||
postalCode: '94040', | ||
sortingCode: 'XYZ-789', | ||
state: 'CA', | ||
}, | ||
userRegistrationRequired: true, | ||
visibleInSearch: true, | ||
members: [], | ||
admins: [], | ||
membershipRequests: [], | ||
blockedUsers: [], | ||
_id: 'event123', | ||
title: 'Test Event Title', | ||
description: 'Test Description', | ||
startDate: '2024-01-01', | ||
endDate: '2024-01-02', | ||
location: 'Test Location', | ||
startTime: '09:00', | ||
endTime: '17:00', | ||
allDay: false, | ||
recurring: false, | ||
isPublic: true, | ||
isRegisterable: true, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
]; | ||
const link = new StaticMockLink(MOCKS, true); | ||
|
||
const resizeWindow = (width: number): void => { | ||
window.innerWidth = width; | ||
fireEvent(window, new Event('resize')); | ||
}; | ||
|
||
const clickToggleMenuBtn = (toggleButton: HTMLElement): void => { | ||
fireEvent.click(toggleButton); | ||
}; | ||
const link = new StaticMockLink(MOCKS, true); | ||
|
||
describe('Testing LeftDrawer in OrganizationScreen', () => { | ||
test('Testing LeftDrawer in page functionality', async () => { | ||
describe('Testing OrganizationScreen', () => { | ||
const renderComponent = (): void => { | ||
render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<MockedProvider addTypename={false} link={link} mocks={MOCKS}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
|
@@ -82,36 +63,41 @@ describe('Testing LeftDrawer in OrganizationScreen', () => { | |
</BrowserRouter> | ||
</MockedProvider>, | ||
); | ||
const toggleButton = screen.getByTestId('closeMenu') as HTMLElement; | ||
const icon = toggleButton.querySelector('i'); | ||
}; | ||
|
||
// Resize window to a smaller width | ||
resizeWindow(800); | ||
clickToggleMenuBtn(toggleButton); | ||
expect(icon).toHaveClass('fa fa-angle-double-left'); | ||
// Resize window back to a larger width | ||
test('renders correctly with event title', async () => { | ||
renderComponent(); | ||
|
||
resizeWindow(1000); | ||
clickToggleMenuBtn(toggleButton); | ||
expect(icon).toHaveClass('fa fa-angle-double-right'); | ||
|
||
clickToggleMenuBtn(toggleButton); | ||
expect(icon).toHaveClass('fa fa-angle-double-left'); | ||
await waitFor(() => { | ||
const mainPage = screen.getByTestId('mainpageright'); | ||
expect(mainPage).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('should be redirected to / if orgId is undefined', async () => { | ||
mockID = undefined; | ||
render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<OrganizationScreen /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider>, | ||
test('handles drawer toggle correctly', () => { | ||
renderComponent(); | ||
|
||
const closeButton = screen.getByTestId('closeMenu'); | ||
fireEvent.click(closeButton); | ||
|
||
// Check for contract class after closing | ||
expect(screen.getByTestId('mainpageright')).toHaveClass('_expand_ccl5z_8'); | ||
|
||
const openButton = screen.getByTestId('openMenu'); | ||
fireEvent.click(openButton); | ||
|
||
// Check for expand class after opening | ||
expect(screen.getByTestId('mainpageright')).toHaveClass( | ||
'_contract_ccl5z_61', | ||
); | ||
expect(window.location.pathname).toEqual('/'); | ||
}); | ||
|
||
test('handles window resize', () => { | ||
renderComponent(); | ||
|
||
window.innerWidth = 800; | ||
fireEvent(window, new Event('resize')); | ||
|
||
expect(screen.getByTestId('mainpageright')).toHaveClass(styles.expand); | ||
}); | ||
}); |
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
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { formatDate } from './dateFormatter'; | ||
|
||
describe('formatDate', () => { | ||
test('formats date with st suffix', () => { | ||
expect(formatDate('2023-01-01')).toBe('1st Jan 2023'); | ||
expect(formatDate('2023-05-21')).toBe('21st May 2023'); | ||
expect(formatDate('2023-10-31')).toBe('31st Oct 2023'); | ||
}); | ||
|
||
test('formats date with nd suffix', () => { | ||
expect(formatDate('2023-06-02')).toBe('2nd Jun 2023'); | ||
expect(formatDate('2023-09-22')).toBe('22nd Sep 2023'); | ||
}); | ||
|
||
test('formats date with rd suffix', () => { | ||
expect(formatDate('2023-07-03')).toBe('3rd Jul 2023'); | ||
expect(formatDate('2023-08-23')).toBe('23rd Aug 2023'); | ||
}); | ||
|
||
test('formats date with th suffix', () => { | ||
expect(formatDate('2023-02-04')).toBe('4th Feb 2023'); | ||
expect(formatDate('2023-03-11')).toBe('11th Mar 2023'); | ||
expect(formatDate('2023-04-12')).toBe('12th Apr 2023'); | ||
expect(formatDate('2023-05-13')).toBe('13th May 2023'); | ||
expect(formatDate('2023-06-24')).toBe('24th Jun 2023'); | ||
}); | ||
|
||
test('throws error for empty date string', () => { | ||
expect(() => formatDate('')).toThrow('Date string is required'); | ||
}); | ||
|
||
test('throws error for invalid date string', () => { | ||
expect(() => formatDate('invalid-date')).toThrow( | ||
'Invalid date string provided', | ||
); | ||
}); | ||
}); |