Skip to content

Commit

Permalink
chore: use react-router new routing approach RouterProvider (#3761)
Browse files Browse the repository at this point in the history
* chore: use react-router new routing approach RouterProvider
* fix: confirmation on leaving the page
  • Loading branch information
mariojsnunes committed Jul 12, 2024
1 parent d5baf3c commit cc1fdd0
Show file tree
Hide file tree
Showing 66 changed files with 302 additions and 340 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/BlockedRoute/BlockedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const BlockedRoute = (props: BlockedRouteProps) => {
<Text sx={{ width: '100%', textAlign: 'center' }}>{props.children}</Text>
<Box sx={{ textAlign: 'center', mt: 2 }}>
<InternalLink to={redirectUrl}>
<Button variant={'subtle'} small>
<Button type="button" variant="subtle" small>
{redirectLabel}
</Button>
</InternalLink>
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/Breadcrumbs/BreadcrumbsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ interface BreadcrumbItemProps {
const BreadcrumbButton = ({ text, link }: BreadcrumbButtonProps) => {
return link ? (
<Link to={link}>
<Button variant="breadcrumb">{text}</Button>
<Button type="button" variant="breadcrumb">
{text}
</Button>
</Link>
) : (
<Button variant="breadcrumb">{text}</Button>
<Button type="button" variant="breadcrumb">
{text}
</Button>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const ButtonShowReplies = (props: Props) => {

return (
<Button
data-cy={`show-replies`}
type="button"
data-cy="show-replies"
icon={icon}
onClick={setIsShowReplies}
sx={{ alignSelf: 'flex-start', border: 'none' }}
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/CommentItem/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const CommentItem = (props: IProps) => {
}}
>
<Button
type="button"
data-cy={`${item}: edit button`}
variant="outline"
small={true}
Expand All @@ -169,6 +170,7 @@ export const CommentItem = (props: IProps) => {
edit
</Button>
<Button
type="button"
data-cy={`${item}: delete button`}
variant={'outline'}
small={true}
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/CommentList/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ export const CommentList = (props: IPropsCommentList) => {
{comments && comments.length > shownComments && (
<Flex>
<Button
sx={{
margin: '0 auto',
}}
type="button"
sx={{ margin: '0 auto' }}
variant="outline"
onClick={handleMoreComments}
>
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/ConfirmModal/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ export const ConfirmModal = (props: Props) => {
<Text>{message}</Text>
<Flex p={2} mx={-1} sx={{ justifyContent: 'flex-end' }}>
<Flex px={1}>
<Button variant={'outline'} onClick={() => props?.handleCancel()}>
<Button
type="button"
variant="outline"
data-cy="Confirm.modal: Cancel"
onClick={() => props?.handleCancel()}
>
Cancel
</Button>
</Flex>
<Flex px={1}>
<Button
type="button"
aria-label={`Confirm ${confirmButtonText} action`}
data-cy="Confirm.modal: Confirm"
variant={'outline'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const ContentStatistics = (props: IProps) => {
{showStats ? '' : 'More Information'}
</Text>
<Button
variant={'subtle'}
type="button"
variant="subtle"
showIconOnly={true}
icon={showStats ? 'chevron-up' : 'chevron-down'}
small={true}
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/EditComment/EditComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const EditComment = (props: IProps) => {
/>
<Flex mt={4} ml="auto">
<Button
type="button"
small
mr={4}
variant="secondary"
Expand All @@ -89,7 +90,7 @@ export const EditComment = (props: IProps) => {
<Button
data-cy="edit-comment-submit"
data-testid="edit-comment-submit"
type={'submit'}
type="submit"
aria-label="Save changes"
small
disabled={disabled}
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/FollowButton/FollowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const FollowButton = (props: IProps) => {
return (
<>
<Button
type="button"
data-testid={isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-cy={isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-tip={isLoggedIn ? '' : 'Login to follow'}
Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/ImageCrop/ImageCrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ export const ImageCrop = (props: Props) => {
</Flex>

<Box sx={{ padding }}>
<Button onClick={onDownloadCropClick} disabled={isLoading}>
<Button
type="button"
onClick={onDownloadCropClick}
disabled={isLoading}
>
{callbackLabel}
</Button>
</Box>
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/MapWithPin/MapWithPin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const MapWithPin = (props: Props) => {
/>
{hasUserLocation && (
<Button
type="button"
mx={2}
onClick={(evt) => {
evt.preventDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const NotificationList = (props: Props) => {
<NotificationItem key={idx} {...(notification as any)} />
))}
<Button
style={{
type="button"
sx={{
width: '100%',
textAlign: 'center',
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const ResearchEditorOverview = (props: ResearchEditorOverviewProps) => {
</Box>
) : null}
{showCreateUpdateButton ? (
<Button small sx={{ mr: 2 }} data-cy="create-update">
<Button small sx={{ mr: 2 }} data-cy="create-update" type="button">
<InternalLink
to={`/research/${researchSlug}/new-update`}
sx={{ color: 'black' }}
Expand All @@ -101,7 +101,7 @@ export const ResearchEditorOverview = (props: ResearchEditorOverviewProps) => {
) : null}

{showBackToResearchButton ? (
<Button small variant={'outline'}>
<Button small variant="outline" type="button">
<InternalLink
to={`/research/${researchSlug}/edit`}
sx={{ color: 'black' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`ResearchEditorOverview > handles empty updates 1`] = `
<button
class="css-fdla8g-Button"
data-cy="create-update"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand All @@ -27,6 +28,7 @@ exports[`ResearchEditorOverview > handles empty updates 1`] = `
</button>
<button
class="css-l7psd3-Button"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand Down Expand Up @@ -56,6 +58,7 @@ exports[`ResearchEditorOverview > handles falsey updates 1`] = `
<button
class="css-fdla8g-Button"
data-cy="create-update"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand All @@ -70,6 +73,7 @@ exports[`ResearchEditorOverview > handles falsey updates 1`] = `
</button>
<button
class="css-l7psd3-Button"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand Down Expand Up @@ -144,6 +148,7 @@ exports[`ResearchEditorOverview > renders correctly 1`] = `
<button
class="css-fdla8g-Button"
data-cy="create-update"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand All @@ -158,6 +163,7 @@ exports[`ResearchEditorOverview > renders correctly 1`] = `
</button>
<button
class="css-l7psd3-Button"
type="button"
>
<span
class="css-a6mlbr-Text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const UsefulStatsButton = (props: IProps) => {
return (
<>
<Button
type="button"
data-tip={props.isLoggedIn ? '' : 'Login to add your vote'}
data-cy={props.isLoggedIn ? 'vote-useful' : 'vote-useful-redirect'}
onClick={() =>
Expand Down
19 changes: 3 additions & 16 deletions packages/cypress/src/integration/howto/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ describe('[How To]', () => {
})

it('[Warning on leaving page]', () => {
const stub = cy.stub()
stub.returns(false)
cy.on('window:confirm', stub)

cy.login(creatorEmail, creatorPassword)
cy.get('[data-cy=loader]').should('not.exist')
cy.step('Access the create-how-to')
Expand All @@ -348,22 +344,13 @@ describe('[How To]', () => {
.clear()
.type(expected.title)
.blur({ force: true })
cy.get('[data-cy=page-link][href*="/how-to"]')
.click()
.then(() => {
expect(stub.callCount).to.equal(1)
stub.resetHistory()
})
cy.get('[data-cy=page-link][href*="/how-to"]').click()
cy.get('[data-cy="Confirm.modal: Cancel"]').click()
cy.url().should('match', /\/how-to\/create$/)

cy.step('Clear title input')
cy.get('[data-cy=intro-title]').clear().blur({ force: true })
cy.get('[data-cy=page-link][href*="/how-to"]')
.click()
.then(() => {
expect(stub.callCount).to.equal(0)
stub.resetHistory()
})
cy.get('[data-cy=page-link][href*="/how-to"]').click()
cy.url().should('match', /\/how-to?/)
})
})
Expand Down
21 changes: 4 additions & 17 deletions packages/cypress/src/integration/research/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('[Research]', () => {
There is an issue with cypress that can not type some of the start string failing the test
https://github.com/cypress-io/cypress/issues/3817
*/
cy.wait(500)
cy.wait(1000)
cy.get('[data-cy=intro-description]').type(expected.description).blur()

cy.step('New collaborators can be assigned to research')
Expand Down Expand Up @@ -228,10 +228,6 @@ describe('[Research]', () => {
})

it('[Warning on leaving page]', () => {
const stub = cy.stub()
stub.returns(false)
cy.on('window:confirm', stub)

cy.login(researcherEmail, researcherPassword)
cy.step('Access the create research article')
cy.get('[data-cy=loader]').should('not.exist')
Expand All @@ -241,22 +237,13 @@ describe('[Research]', () => {
.clear()
.type('Create research article test')
.blur({ force: true })
cy.get('[data-cy=page-link][href*="/research"]')
.click()
.then(() => {
expect(stub.callCount).to.equal(1)
stub.resetHistory()
})
cy.get('[data-cy=page-link][href*="/research"]').click()
cy.get('[data-cy="Confirm.modal: Cancel"]').click()

cy.url().should('match', /\/research\/create$/)

cy.step('Clear title input')
cy.get('[data-cy=intro-title').clear().blur({ force: true })
cy.get('[data-cy=page-link][href*="/research"]')
.click()
.then(() => {
expect(stub.callCount).to.equal(0)
stub.resetHistory()
})
cy.url().should('match', /\/research?/)
})
})
Expand Down
15 changes: 5 additions & 10 deletions packages/cypress/src/integration/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('[Settings]', () => {
})

describe('[Focus Member]', () => {
it('[Cancel edit profile and get confirmation]', (done) => {
it('[Cancel edit profile and get confirmation]', () => {
cy.signUpNewUser()

cy.step('Go to User Settings')
Expand All @@ -41,12 +41,7 @@ describe('[Settings]', () => {

cy.step('Confirm shown when attempting to go to another page')
cy.get('[data-cy=page-link]').contains('How-to').click()
cy.on('window:confirm', (text) => {
expect(text).to.eq(
'You are leaving this page without saving. Do you want to continue ?',
)
done()
})
cy.get('[data-cy="Confirm.modal: Modal"]').should('be.visible')
})

it('[Edit a new profile]', () => {
Expand Down Expand Up @@ -349,8 +344,8 @@ describe('[Settings]', () => {
openTimes.forEach((openTime) => {
cy.setSettingAddOpeningTime(openTime)
})
cy.setSettingDeleteOpeningTime(0, false)
cy.setSettingDeleteOpeningTime(1, true)
cy.setSettingDeleteOpeningTime(1, false)
cy.setSettingDeleteOpeningTime(2, true)

cy.get(`[data-cy=plastic-${plasticTypes[0]}]`).click()
cy.get(`[data-cy=plastic-${plasticTypes[1]}]`).click()
Expand All @@ -374,7 +369,7 @@ describe('[Settings]', () => {
`${openTimes[0].day}: ${openTimes[0].from} - ${openTimes[0].to}`,
)
cy.contains(
`${openTimes[2].day}: ${openTimes[2].from} - ${openTimes[2].to}`,
`${openTimes[1].day}: ${openTimes[1].from} - ${openTimes[1].to}`,
)
cy.contains(
`${openTimes[3].day}: ${openTimes[3].from} - ${openTimes[3].to}`,
Expand Down
9 changes: 3 additions & 6 deletions packages/cypress/src/support/commandsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,8 @@ Cypress.Commands.add(
'selectTag',
(tagName: string, selector = '[data-cy=tag-select]') => {
cy.log('select tag', tagName)
cy.get(`${selector} input`)
.click({ force: true })
.type(tagName, { force: true })
.get(`${selector} .data-cy__menu-list`)
.contains(tagName)
.click()
cy.get(`${selector} input`).click({ force: true })
cy.get(`${selector} input`).type(tagName, { force: true })
cy.get(`${selector} .data-cy__menu-list`).contains(tagName).click()
},
)
4 changes: 3 additions & 1 deletion src/common/Error/handlers/ChunkLoadError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const ChunkLoadErrorHandler = () => {
<Text mb={4} sx={{ fontSize: 3 }}>
The website got some updates
</Text>
<Button onClick={() => attemptReload()}>Load the new site.</Button>
<Button type="button" onClick={() => attemptReload()}>
Load the new site.
</Button>
<Text mt={4} sx={{ fontSize: 0.75 }}>
If it doesn't work you might need to try another browser.
<br></br>Or send us a{' '}
Expand Down
1 change: 1 addition & 0 deletions src/common/Form/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const FileInput = (props: IProps) => {
{showFileList ? (
<>
<Button
type="button"
onClick={() => toggleModal()}
icon="upload"
variant="outline"
Expand Down
1 change: 1 addition & 0 deletions src/common/Form/ImageInput/DeleteImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const DeleteImage = ({ onClick }: IProps) => {
small
variant="secondary"
icon="delete"
type="button"
onClick={(event) => onClick(event)}
>
Delete
Expand Down
Loading

0 comments on commit cc1fdd0

Please sign in to comment.