-
Notifications
You must be signed in to change notification settings - Fork 365
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
fix: [M3-6540] - Surface general errors in the Object Storage Bucket Create Drawer #9067
Merged
bnussman-akamai
merged 5 commits into
linode:develop
from
bnussman-akamai:M3-6540-surface-general-object-storage-errors-create-drawer
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
packages/manager/src/features/ObjectStorage/BucketLanding/CreateBucketDrawer.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,81 @@ | ||
import * as React from 'react'; | ||
import { CreateBucketDrawer } from './CreateBucketDrawer'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { rest, server } from 'src/mocks/testServer'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { | ||
accountSettingsFactory, | ||
objectStorageClusterFactory, | ||
regionFactory, | ||
} from 'src/factories'; | ||
|
||
const props = { | ||
isOpen: true, | ||
onClose: jest.fn(), | ||
}; | ||
|
||
jest.mock('src/components/EnhancedSelect/Select'); | ||
|
||
describe('CreateBucketDrawer', () => { | ||
it('Should show a general error notice if the API returns one', async () => { | ||
server.use( | ||
rest.post('*/object-storage/buckets', (req, res, ctx) => { | ||
return res( | ||
ctx.status(500), | ||
ctx.json({ errors: [{ reason: 'Object Storage is offline!' }] }) | ||
); | ||
}), | ||
rest.get('*/regions', async (req, res, ctx) => { | ||
return res( | ||
ctx.json( | ||
makeResourcePage( | ||
regionFactory.buildList(1, { id: 'us-east', label: 'Newark, NJ' }) | ||
) | ||
) | ||
); | ||
}), | ||
rest.get('*object-storage/clusters', (req, res, ctx) => { | ||
return res( | ||
ctx.json( | ||
makeResourcePage( | ||
objectStorageClusterFactory.buildList(1, { | ||
region: 'us-east', | ||
id: 'us-east-1', | ||
}) | ||
) | ||
) | ||
); | ||
}), | ||
rest.get('*/account/settings', (req, res, ctx) => { | ||
return res( | ||
ctx.json(accountSettingsFactory.build({ object_storage: 'active' })) | ||
); | ||
}) | ||
); | ||
|
||
const { | ||
getByTestId, | ||
getByLabelText, | ||
getByPlaceholderText, | ||
findByText, | ||
} = renderWithTheme(<CreateBucketDrawer {...props} />); | ||
|
||
userEvent.type(getByLabelText('Label'), 'my-test-bucket'); | ||
|
||
// We must waitFor because we need to load region and cluster data from the API | ||
await waitFor(() => | ||
userEvent.selectOptions( | ||
getByPlaceholderText('Select a Region'), | ||
'Newark, NJ (us-east-1)' | ||
) | ||
); | ||
|
||
const saveButton = getByTestId('create-bucket-button'); | ||
|
||
userEvent.click(saveButton); | ||
|
||
await findByText('Object Storage is offline!'); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't those be wrapped in an
act()
?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.
When I wrap
userEvent.type(getByLabelText('Label'), 'my-test-bucket');
in anact
, the underlying input does not update properlyThere 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.
something's odd - lemme try locally
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.
This is where I'm stuck. Something about the mock error isn't correct but I don't know what it is.
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.
am not getting that error by doing something like this:
but it does not find the element. am confused as to what's going on here
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.
nevermind this is erroneous code ^
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.
yeah, I've never seen anything like this. Feels like an Axios interceptor issue or something
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.
Okay, yeah. Seems like the
error
is an actualError
, not in theAPIError
shape like we'd expect. This is probably caused by the Axios interceptors not being applied to transform the error to the expected shape. I don't know if this is a new problem or an existing one.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.
Got it fixed in 18edd23. Axios interceptors were not setup...
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.
ah thanks, nice fix - strange that this is the only test relying on those