-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add passphrase input to the add SSH key dialog
- Loading branch information
Showing
7 changed files
with
224 additions
and
1 deletion.
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
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
48 changes: 48 additions & 0 deletions
48
...eferences/SshKeys/AddModal/Form/SshPassphrase/__tests__/__snapshots__/index.spec.tsx.snap
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,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SshPassphrase snapshot 1`] = ` | ||
<form | ||
className="pf-c-form" | ||
noValidate={true} | ||
> | ||
<div | ||
className="pf-c-form__group" | ||
> | ||
<div | ||
className="pf-c-form__group-label" | ||
> | ||
<label | ||
className="pf-c-form__label" | ||
htmlFor="ssh-passphrase" | ||
> | ||
<span | ||
className="pf-c-form__label-text" | ||
> | ||
Passphrase | ||
</span> | ||
</label> | ||
</div> | ||
<div | ||
className="pf-c-form__group-control" | ||
> | ||
<input | ||
aria-invalid={false} | ||
aria-label="Passphrase" | ||
className="pf-c-form-control" | ||
data-ouia-component-id="OUIA-Generated-TextInputBase-1" | ||
data-ouia-component-type="PF4/TextInput" | ||
data-ouia-safe={true} | ||
disabled={false} | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onFocus={[Function]} | ||
placeholder="Enter passphrase (optional)" | ||
required={false} | ||
type="text" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
`; |
76 changes: 76 additions & 0 deletions
76
...nd/src/pages/UserPreferences/SshKeys/AddModal/Form/SshPassphrase/__tests__/index.spec.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,76 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import { Form } from '@patternfly/react-core'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { SshPassphrase } from '@/pages/UserPreferences/SshKeys/AddModal/Form/SshPassphrase'; | ||
import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer'; | ||
|
||
const { createSnapshot, renderComponent } = getComponentRenderer(getComponent); | ||
|
||
const mockOnChange = jest.fn(); | ||
|
||
jest.mock('@/components/TextFileUpload'); | ||
|
||
describe('SshPassphrase', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('snapshot', () => { | ||
const snapshot = createSnapshot(); | ||
expect(snapshot.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
describe('text area', () => { | ||
it('should handle SSH passphrase', () => { | ||
renderComponent(); | ||
|
||
expect(mockOnChange).not.toHaveBeenCalled(); | ||
|
||
const input = screen.getByPlaceholderText('Enter passphrase (optional)'); | ||
|
||
const passphrase = 'passphrase'; | ||
userEvent.paste(input, passphrase); | ||
|
||
expect(mockOnChange).toHaveBeenCalledWith(passphrase); | ||
}); | ||
|
||
it('should handle the empty value', () => { | ||
renderComponent(); | ||
|
||
expect(mockOnChange).not.toHaveBeenCalled(); | ||
|
||
const input = screen.getByPlaceholderText('Enter passphrase (optional)'); | ||
|
||
// fill the SSH key data field | ||
userEvent.paste(input, 'ssh-key-data'); | ||
|
||
mockOnChange.mockClear(); | ||
|
||
// clear the SSH key data field | ||
userEvent.clear(input); | ||
|
||
expect(mockOnChange).toHaveBeenCalledWith(''); | ||
}); | ||
}); | ||
}); | ||
|
||
function getComponent(): React.ReactElement { | ||
return ( | ||
<Form> | ||
<SshPassphrase onChange={mockOnChange} /> | ||
</Form> | ||
); | ||
} |
51 changes: 51 additions & 0 deletions
51
...ashboard-frontend/src/pages/UserPreferences/SshKeys/AddModal/Form/SshPassphrase/index.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,51 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import { FormGroup, TextInput } from '@patternfly/react-core'; | ||
import React from 'react'; | ||
|
||
export type Props = { | ||
onChange: (passphrase: string) => void; | ||
}; | ||
|
||
export type State = { | ||
passphrase: string | undefined; | ||
}; | ||
|
||
export class SshPassphrase extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
passphrase: undefined, | ||
}; | ||
} | ||
|
||
private onChange(passphrase: string): void { | ||
const { onChange } = this.props; | ||
|
||
this.setState({ passphrase }); | ||
onChange(passphrase); | ||
} | ||
|
||
public render(): React.ReactElement { | ||
return ( | ||
<FormGroup fieldId="ssh-passphrase" label="Passphrase" isRequired={false}> | ||
<TextInput | ||
aria-label="Passphrase" | ||
placeholder="Enter passphrase (optional)" | ||
onChange={passphrase => this.onChange(passphrase)} | ||
/> | ||
</FormGroup> | ||
); | ||
} | ||
} |
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