-
Notifications
You must be signed in to change notification settings - Fork 163
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
feat(mr): create mr modal #2828
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { mockDashboardConfig, mockDscStatus } from '~/__mocks__'; | ||
import { mockDsciStatus } from '~/__mocks__/mockDsciStatus'; | ||
import { StackCapability, StackComponent } from '~/concepts/areas/types'; | ||
import { modelRegistrySettings } from '~/__tests__/cypress/cypress/pages/modelRegistrySettings'; | ||
import { pageNotfound } from '~/__tests__/cypress/cypress/pages/pageNotFound'; | ||
import { asProductAdminUser, asProjectAdminUser } from '~/__tests__/cypress/cypress/utils/users'; | ||
|
||
const setupMocksForMRSettingAccess = () => { | ||
asProductAdminUser(); | ||
cy.interceptOdh( | ||
'GET /api/config', | ||
mockDashboardConfig({ | ||
disableModelRegistry: false, | ||
}), | ||
); | ||
cy.interceptOdh( | ||
'GET /api/dsc/status', | ||
mockDscStatus({ | ||
installedComponents: { | ||
[StackComponent.MODEL_REGISTRY]: true, | ||
[StackComponent.MODEL_MESH]: true, | ||
}, | ||
}), | ||
); | ||
cy.interceptOdh( | ||
'GET /api/dsci/status', | ||
mockDsciStatus({ | ||
requiredCapabilities: [StackCapability.SERVICE_MESH, StackCapability.SERVICE_MESH_AUTHZ], | ||
}), | ||
); | ||
}; | ||
|
||
it('Model registry settings should not be available for non product admins', () => { | ||
asProjectAdminUser(); | ||
modelRegistrySettings.visit(false); | ||
pageNotfound.findPage().should('exist'); | ||
modelRegistrySettings.findNavItem().should('not.exist'); | ||
}); | ||
|
||
it('Model registry settings should be available for product admins with capabilities', () => { | ||
setupMocksForMRSettingAccess(); | ||
// check page is accessible | ||
modelRegistrySettings.visit(true); | ||
// check nav item exists | ||
modelRegistrySettings.findNavItem().should('exist'); | ||
}); | ||
|
||
describe('CreateModal', () => { | ||
beforeEach(() => { | ||
setupMocksForMRSettingAccess(); | ||
}); | ||
|
||
it('should display error messages when form fields are invalid and not allow submit', () => { | ||
modelRegistrySettings.visit(true); | ||
cy.findByText('Create model registry').click(); | ||
// Fill in the form with invalid data | ||
cy.get('#mr-name').clear(); | ||
cy.get('#mr-host').clear(); | ||
cy.get('#mr-port').clear(); | ||
cy.get('#mr-username').clear(); | ||
cy.get('#mr-password').clear(); | ||
cy.get('#mr-database').clear(); | ||
cy.get('#mr-database').blur(); | ||
// Assert the submit button is disabled | ||
cy.findByTestId('modal-submit-button').should('be.disabled'); | ||
// Assert that error messages are displayed | ||
cy.findByTestId('mr-name-error') | ||
.should('be.visible') | ||
.contains( | ||
"Must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character", | ||
); | ||
cy.findByTestId('mr-host-error').should('be.visible').contains('Host cannot be empty'); | ||
cy.findByTestId('mr-port-error').should('be.visible').contains('Port cannot be empty'); | ||
cy.findByTestId('mr-username-error').should('be.visible').contains('Username cannot be empty'); | ||
cy.findByTestId('mr-password-error').should('be.visible').contains('Password cannot be empty'); | ||
cy.findByTestId('mr-database-error').scrollIntoView(); | ||
cy.findByTestId('mr-database-error').should('be.visible').contains('Database cannot be empty'); | ||
Comment on lines
+55
to
+77
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. @dpanshug Selectors should be part of page objects so they are reusable when we get to e2e tests. 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. @christianvogt FYI I addressed this in updates to #2829 |
||
}); | ||
|
||
it('should enable submit button if fields are valid', () => { | ||
modelRegistrySettings.visit(true); | ||
cy.findByText('Create model registry').click(); | ||
// Fill in the form with invalid data | ||
cy.get('#mr-name').type('valid-mr-name'); | ||
cy.get('#mr-host').type('host'); | ||
cy.get('#mr-port').type('1234'); | ||
cy.get('#mr-username').type('validUser'); | ||
cy.get('#mr-password').type('strongPassword'); | ||
cy.get('#mr-database').type('myDatabase'); | ||
cy.get('#mr-database').blur(); | ||
// Assert the submit button is disabled | ||
cy.findByTestId('modal-submit-button').should('be.enabled'); | ||
// Assert that error messages are not displayed | ||
cy.findByTestId('mr-name-error').should('not.exist'); | ||
cy.findByTestId('mr-host-error').should('not.exist'); | ||
cy.findByTestId('mr-port-error').should('not.exist'); | ||
cy.findByTestId('mr-username-error').should('not.exist'); | ||
cy.findByTestId('mr-password-error').should('not.exist'); | ||
cy.findByTestId('mr-database-error').should('not.exist'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { appChrome } from './appChrome'; | ||
|
||
class ModelRegistrySettings { | ||
visit(wait = true) { | ||
cy.visit('/modelRegistrySettings'); | ||
if (wait) { | ||
this.wait(); | ||
} | ||
} | ||
|
||
navigate() { | ||
this.findNavItem().click(); | ||
this.wait(); | ||
} | ||
|
||
private wait() { | ||
this.findHeading(); | ||
cy.testA11y(); | ||
} | ||
|
||
private findHeading() { | ||
cy.findByTestId('app-page-title').should('exist'); | ||
cy.findByTestId('app-page-title').contains('Model Registry Settings'); | ||
} | ||
|
||
findNavItem() { | ||
return appChrome.findNavItem('Model registry settings', 'Settings'); | ||
} | ||
} | ||
|
||
export const modelRegistrySettings = new ModelRegistrySettings(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// targeting specific form section title elements to override --pf-v5-c-form__section-title--FontSize, --pf-v5-c-form__section-title--FontWeight | ||
.form-subtitle-text { | ||
color: var(--pf-v5-global--Color--200); | ||
gitdallas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
font-size: initial; | ||
font-weight: initial; | ||
} |
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.
Asserting static text as defined in in our react components is often a bad idea because it's a 1:1 relationship and will only fail if we change the react component.
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.
Ack. I plan to give these tests a second pass as part of adding more in #2829, I'll address this feedback there and request a review from you for that one when it's ready if you don't mind.
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.
@christianvogt looking back at this, I think it has value beyond what you're saying -- we shouldn't just assert that components render certain text for the sake of it, but this is trying to assert that the error is shown vs not shown. We could do it with a testid instead if you prefer but imo it doesn't matter much as long as the test is asserting logic and not just content. This test will fail if the form validation logic breaks.
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.
My concern was the
contains
check and not so much the check that the error node was visible since this is the only available error text that's shown in this node.Note that if the error text was dynamic from a server response, I would agree with asserting the text presence.
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.
@christianvogt FYI I addressed this in updates to #2829