-
Notifications
You must be signed in to change notification settings - Fork 358
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
test: Unit test coverage - HostNameTableCell #10596
Merged
cpathipa
merged 7 commits into
linode:develop
from
cpathipa:test-coverage-HostNameTableCell
Jun 20, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8c21c6
test coverage - HostNameTableCell
cpathipa 5d35513
Added changeset: Unit test coverage - HostNameTableCell
cpathipa 93bcfde
PR - feedback - @bnussman @jaalah-akamai
cpathipa 07f95fd
Update packages/manager/src/features/ObjectStorage/AccessKeyLanding/Aβ¦
cpathipa 26a539c
PR - feedback - @abailly-akamai
cpathipa 48447e4
code cleanup
cpathipa b6ef258
Update packages/manager/src/features/ObjectStorage/AccessKeyLanding/Aβ¦
cpathipa 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
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,5 @@ | ||
--- | ||
"@linode/manager": Tests | ||
--- | ||
|
||
Unit test coverage - HostNameTableCell ([#10596](https://github.com/linode/manager/pull/10596)) |
103 changes: 103 additions & 0 deletions
103
...ger/src/features/ObjectStorage/AccessKeyLanding/AccessKeyTable/HostNameTableCell.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,103 @@ | ||
import '@testing-library/jest-dom'; | ||
import { waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { objectStorageKeyFactory, regionFactory } from 'src/factories'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { HostNameTableCell } from './HostNameTableCell'; | ||
|
||
const storageKeyData = objectStorageKeyFactory.build({ | ||
regions: [ | ||
{ | ||
id: 'us-east', | ||
s3_endpoint: 'alpha.test.com', | ||
}, | ||
], | ||
}); | ||
|
||
describe('HostNameTableCell', () => { | ||
it('should render "None" when there are no regions', () => { | ||
const { getByText } = renderWithTheme( | ||
<HostNameTableCell | ||
storageKeyData={{ | ||
access_key: 'test_key', | ||
bucket_access: null, | ||
id: 0, | ||
label: 'test', | ||
limited: false, | ||
regions: [], | ||
secret_key: '', | ||
}} | ||
setHostNames={vi.fn()} | ||
setShowHostNamesDrawers={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(getByText('None')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render "Regions/S3 Hostnames" cell when there are regions', async () => { | ||
const region = regionFactory.build({ | ||
capabilities: ['Object Storage'], | ||
id: 'us-east', | ||
label: 'Newark, NJ', | ||
}); | ||
|
||
server.use( | ||
http.get('*/v4/regions', () => { | ||
return HttpResponse.json(makeResourcePage([region])); | ||
}) | ||
); | ||
const { findByText } = renderWithTheme( | ||
<HostNameTableCell | ||
setHostNames={vi.fn()} | ||
setShowHostNamesDrawers={vi.fn()} | ||
storageKeyData={storageKeyData} | ||
/> | ||
); | ||
|
||
const hostname = await findByText('Newark, NJ: alpha.test.com'); | ||
|
||
await waitFor(() => expect(hostname).toBeInTheDocument()); | ||
}); | ||
test('should render all "Regions/S3 Hostnames" in the cell when there are multiple regions', async () => { | ||
const region = regionFactory.build({ | ||
capabilities: ['Object Storage'], | ||
id: 'us-east', | ||
label: 'Newark, NJ', | ||
}); | ||
|
||
server.use( | ||
http.get('*/v4/regions', () => { | ||
return HttpResponse.json(makeResourcePage([region])); | ||
}) | ||
); | ||
const { findByText } = renderWithTheme( | ||
<HostNameTableCell | ||
storageKeyData={{ | ||
...storageKeyData, | ||
regions: [ | ||
{ | ||
id: 'us-east', | ||
s3_endpoint: 'alpha.test.com', | ||
}, | ||
{ | ||
id: 'us-south', | ||
s3_endpoint: 'alpha.test.com', | ||
}, | ||
], | ||
}} | ||
setHostNames={vi.fn()} | ||
setShowHostNamesDrawers={vi.fn()} | ||
/> | ||
); | ||
const hostname = await findByText('Newark, NJ: alpha.test.com'); | ||
const moreButton = await findByText(/and\s+1\s+more\.\.\./); | ||
await waitFor(() => expect(hostname).toBeInTheDocument()); | ||
|
||
await expect(moreButton).toBeInTheDocument(); | ||
}); | ||
}); |
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.
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.
nit: you could use the factory here as well.