-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
End to end testing #711
base: main
Are you sure you want to change the base?
End to end testing #711
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,10 +187,10 @@ const VotePage = () => { | |
if(pages.length == 0){ | ||
return <Container disableGutters={true} maxWidth="sm"><h3>No races created for election</h3></Container> | ||
} | ||
|
||
let pageIsUnderVote = (page) => { | ||
return page.candidates.reduce((prev, c) => prev && (c.score == 0 || c.score == null), true) | ||
} | ||
const isOnLastPage = currentPage === pages.length - 1 | ||
const noScores = pages.every(page => page.candidates.every(candidate => candidate.score === null)) | ||
const thereAreWarnings = pages.some(page => page.warnings) | ||
const submitButtonDisabled = !isOnLastPage || (isPending || noScores || thereAreWarnings) | ||
|
||
return ( | ||
<Container disableGutters={true} maxWidth="sm"> | ||
|
@@ -249,9 +249,11 @@ const VotePage = () => { | |
} | ||
<Button | ||
variant='contained' | ||
onClick={() => (currentPage === pages.length-1)? setIsOpen(true) : setCurrentPageAndScroll(count => count + 1)} | ||
sx={{ maxHeight: '40px', minWidth: '100px', marginLeft: {xs: '10px', md: '40px'}, visibility: 'visible' }}> | ||
{t((currentPage === pages.length-1)? 'ballot.submit_ballot' : 'ballot.next')} | ||
name='submit-ballot' | ||
onClick={() => setIsOpen(true)} | ||
disabled={submitButtonDisabled}//disable unless on last page and at least one candidate scored | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea breaking those out into variables, it's much more readable now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it wasn't behaving how it was supposed to do I had to break it into smaller pieces to make it easier to debug |
||
style={{ margin: "auto", minWidth: "150px", marginTop: "40px" }}> | ||
<Typography variant="h6">{t('ballot.submit_ballot')}</Typography> | ||
</Button> | ||
</Box> | ||
<SupportBlurb/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,27 +307,36 @@ const CandidateDialog = ({ onEditCandidate, candidate, index, onSave, open, hand | |
</Dialog> | ||
) | ||
} | ||
|
||
export const CandidateForm = ({ onEditCandidate, candidate, index, onDeleteCandidate, disabled, inputRef, onKeyDown}) => { | ||
interface CandidateFormProps { | ||
onEditCandidate: (newCandidate: Candidate) => void, | ||
candidate: Candidate, | ||
index: number, | ||
onDeleteCandidate: () => void, | ||
disabled: boolean, | ||
inputRef: (el: React.MutableRefObject<any[]>) => React.MutableRefObject<any[]>, | ||
onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void, | ||
electionState: string | ||
} | ||
export const CandidateForm = ({ onEditCandidate, candidate, index, onDeleteCandidate, disabled, inputRef, onKeyDown, electionState}: CandidateFormProps) => { | ||
|
||
const [open, setOpen] = React.useState(false); | ||
const handleOpen = () => setOpen(true); | ||
const handleClose = () => setOpen(false); | ||
const flags = useFeatureFlags(); | ||
const onSave = () => { handleClose() } | ||
return ( | ||
<Paper elevation={4} sx={{ width: '100%' }}> | ||
<Paper elevation={4} sx={{ width: '100%' }} aria-label={`candidate-form-${index + 1}`}> | ||
<Box | ||
sx={{ display: 'flex', justifyContent: 'space-between', bgcolor: 'background.paper', borderRadius: 10 }} | ||
alignItems={'center'} | ||
> | ||
<DragHandle style={{marginLeft: 5}} disabled={disabled}/> | ||
<DragHandle style={{marginLeft: 5}} disabled={disabled} ariaLabel={`drag-candidate-number-${index + 1}`}/> | ||
|
||
<Box sx={{ overflow: 'hidden', textOverflow: 'ellipsis', width: '100%', pl: 2 }}> | ||
<TextField | ||
id={'candidate-name'} | ||
name="new-candidate-name" | ||
// label={"Candidate Name"} | ||
id={`candidate-name-${index + 1}`} | ||
name={`candidate-name-${index + 1}`} | ||
data-testid={`candidate-name-${index + 1}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like there's several parameters being added in order for the tests to retrieve elements (role, aria-label, name, data-testid, etc). Is there a best practice on which one to use when we're writing tests? It sounds like role and aria-label are things we should be including anyway for making the site screen reader friendly, so I like the idea of tests forcing us to improve the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, if there is or not. I tried to avoid data-testid as much as possible though to use name, role, or label instead so it would be screen reader friendly |
||
type="text" | ||
value={candidate.candidate_name} | ||
fullWidth | ||
|
@@ -336,6 +345,7 @@ export const CandidateForm = ({ onEditCandidate, candidate, index, onDeleteCandi | |
onChange={(e) => onEditCandidate({ ...candidate, candidate_name: e.target.value })} | ||
inputRef={inputRef} | ||
onKeyDown={onKeyDown} | ||
disabled={electionState !== 'draft'} | ||
/> | ||
</Box> | ||
|
||
|
@@ -348,7 +358,8 @@ export const CandidateForm = ({ onEditCandidate, candidate, index, onDeleteCandi | |
</IconButton> | ||
} | ||
<IconButton | ||
aria-label="delete" | ||
aria-label={`delete-candidate-number-${index + 1}`} | ||
name={`delete-${candidate.candidate_name}`} | ||
color="error" | ||
onClick={onDeleteCandidate} | ||
disabled={disabled}> | ||
|
@@ -360,7 +371,7 @@ export const CandidateForm = ({ onEditCandidate, candidate, index, onDeleteCandi | |
) | ||
} | ||
|
||
const AddCandidate = ({ onAddNewCandidate }) => { | ||
const AddCandidate = ({ onAddNewCandidate, index }) => { | ||
|
||
const handleEnter = (e) => { | ||
saveNewCandidate() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that was just from trying to get the name prop to work on the bubbles. I must have forgotten to remove it.