generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Workspace Cypress tests (Creation/Deletion) #351
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 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac6b028
workspace tests for creation and deletion
Hubert-Szczepanski-SAP 455b36d
Merge branch 'main' into feat/workspace-cypress-tests
Hubert-Szczepanski-SAP 7316711
PR changes
Hubert-Szczepanski-SAP 0bf9350
Merge branch 'main' into feat/workspace-cypress-tests
Hubert-Szczepanski-SAP 00159f2
PR changes
Hubert-Szczepanski-SAP e391c61
Merge branch 'feat/workspace-cypress-tests' of https://github.com/ope…
Hubert-Szczepanski-SAP c472b45
PR changes
Hubert-Szczepanski-SAP 6996751
PR changes
Hubert-Szczepanski-SAP 3da4741
PR changes
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
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
164 changes: 164 additions & 0 deletions
164
src/components/Dialogs/CreateWorkspaceDialogContainer.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,164 @@ | ||
| import { CreateWorkspaceDialogContainer } from './CreateWorkspaceDialogContainer'; | ||
| import { useCreateWorkspace, CreateWorkspaceParams } from '../../hooks/useCreateWorkspace'; | ||
| import { useAuthOnboarding } from '../../spaces/onboarding/auth/AuthContextOnboarding'; | ||
|
|
||
| describe('CreateWorkspaceDialogContainer', () => { | ||
| let createWorkspacePayload: Omit<CreateWorkspaceParams, 'namespace'> | null = null; | ||
|
|
||
| const fakeUseCreateWorkspace: typeof useCreateWorkspace = () => ({ | ||
| createWorkspace: async (data: Omit<CreateWorkspaceParams, 'namespace'>): Promise<boolean> => { | ||
| createWorkspacePayload = data; | ||
| return true; | ||
| }, | ||
| isLoading: false, | ||
| errorDialogRef: { current: null }, | ||
| }); | ||
|
|
||
| const fakeUseAuthOnboarding = (() => ({ | ||
| user: { | ||
| email: '[email protected]', | ||
| }, | ||
| })) as typeof useAuthOnboarding; | ||
|
|
||
| beforeEach(() => { | ||
| createWorkspacePayload = null; | ||
| }); | ||
|
|
||
| it('creates a workspace with valid data', () => { | ||
| const setIsOpen = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateWorkspaceDialogContainer | ||
| useCreateWorkspace={fakeUseCreateWorkspace} | ||
| useAuthOnboarding={fakeUseAuthOnboarding} | ||
| isOpen={true} | ||
| setIsOpen={setIsOpen} | ||
| project="test-project" | ||
| />, | ||
| ); | ||
|
|
||
| const expectedPayload = { | ||
| name: 'test-workspace', | ||
| displayName: 'Test Workspace Display Name', | ||
| chargingTarget: '12345678-1234-1234-1234-123456789abc', | ||
| members: [ | ||
| { | ||
| name: '[email protected]', | ||
| roles: ['admin'], | ||
| kind: 'User', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| // Fill in the form (using Shadow DOM selectors) | ||
| cy.get('#name').find('input[id*="inner"]').type('test-workspace'); | ||
| cy.get('#displayName').find('input[id*="inner"]').type('Test Workspace Display Name'); | ||
|
|
||
| // Select charging target type | ||
| cy.get('#chargingTargetType').click(); | ||
| cy.contains('BTP').click(); | ||
|
|
||
| // Fill charging target | ||
| cy.get('#chargingTarget').find('input[id*="inner"]').type('12345678-1234-1234-1234-123456789abc'); | ||
|
|
||
| // Submit the form | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Verify the hook was called with correct data | ||
| cy.then(() => cy.wrap(createWorkspacePayload).deepEqualJson(expectedPayload)); | ||
|
|
||
| // Dialog should close on success | ||
| cy.wrap(setIsOpen).should('have.been.calledWith', false); | ||
| }); | ||
|
|
||
| it('validates required fields', () => { | ||
| const setIsOpen = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateWorkspaceDialogContainer | ||
| useCreateWorkspace={fakeUseCreateWorkspace} | ||
| useAuthOnboarding={fakeUseAuthOnboarding} | ||
| isOpen={true} | ||
| setIsOpen={setIsOpen} | ||
| project="test-project" | ||
| />, | ||
| ); | ||
|
|
||
| // Try to submit without filling required fields | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Should show validation errors - check for value-state="Negative" attribute | ||
| cy.get('#name').should('have.attr', 'value-state', 'Negative'); | ||
|
|
||
| // Or check if error message exists in DOM (even if hidden by CSS) | ||
| cy.contains('This field is required').should('exist'); | ||
|
|
||
| // Dialog should not close | ||
| cy.wrap(setIsOpen).should('not.have.been.called'); | ||
| }); | ||
|
|
||
| it('validates charging target format for BTP', () => { | ||
| const setIsOpen = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateWorkspaceDialogContainer | ||
| useCreateWorkspace={fakeUseCreateWorkspace} | ||
| useAuthOnboarding={fakeUseAuthOnboarding} | ||
| isOpen={true} | ||
| setIsOpen={setIsOpen} | ||
| project="test-project" | ||
| />, | ||
| ); | ||
|
|
||
| cy.get('#name').find('input[id*="inner"]').type('test-workspace'); | ||
| cy.get('#chargingTargetType').click(); | ||
| cy.contains('BTP').click(); | ||
|
|
||
| // Invalid format | ||
| cy.get('#chargingTarget').find('input[id*="inner"]').type('invalid-format'); | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Should show validation error - check for value-state="Negative" attribute | ||
| cy.get('#chargingTarget').should('have.attr', 'value-state', 'Negative'); | ||
|
|
||
| // Dialog should not close | ||
| cy.wrap(setIsOpen).should('not.have.been.called'); | ||
| }); | ||
|
|
||
| it('should not close dialog when creation fails', () => { | ||
| const failingUseCreateWorkspace: typeof useCreateWorkspace = () => ({ | ||
| createWorkspace: async (): Promise<boolean> => { | ||
| return false; // Simulate failure | ||
| }, | ||
| isLoading: false, | ||
| errorDialogRef: { current: null }, | ||
| }); | ||
|
|
||
| const setIsOpen = cy.stub(); | ||
|
|
||
| cy.mount( | ||
| <CreateWorkspaceDialogContainer | ||
| useCreateWorkspace={failingUseCreateWorkspace} | ||
| useAuthOnboarding={fakeUseAuthOnboarding} | ||
| isOpen={true} | ||
| setIsOpen={setIsOpen} | ||
| project="test-project" | ||
| />, | ||
| ); | ||
|
|
||
| // Fill in the form | ||
| cy.get('#name').find('input[id*="inner"]').type('test-workspace'); | ||
| cy.get('#chargingTargetType').click(); | ||
| cy.contains('BTP').click(); | ||
| cy.get('#chargingTarget').find('input[id*="inner"]').type('12345678-1234-1234-1234-123456789abc'); | ||
|
|
||
| // Submit the form | ||
| cy.get('ui5-button').contains('Create').click(); | ||
|
|
||
| // Dialog should NOT close on failure | ||
| cy.wrap(setIsOpen).should('not.have.been.called'); | ||
|
|
||
| // Dialog should still be visible | ||
| cy.contains('Create').should('be.visible'); | ||
| }); | ||
| }); |
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
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.