-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [web] export awsoidc integration UI state and components (#…
…47170) * refactor: export awsoidc integration UI state and components * awsoidc ui test, copy edit and move requiredMatchingRoleNameAndRoleArn to rules.ts * update ShowConfigurationScript copy to explain what the command does * abstract validAwsIAMRoleName and export it
- Loading branch information
1 parent
de6d19b
commit bc2cb80
Showing
9 changed files
with
631 additions
and
174 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
98 changes: 98 additions & 0 deletions
98
web/packages/teleport/src/Integrations/Enroll/AwsOidc/AwsOidc.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,98 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { | ||
fireEvent, | ||
render, | ||
screen, | ||
userEvent, | ||
waitFor, | ||
} from 'design/utils/testing'; | ||
import { MemoryRouter } from 'react-router'; | ||
|
||
import { userEventService } from 'teleport/services/userEvent'; | ||
|
||
import { AwsOidc } from './AwsOidc'; | ||
|
||
test('render', async () => { | ||
jest | ||
.spyOn(userEventService, 'captureIntegrationEnrollEvent') | ||
.mockImplementation(); | ||
render( | ||
<MemoryRouter> | ||
<AwsOidc /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getByText(/Set up your AWS account/i)).toBeInTheDocument(); | ||
expect( | ||
screen.getByLabelText(/Give this AWS integration a name/i) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByLabelText( | ||
/Give a name for an AWS IAM role this integration will create/i | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test('generate command', async () => { | ||
const user = userEvent.setup({ delay: null }); | ||
jest | ||
.spyOn(userEventService, 'captureIntegrationEnrollEvent') | ||
.mockImplementation(); | ||
|
||
window.prompt = jest.fn(); | ||
|
||
render( | ||
<MemoryRouter> | ||
<AwsOidc /> | ||
</MemoryRouter> | ||
); | ||
|
||
const pluginConfig = { | ||
name: 'integration-name', | ||
roleName: 'integration-role-name', | ||
}; | ||
|
||
expect(screen.getByText(/Set up your AWS account/i)).toBeInTheDocument(); | ||
fireEvent.change(screen.getByLabelText(/Give this AWS integration a name/i), { | ||
target: { value: pluginConfig.name }, | ||
}); | ||
fireEvent.change( | ||
screen.getByLabelText( | ||
/Give a name for an AWS IAM role this integration will create/i | ||
), | ||
{ | ||
target: { value: pluginConfig.roleName }, | ||
} | ||
); | ||
|
||
fireEvent.click(screen.getByRole('button', { name: /Generate Command/i })); | ||
|
||
const commandBoxEl = screen.getByText(/AWS CloudShell/i, { exact: false }); | ||
await waitFor(() => { | ||
expect(commandBoxEl).toBeInTheDocument(); | ||
}); | ||
|
||
// the first element found shows AWS tags added by OIDC integraiton. | ||
// second element is the command copy box. | ||
await user.click(screen.getAllByTestId('btn-copy')[1]); | ||
const clipboardText = await navigator.clipboard.readText(); | ||
expect(clipboardText).toContain(`integrationName=${pluginConfig.name}`); | ||
expect(clipboardText).toContain(`role=${pluginConfig.roleName}`); | ||
}); |
Oops, something went wrong.