This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Teleport Connect: Add dropdown for database name #757
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
989db5a
Add required prop to MenuLogin
ravicious 8ad03cc
Update proto files
ravicious b9717a9
Include targetSubresourceName when creating a gateway
ravicious 63e7054
Set better title for gateway tab
ravicious ff497ab
Fix long document titles breaking connection tracker's UI
ravicious a722557
Merge branch 'master' into ravicious/db-name
ravicious 7232ea8
Sync proto files with updates in teleport repo
ravicious 9144ee1
Extract origins to variables
ravicious 0bcf172
Merge branch 'master' into ravicious/db-name
ravicious 025384b
Pass db name when creating gateway from connection tracker
ravicious 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,47 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, waitFor } from 'design/utils/testing'; | ||
import { MenuLogin } from './MenuLogin'; | ||
|
||
test('does not accept an empty value when required is set to true', async () => { | ||
const onSelect = jest.fn(); | ||
const { findByText, findByPlaceholderText } = render( | ||
<MenuLogin | ||
placeholder="MenuLogin input" | ||
required={true} | ||
getLoginItems={() => []} | ||
onSelect={() => onSelect()} | ||
/> | ||
); | ||
|
||
fireEvent.click(await findByText('CONNECT')); | ||
await waitFor(async () => | ||
fireEvent.keyPress(await findByPlaceholderText('MenuLogin input'), { | ||
key: 'Enter', | ||
keyCode: 13, | ||
}) | ||
); | ||
|
||
expect(onSelect).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
test('accepts an empty value when required is set to false', async () => { | ||
const onSelect = jest.fn(); | ||
const { findByText, findByPlaceholderText } = render( | ||
<MenuLogin | ||
placeholder="MenuLogin input" | ||
required={false} | ||
getLoginItems={() => []} | ||
onSelect={() => onSelect()} | ||
/> | ||
); | ||
|
||
fireEvent.click(await findByText('CONNECT')); | ||
await waitFor(async () => | ||
fireEvent.keyPress(await findByPlaceholderText('MenuLogin input'), { | ||
key: 'Enter', | ||
keyCode: 13, | ||
}) | ||
); | ||
|
||
expect(onSelect).toHaveBeenCalledTimes(1); | ||
}); |
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
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ export function useDatabases() { | |
const dbs = clusterContext.getDbs(); | ||
const syncStatus = clusterContext.getSyncStatus().dbs; | ||
|
||
function connect(dbUri: string, user: string): void { | ||
function connect(dbUri: string, dbUser: string, dbName: string): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When having 2+ params, it's better to convert them to object |
||
const db = appContext.clustersService.findDb(dbUri); | ||
const rootClusterUri = routing.ensureRootClusterUri(db.uri); | ||
const documentsService = | ||
|
@@ -33,9 +33,10 @@ export function useDatabases() { | |
const doc = documentsService.createGatewayDocument({ | ||
// Not passing the `gatewayUri` field here, as at this point the gateway doesn't exist yet. | ||
// `port` is not passed as well, we'll let the tsh daemon pick a random one. | ||
title: db.name, | ||
targetUri: db.uri, | ||
targetUser: user, | ||
targetName: db.name, | ||
targetUser: dbUser, | ||
targetSubresourceName: dbName, | ||
}); | ||
documentsService.add(doc); | ||
documentsService.open(doc.uri); | ||
|
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.
I wasn't sure whether to put
waitFor
onfireEvent
vsexpect().toHaveBeenCalledTimes(0)
.My understanding was that in order to verify that something was not at all,
waitFor
would have to wait until its default timeout runs out. To verify iffireEvent
was called, it only needs to check if the event was fired.Turns out this is not how
waitFor
works at all. If the callback doesn't return a promise,waitFor
just continuously calls the callback until it stops throwing an error or the timeout runs out.Anyway, I guess it's more readable to have expectations without
waitFor
.