generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #828 from ita-social-projects/develop
Merge develop to release
- Loading branch information
Showing
59 changed files
with
1,410 additions
and
188 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import { Button } from '@material-ui/core'; | ||
import { useStyles } from './styles/CancelButton.style'; | ||
|
||
type CancelButtonPropsType = { | ||
label: string; | ||
onClick?: React.MouseEventHandler<HTMLButtonElement>; | ||
}; | ||
export const CancelButton: React.FC<CancelButtonPropsType> = ({ | ||
label, | ||
onClick, | ||
}) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Button | ||
className={classes.cancelButton} | ||
variant="contained" | ||
onClick={onClick} | ||
> | ||
{label} | ||
</Button> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/components/Form/Buttons/__tests__/CancelButton.test.tsx
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,27 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import userEvent, { TargetElement } from '@testing-library/user-event'; | ||
import { CancelButton } from '../CancelButton'; | ||
|
||
describe('Test for CancelButton component', () => { | ||
it('Should render a button', () => { | ||
const { container } = render(<CancelButton label="Hello world" />); | ||
expect(container.firstChild).toHaveClass('CancelButton-cancelButton-1'); | ||
}); | ||
|
||
it('Should render a label properly', () => { | ||
render(<CancelButton label="Hello world" />); | ||
const label = screen.getByText('Hello world'); | ||
|
||
expect(label).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should handle onClick', () => { | ||
const handleClick = jest.fn(); | ||
const { container } = render( | ||
<CancelButton label="Hello World" onClick={handleClick} />, | ||
); | ||
userEvent.click(container.firstChild as TargetElement); | ||
expect(handleClick).toBeCalled(); | ||
}); | ||
}); |
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 +1,2 @@ | ||
export { BasicButton } from './BasicButton'; | ||
export { CancelButton } from './CancelButton'; |
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,25 @@ | ||
import { makeStyles, Theme } from '@material-ui/core'; | ||
|
||
export const useStyles = makeStyles( | ||
(theme: Theme) => ({ | ||
cancelButton: { | ||
flex: '0 1 300px', | ||
backgroundColor: theme.palette.info.light, | ||
'& .MuiButton-label': { | ||
color: theme.palette.common.white, | ||
fontWeight: 700, | ||
fontSize: '18px', | ||
}, | ||
'&:hover': { | ||
backgroundColor: theme.palette.info.main, | ||
}, | ||
[theme.breakpoints.down('sm')]: { | ||
flex: '0 1 auto', | ||
'& .MuiButton-label': { | ||
fontSize: '15px', | ||
}, | ||
}, | ||
}, | ||
}), | ||
{ name: 'CancelButton' }, | ||
); |
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,15 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import { fetchChangeLog } from 'old/lib/utilities/API/api'; | ||
import { IChangeLogOptions } from './types'; | ||
|
||
export const getChangeLog = createAsyncThunk( | ||
'getChangeLogActions', | ||
async (options: IChangeLogOptions, { rejectWithValue }) => { | ||
try { | ||
const { data } = await fetchChangeLog(options); | ||
return data; | ||
} catch (error) { | ||
return rejectWithValue(error); | ||
} | ||
}, | ||
); |
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,3 @@ | ||
/* eslint-disable import/no-cycle */ | ||
export { changeLogReducer, setChangesSize } from './reducer'; | ||
export { selectSize } from './selectors'; |
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,32 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { getAsyncActionsReducer } from 'models/helpers/asyncActions'; | ||
import { ChangeLogType } from 'old/lib/utilities/API/types'; | ||
import { getChangeLog } from './asyncAction'; | ||
|
||
const initialState: ChangeLogType = { | ||
size: 0, | ||
content: [], | ||
}; | ||
|
||
const changeLog = createSlice({ | ||
name: 'changesLog', | ||
initialState, | ||
reducers: { | ||
setChangesSize: (state, action: PayloadAction<number>) => { | ||
const setChangeObj = state; | ||
setChangeObj.size = action.payload; | ||
}, | ||
setPage: (state, action: PayloadAction<number>) => { | ||
const setPageObj = state; | ||
setPageObj.totalElements = action.payload; | ||
}, | ||
}, | ||
extraReducers: { | ||
...getAsyncActionsReducer(getChangeLog as any), | ||
}, | ||
}); | ||
|
||
const { setChangesSize, setPage } = changeLog.actions; | ||
|
||
const changeLogReducer = changeLog.reducer; | ||
export { setChangesSize, setPage, changeLogReducer }; |
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,9 @@ | ||
import { RootStateType } from 'models/rootReducer'; | ||
|
||
export const selectSize = (state: RootStateType): number | undefined => { | ||
return state.changesLog.size; | ||
}; | ||
|
||
export const selectTotalPages = (state: RootStateType): number | undefined => { | ||
return state.changesLog.totalPages; | ||
}; |
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,7 @@ | ||
export interface IChangeLogOptions { | ||
size?: number; | ||
page?: number; | ||
totalElements?: number; | ||
totalPages?: number; | ||
pageNumber?: number; | ||
} |
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
Oops, something went wrong.