generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: adding git repo #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4596684
creating git repo
Hubert-Szczepanski-SAP 735a85c
moving texts to proper file
Hubert-Szczepanski-SAP 2cf0e87
fixing type and moving texts
Hubert-Szczepanski-SAP 13117fb
PR changes
Hubert-Szczepanski-SAP 5242fb2
fix
Hubert-Szczepanski-SAP 541f288
Merge branch 'main' into feat/adding-git-repository
Hubert-Szczepanski-SAP aeb5908
PR changes
Hubert-Szczepanski-SAP be845fc
Merge branch 'feat/adding-git-repository' of https://github.com/openm…
Hubert-Szczepanski-SAP 8bb25e4
lint
Hubert-Szczepanski-SAP 342af82
Merge branch 'main' into feat/adding-git-repository
Hubert-Szczepanski-SAP 7baafee
removing placeholder
Hubert-Szczepanski-SAP 4589bec
Merge branch 'feat/adding-git-repository' of https://github.com/openm…
Hubert-Szczepanski-SAP a147683
lint
Hubert-Szczepanski-SAP 16f498d
button
Hubert-Szczepanski-SAP f99a16e
Merge branch 'main' into feat/adding-git-repository
Hubert-Szczepanski-SAP 8815560
PR changes + merge to main
Hubert-Szczepanski-SAP 3937a3a
restoring package-lock.json
Hubert-Szczepanski-SAP cfe2965
removing placeholder
Hubert-Szczepanski-SAP 826dc23
lint fix
Hubert-Szczepanski-SAP 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
223 changes: 223 additions & 0 deletions
223
src/components/Dialogs/CreateGitRepositoryDialog.cy.tsx
This file contains hidden or 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,223 @@ | ||
| import { CreateGitRepositoryDialog } from './CreateGitRepositoryDialog'; | ||
| import { CreateGitRepositoryParams } from '../../hooks/useCreateGitRepository'; | ||
|
|
||
| describe('CreateGitRepositoryDialog', () => { | ||
| let capturedData: CreateGitRepositoryParams | null = null; | ||
|
|
||
| const fakeUseCreateGitRepository = () => ({ | ||
| createGitRepository: async (data: CreateGitRepositoryParams): Promise<void> => { | ||
| capturedData = data; | ||
| }, | ||
| isLoading: false, | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| capturedData = null; | ||
| }); | ||
|
|
||
| it('creates a git repository with valid data', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| const expectedPayload = { | ||
| namespace: 'default', | ||
| name: 'test-repo', | ||
| interval: '5m0s', | ||
| url: 'https://github.com/test/repo', | ||
| branch: 'develop', | ||
| secretRef: '', | ||
| }; | ||
|
|
||
| // Fill in the form | ||
| cy.get('#name').find('input').type('test-repo'); | ||
| cy.get('#interval').find('input').clear().type('5m0s'); | ||
| cy.get('#url').find('input').type('https://github.com/test/repo'); | ||
| cy.get('#branch').find('input').clear().type('develop'); | ||
|
|
||
| // Submit the form | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Verify the hook was called with correct data | ||
| cy.then(() => cy.wrap(capturedData).deepEqualJson(expectedPayload)); | ||
|
|
||
| // Dialog should close on success | ||
| cy.wrap(onClose).should('have.been.called'); | ||
| }); | ||
|
|
||
| it('includes secretRef when provided', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| const expectedPayload = { | ||
| namespace: 'default', | ||
| name: 'test-repo', | ||
| interval: '1m0s', | ||
| url: 'https://github.com/test/repo', | ||
| branch: 'main', | ||
| secretRef: 'my-git-secret', | ||
| }; | ||
|
|
||
| // Fill in the form | ||
| cy.get('#name').find('input').type('test-repo'); | ||
andreaskienle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cy.get('#url').find('input').type('https://github.com/test/repo'); | ||
| cy.get('#secretRef').find('input').type('my-git-secret'); | ||
|
|
||
| // Submit the form | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Verify the hook was called with correct data | ||
| cy.then(() => cy.wrap(capturedData).deepEqualJson(expectedPayload)); | ||
|
|
||
| // Dialog should close on success | ||
| cy.wrap(onClose).should('have.been.called'); | ||
| }); | ||
|
|
||
| it('validates required fields', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| // Try to submit without filling required fields | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Should show validation errors | ||
| cy.get('#name').should('have.attr', 'value-state', 'Negative'); | ||
| cy.contains('This field is required').should('exist'); | ||
|
|
||
| // Dialog should not close | ||
| cy.wrap(onClose).should('not.have.been.called'); | ||
| }); | ||
|
|
||
| it('validates URL format', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| cy.get('#name').find('input').type('test-repo'); | ||
| cy.get('#interval').find('input').clear().type('1m0s'); | ||
| cy.get('#branch').find('input').clear().type('main'); | ||
|
|
||
| // Test 1: Invalid string | ||
| cy.get('#url').find('input').clear().type('not-a-valid-url'); | ||
| cy.get('ui5-button').contains('Create').click(); | ||
| cy.get('#url').should('have.attr', 'value-state', 'Negative'); | ||
| cy.contains('Must be a valid HTTPS URL').should('exist'); | ||
|
|
||
| // Test 2: HTTP protocol (should fail if we require HTTPS) | ||
| cy.get('#url').find('input').clear().type('http://github.com/test/repo'); | ||
| cy.get('ui5-button').contains('Create').click(); | ||
| cy.get('#url').should('have.attr', 'value-state', 'Negative'); | ||
| cy.contains('Must be a valid HTTPS URL').should('exist'); | ||
|
|
||
| // Test 3: Valid HTTPS URL (should pass) | ||
| cy.get('#url').find('input').clear().type('https://github.com/test/repo'); | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Dialog should close on success | ||
| cy.wrap(onClose).should('have.been.called'); | ||
| }); | ||
|
|
||
| it('closes dialog when cancel is clicked', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| // Fill in some data | ||
| cy.get('#name').find('input').type('test-repo'); | ||
|
|
||
| // Click cancel | ||
| cy.get('ui5-button').contains('Cancel').click(); | ||
|
|
||
| // Dialog should close without calling onSuccess | ||
| cy.wrap(onClose).should('have.been.called'); | ||
| }); | ||
|
|
||
| it('uses default values for interval and branch', () => { | ||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={fakeUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| // Check default values | ||
| cy.get('#interval').find('input').should('have.value', '1m0s'); | ||
| cy.get('#branch').find('input').should('have.value', 'main'); | ||
| }); | ||
|
|
||
| it('should not close dialog when creation fails', () => { | ||
| const failingUseCreateGitRepository = () => ({ | ||
| createGitRepository: async (): Promise<void> => { | ||
| throw new Error('Creation failed'); | ||
| }, | ||
| isLoading: false, | ||
| }); | ||
|
|
||
| const onClose = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateGitRepositoryDialog | ||
| isOpen={true} | ||
| namespace="default" | ||
| useCreateGitRepository={failingUseCreateGitRepository} | ||
| onClose={onClose} | ||
| />, | ||
| ); | ||
|
|
||
| // Fill in the form | ||
| cy.get('#name').find('input').type('test-repo'); | ||
| cy.get('#interval').find('input').clear().type('1m0s'); | ||
| cy.get('#url').find('input').type('https://github.com/test/repo'); | ||
| cy.get('#branch').find('input').clear().type('main'); | ||
|
|
||
| // Submit the form | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Dialog should NOT close on failure | ||
| cy.wrap(onClose).should('not.have.been.called'); | ||
|
|
||
| // Dialog should still be visible | ||
| cy.contains('Create Git Repository').should('be.visible'); | ||
| }); | ||
| }); | ||
41 changes: 41 additions & 0 deletions
41
src/components/Dialogs/CreateGitRepositoryDialog.module.css
This file contains hidden or 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,41 @@ | ||
| .grid { | ||
| display: grid; | ||
| grid-template-columns: auto 1fr; | ||
| gap: 1rem; | ||
| padding: 1rem; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .gridColumnLabel { | ||
| justify-self: end; | ||
| } | ||
|
|
||
| .inputField { | ||
| width: 25rem; | ||
| } | ||
|
|
||
| .sectionHeader { | ||
| grid-column: 1 / -1; | ||
| font-weight: bold; | ||
| font-size: var(--sapFontHeader6Size); | ||
| padding-top: 0.5rem; | ||
| padding-bottom: 0.5rem; | ||
| border-bottom: 1px solid var(--sapGroup_Title_BorderColor); | ||
| margin-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .sectionHeader:first-child { | ||
| padding-top: 0; | ||
| } | ||
|
|
||
| .form { | ||
| width: 30rem; | ||
| } | ||
|
|
||
| .formField { | ||
| margin-bottom: 1.25rem; | ||
| } | ||
|
|
||
| .input { | ||
| width: 100%; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.