-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support static prefix for k8s resource name (#3447)
* support static prefix for k8s resource name * rename isStaticPrefix -> staticPrefix
- Loading branch information
1 parent
5ec3d22
commit 0e4420f
Showing
7 changed files
with
189 additions
and
28 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
93 changes: 93 additions & 0 deletions
93
frontend/src/concepts/k8s/K8sNameDescriptionField/__tests__/ResourceNameField.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,93 @@ | ||
import * as React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ResourceNameField from '~/concepts/k8s/K8sNameDescriptionField/ResourceNameField'; | ||
|
||
describe('ResourceNameField', () => { | ||
it('should render immutable name', () => { | ||
render( | ||
<ResourceNameField | ||
allowEdit={false} | ||
dataTestId="test" | ||
k8sName={{ | ||
value: 'test', | ||
state: { | ||
immutable: true, | ||
invalidCharacters: false, | ||
invalidLength: false, | ||
maxLength: 0, | ||
touched: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
expect(screen.queryByTestId('test-resourceName')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render nothing if not editable and not immutable', () => { | ||
const result = render( | ||
<ResourceNameField | ||
allowEdit={false} | ||
dataTestId="test" | ||
k8sName={{ | ||
value: 'test', | ||
state: { | ||
immutable: false, | ||
invalidCharacters: false, | ||
invalidLength: false, | ||
maxLength: 0, | ||
touched: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
expect(result.container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render editable name', () => { | ||
render( | ||
<ResourceNameField | ||
allowEdit | ||
dataTestId="test" | ||
k8sName={{ | ||
value: 'test', | ||
state: { | ||
immutable: false, | ||
invalidCharacters: false, | ||
invalidLength: false, | ||
maxLength: 0, | ||
touched: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
expect(screen.queryByTestId('test-resourceName')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render editable name with static prefix', () => { | ||
render( | ||
<ResourceNameField | ||
allowEdit | ||
dataTestId="test" | ||
k8sName={{ | ||
value: 'test', | ||
state: { | ||
immutable: false, | ||
invalidCharacters: false, | ||
invalidLength: false, | ||
maxLength: 0, | ||
touched: false, | ||
safePrefix: 'wb-', | ||
staticPrefix: true, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('wb-')).toBeInTheDocument(); | ||
expect(screen.queryByTestId('test-resourceName')).toHaveValue('test'); | ||
}); | ||
}); |
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