-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve error and loading handling (#1869)
- Loading branch information
Showing
88 changed files
with
498 additions
and
549 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type Config = { | ||
endpoint: string; | ||
method?: string; | ||
statusCode: number; | ||
body?: any; | ||
}; | ||
|
||
export function simulateError({ method, endpoint, statusCode, body }: Config) { | ||
cy.intercept( | ||
{ | ||
method: method, | ||
url: `*${endpoint}*`, | ||
}, | ||
{ statusCode, body } | ||
); | ||
} | ||
|
||
export function tryCreateProject(name: string) { | ||
cy.gcy('project-name-field').type('Test'); | ||
cy.gcy('global-form-save-button').click(); | ||
} |
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,59 @@ | ||
import { HOST } from '../../common/constants'; | ||
import 'cypress-file-upload'; | ||
import { projectTestData } from '../../common/apiCalls/testData/testData'; | ||
import { login } from '../../common/apiCalls/common'; | ||
import { assertMessage } from '../../common/shared'; | ||
import { simulateError } from '../../common/errorHandling'; | ||
|
||
describe('Error handling', () => { | ||
beforeEach(() => { | ||
projectTestData.clean(); | ||
projectTestData.generate(); | ||
login('cukrberg@facebook.com', 'admin'); | ||
}); | ||
|
||
it('Handles not found error', () => { | ||
simulateError({ | ||
method: 'get', | ||
endpoint: 'projects-with-stats', | ||
statusCode: 404, | ||
}); | ||
cy.visit(`${HOST}`); | ||
assertMessage('Not found'); | ||
}); | ||
|
||
it('Handles permissions error', () => { | ||
simulateError({ | ||
method: 'get', | ||
endpoint: 'projects-with-stats', | ||
statusCode: 403, | ||
}); | ||
cy.visit(`${HOST}`); | ||
assertMessage('Your permissions are not sufficient for this operation.'); | ||
}); | ||
|
||
it('Handles 404 by redirect', () => { | ||
simulateError({ | ||
method: 'get', | ||
endpoint: 'facebook', | ||
statusCode: 404, | ||
}); | ||
cy.visit(`${HOST}/organizations/facebook/profile`); | ||
assertMessage('Not found'); | ||
cy.url().should('include', '/projects'); | ||
}); | ||
|
||
it('Handles 401 by logout', () => { | ||
simulateError({ | ||
method: 'get', | ||
endpoint: 'facebook', | ||
statusCode: 401, | ||
}); | ||
cy.visit(`${HOST}/organizations/facebook/profile`); | ||
cy.url().should('include', '/login'); | ||
}); | ||
|
||
after(() => { | ||
projectTestData.clean(); | ||
}); | ||
}); |
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,55 @@ | ||
import { HOST } from '../../common/constants'; | ||
import 'cypress-file-upload'; | ||
import { projectTestData } from '../../common/apiCalls/testData/testData'; | ||
import { login } from '../../common/apiCalls/common'; | ||
import { assertMessage } from '../../common/shared'; | ||
import { simulateError, tryCreateProject } from '../../common/errorHandling'; | ||
|
||
describe('Error handling', () => { | ||
beforeEach(() => { | ||
projectTestData.clean(); | ||
projectTestData.generate(); | ||
login('cukrberg@facebook.com', 'admin'); | ||
}); | ||
|
||
it('Handles project creation general error', () => { | ||
simulateError({ | ||
method: 'post', | ||
endpoint: 'projects', | ||
statusCode: 400, | ||
body: { | ||
code: 'user_has_no_project_access', | ||
}, | ||
}); | ||
cy.visit(`${HOST}/projects/add`); | ||
tryCreateProject('Test'); | ||
cy.contains('User has no access to the project').should('be.visible'); | ||
}); | ||
|
||
it('Handles project creation 403 error', () => { | ||
simulateError({ | ||
method: 'post', | ||
endpoint: 'projects', | ||
statusCode: 403, | ||
}); | ||
cy.visit(`${HOST}/projects/add`); | ||
tryCreateProject('Test'); | ||
assertMessage('Your permissions are not sufficient for this operation'); | ||
}); | ||
|
||
it('Handles project creation 404 error without redirect', () => { | ||
simulateError({ | ||
method: 'post', | ||
endpoint: 'projects', | ||
statusCode: 404, | ||
}); | ||
cy.visit(`${HOST}/projects/add`); | ||
tryCreateProject('Test'); | ||
assertMessage('Not found'); | ||
cy.url().should('contain', '/projects/add'); | ||
}); | ||
|
||
after(() => { | ||
projectTestData.clean(); | ||
}); | ||
}); |
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,9 @@ | ||
import { CircularProgress as MuiCircularProgress } from '@mui/material'; | ||
import { useLoadingRegister } from './GlobalLoading'; | ||
|
||
type Props = React.ComponentProps<typeof MuiCircularProgress>; | ||
|
||
export const SpinnerProgress = (props: Props) => { | ||
useLoadingRegister(true); | ||
return <MuiCircularProgress {...props} />; | ||
}; |
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
Oops, something went wrong.