-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82c7ad5
commit 27545fc
Showing
10 changed files
with
267 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const SAMPLE_FLAGS = [ | ||
{ | ||
id: '053d9c35-182e-41d8-9f1f-2f5b443d0fbd', | ||
name: 'Inappropriate Content', | ||
}, | ||
{ | ||
id: '69f652a7-9c04-4346-b963-004e63c478b9', | ||
name: 'Hate speech', | ||
}, | ||
{ | ||
id: 'a1ebd159-416a-404b-b893-02a7064454db', | ||
name: 'Fraud / Plagiarism', | ||
}, | ||
{ | ||
id: '7463afaa-a74e-4a5c-810c-44f9642c87c5', | ||
name: 'Spam', | ||
}, | ||
{ | ||
id: 'ca6d1841-fabc-4444-b86e-b76af41263c1', | ||
name: 'Targeted Harrasment', | ||
}, | ||
{ | ||
id: '9baecb0e-3dc3-4191-bbf7-2a89d304600b', | ||
name: 'False Information', | ||
}, | ||
]; |
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,63 @@ | ||
import { SAMPLE_ITEMS } from '../../../fixtures/items'; | ||
import { HOME_PATH } from '../../../../src/config/paths'; | ||
import { | ||
buildFlagListItemId, | ||
buildItemMenu, | ||
buildItemsTableRowId, | ||
FLAG_ITEM_BUTTON_ID, | ||
ITEM_MENU_BUTTON_CLASS, | ||
ITEM_MENU_FLAG_BUTTON_CLASS, | ||
} from '../../../../src/config/selectors'; | ||
import { SAMPLE_FLAGS } from '../../../fixtures/flags'; | ||
|
||
const openFlagItemModal = (itemId) => { | ||
const menuSelector = `#${buildItemsTableRowId( | ||
itemId, | ||
)} .${ITEM_MENU_BUTTON_CLASS}`; | ||
|
||
cy.get(menuSelector).click(); | ||
|
||
const menuFlagButton = cy.get( | ||
`#${buildItemMenu(itemId)} .${ITEM_MENU_FLAG_BUTTON_CLASS}`, | ||
); | ||
|
||
menuFlagButton.click(); | ||
}; | ||
|
||
const flagItem = (itemId, flagId) => { | ||
openFlagItemModal(itemId); | ||
|
||
const flagListItem = cy.get(`#${buildFlagListItemId(flagId)}`); | ||
|
||
flagListItem.click(); | ||
|
||
const flagItemButton = cy.get(`#${FLAG_ITEM_BUTTON_ID}`); | ||
|
||
flagItemButton.click(); | ||
}; | ||
|
||
describe('Flag Item', () => { | ||
beforeEach(() => { | ||
cy.setUpApi(SAMPLE_ITEMS); | ||
cy.visit(HOME_PATH); | ||
}); | ||
|
||
it('flag item', () => { | ||
const item = SAMPLE_ITEMS.items[0]; | ||
const flag = SAMPLE_FLAGS[0]; | ||
|
||
flagItem(item.id, flag.id); | ||
|
||
cy.wait('@postItemFlag').then( | ||
({ | ||
request: { | ||
url, | ||
body: { flagId }, | ||
}, | ||
}) => { | ||
expect(flagId).to.equal(flag.id); | ||
expect(url).to.contain(item.id); | ||
}, | ||
); | ||
}); | ||
}); |
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,115 @@ | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { MUTATION_KEYS } from '@graasp/query-client'; | ||
import PropTypes from 'prop-types'; | ||
import DialogTitle from '@material-ui/core/DialogTitle'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogActions from '@material-ui/core/DialogActions'; | ||
import Button from '@material-ui/core/Button'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import List from '@material-ui/core/List'; | ||
import { ListItem, ListItemText, makeStyles } from '@material-ui/core'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { useMutation, hooks } from '../../config/queryClient'; | ||
import { | ||
buildFlagListItemId, | ||
FLAG_ITEM_BUTTON_ID, | ||
} from '../../config/selectors'; | ||
|
||
const { useFlags } = hooks; | ||
|
||
const FlagItemModalContext = React.createContext(); | ||
|
||
const useStyles = makeStyles(() => ({ | ||
list: { | ||
width: '100%', | ||
overflow: 'auto', | ||
maxHeight: 250, | ||
}, | ||
listTitle: { | ||
fontSize: 'small', | ||
}, | ||
flagItemButton: { | ||
color: 'red', | ||
}, | ||
})); | ||
|
||
const FlagItemModalProvider = ({ children }) => { | ||
const { t } = useTranslation(); | ||
const classes = useStyles(); | ||
const { mutate: postFlagItem } = useMutation(MUTATION_KEYS.POST_ITEM_FLAG); | ||
const [open, setOpen] = useState(false); | ||
const [selectedFlag, setSelectedFlag] = useState(false); | ||
const [itemId, setItemId] = useState(false); | ||
|
||
const { data: flags } = useFlags(); | ||
|
||
const openModal = (newItemId) => { | ||
setOpen(true); | ||
setItemId(newItemId); | ||
}; | ||
|
||
const onClose = () => { | ||
setOpen(false); | ||
setItemId(null); | ||
}; | ||
|
||
const handleSelect = (flag) => () => setSelectedFlag(flag); | ||
|
||
const onFlag = () => { | ||
postFlagItem({ | ||
flagId: selectedFlag.id, | ||
itemId, | ||
}); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<FlagItemModalContext.Provider value={{ openModal }}> | ||
<Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth> | ||
<DialogTitle>{t('Flag Item')}</DialogTitle> | ||
<DialogContent> | ||
<Typography variant="h6" className={classes.listTitle}> | ||
{`${t('Select reason for flagging this item')}:`} | ||
</Typography> | ||
<List component="nav" className={classes.list}> | ||
{flags?.map((flag) => ( | ||
<ListItem | ||
id={buildFlagListItemId(flag.id)} | ||
button | ||
selected={selectedFlag.id === flag.id} | ||
onClick={handleSelect(flag)} | ||
> | ||
<ListItemText primary={flag.name} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose} color="primary"> | ||
{t('Cancel')} | ||
</Button> | ||
<Button | ||
onClick={onFlag} | ||
className={classes.flagItemButton} | ||
id={FLAG_ITEM_BUTTON_ID} | ||
disabled={!selectedFlag} | ||
> | ||
{t('Flag')} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
{children} | ||
</FlagItemModalContext.Provider> | ||
); | ||
}; | ||
|
||
FlagItemModalProvider.propTypes = { | ||
children: PropTypes.node, | ||
}; | ||
|
||
FlagItemModalProvider.defaultProps = { | ||
children: null, | ||
}; | ||
|
||
export { FlagItemModalProvider, FlagItemModalContext }; |
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