-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2458 from OneCommunityGlobal/development
Frontend Release to Main [3.66]
- Loading branch information
Showing
48 changed files
with
2,002 additions
and
1,074 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,94 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import Project from './Project'; | ||
import thunk from 'redux-thunk'; | ||
import { authMock, rolesMock, userProfileMock } from '../../../__tests__/mockStates'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
const renderProject = (props) => { | ||
const store = mockStore({ | ||
auth: authMock, | ||
userProfile: userProfileMock, | ||
role: rolesMock.role, | ||
}); | ||
|
||
return render( | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<Project {...props} /> | ||
</BrowserRouter> | ||
</Provider> | ||
); | ||
}; | ||
|
||
describe('Project Component', () => { | ||
const sampleProjectData = { | ||
_id: '1', | ||
projectName: 'Sample Project', | ||
category: 'Unspecified', | ||
isActive: true, | ||
}; | ||
|
||
const sampleProps = { | ||
projectData: sampleProjectData, | ||
index: 0, | ||
darkMode: false, | ||
hasPermission: jest.fn((permission) => true), | ||
onUpdateProject: jest.fn(), | ||
onClickArchiveBtn: jest.fn(), | ||
}; | ||
|
||
it('renders correctly with props', () => { | ||
const { getByDisplayValue, getByText } = renderProject(sampleProps); | ||
|
||
// Check if the input element is present | ||
expect(getByDisplayValue('Sample Project')).toBeInTheDocument(); | ||
|
||
// Verify the category value | ||
expect(getByText('Unspecified')).toBeInTheDocument(); | ||
}); | ||
|
||
it('updates project name on input change', async () => { | ||
const { getByDisplayValue } = renderProject(sampleProps); | ||
|
||
// Find the input element using getByDisplayValue | ||
const inputElement = getByDisplayValue('Sample Project'); | ||
|
||
// Simulate a user changing the input value | ||
fireEvent.change(inputElement, { target: { value: 'New Project Name' } }); | ||
|
||
await waitFor(() => { | ||
// Check if the input value has been updated | ||
expect(getByDisplayValue('New Project Name')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('toggles project active status on button click', () => { | ||
const { getByTestId } = renderProject(sampleProps); | ||
|
||
// Find the active status button and click it | ||
const activeButton = getByTestId('project-active'); | ||
fireEvent.click(activeButton); | ||
|
||
// Check if the onUpdateProject function has been called | ||
expect(sampleProps.onUpdateProject).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('triggers delete action on button click', () => { | ||
const { getByTestId } = renderProject(sampleProps); | ||
|
||
// Find the delete button and click it | ||
const deleteButton = getByTestId('delete-button'); | ||
fireEvent.click(deleteButton); | ||
|
||
// Check if the onClickArchiveBtn function has been called | ||
expect(sampleProps.onClickArchiveBtn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
Oops, something went wrong.