forked from linode/manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test coverage for HostNameTableCell
- Loading branch information
Showing
2 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...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,115 @@ | ||
import '@testing-library/jest-dom'; | ||
import { waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { regionFactory } from 'src/factories'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers'; | ||
|
||
import { HostNameTableCell } from './HostNameTableCell'; | ||
|
||
const storageKeyData = { | ||
access_key: 'test_key', | ||
bucket_access: null, | ||
id: 12345, | ||
label: 'this is regular key', | ||
limited: false, | ||
regions: [ | ||
{ | ||
id: 'us-east', | ||
s3_endpoint: 'alpha.test.com', | ||
}, | ||
], | ||
secret_key: '[test]', | ||
}; | ||
|
||
describe('HostNameTableCell', () => { | ||
it('should render "None" when there are no regions', () => { | ||
const { getByText } = renderWithThemeAndHookFormContext({ | ||
component: ( | ||
<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 } = renderWithThemeAndHookFormContext({ | ||
component: ( | ||
<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 } = renderWithThemeAndHookFormContext({ | ||
component: ( | ||
<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