Skip to content
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

Labels editing and validation #3426

Merged
merged 15 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,38 @@ class ModelVersionDetails {
this.findTable().find(`[data-label=Key]`).contains(name).parents('tr'),
);
}

findEditLabelsButton() {
return cy.findByTestId('editable-labels-group-edit');
}

findAddLabelButton() {
return cy.findByTestId('add-label-button');
}

findLabelInput(label: string) {
return cy.findByTestId(`edit-label-input-${label}`);
}

findLabel(label: string) {
return cy.findByTestId(`editable-label-${label}`);
}

findRemoveLabelButton(label: string) {
return cy.findByTestId(`remove-label-${label}`);
}

findLabelErrorAlert() {
return cy.findByTestId('label-error-alert');
}

findSaveLabelsButton() {
return cy.findByTestId('editable-labels-group-save');
}

findDiscardLabelsButton() {
return cy.findByTestId('editable-labels-group-discard');
}
}

class PropertyRow extends TableRow {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,6 @@ describe('Model version details', () => {
it('Model version details tab', () => {
modelVersionDetails.findVersionId().contains('1');
modelVersionDetails.findDescription().should('have.text', 'Description of model version');
modelVersionDetails.findMoreLabelsButton().contains('6 more');
modelVersionDetails.findMoreLabelsButton().click();
modelVersionDetails.shouldContainsModalLabels([
'Testing label',
'Financial',
'Financial data',
'Fraud detection',
'Machine learning',
'Next data to be overflow',
'Label x',
'Label y',
'Label z',
]);
modelVersionDetails.findStorageEndpoint().contains('test-endpoint');
modelVersionDetails.findStorageRegion().contains('test-region');
modelVersionDetails.findStorageBucket().contains('test-bucket');
Expand Down Expand Up @@ -346,6 +333,43 @@ describe('Model version details', () => {
modelVersionDetails.findModelVersionDropdownItem('Version 2').click();
modelVersionDetails.findVersionId().contains('2');
});

it('should handle label editing', () => {
modelVersionDetails.findEditLabelsButton().click();
modelVersionDetails.findAddLabelButton().click();

// Check label exists and is visible
cy.findByTestId('editable-label-New Label').should('exist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can findLabel('New label') be used instead ofeditable-label-New label? I believe findLabel was added for this?

cy.findByTestId('editable-label-New Label').should('be.visible');

// Click the label
cy.findByTestId('editable-label-New Label').click();

// Type the new label
cy.get('input[data-testid="edit-label-input-New Label"]').should('exist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies here: modelVersionDetails.findLabelInput('New Label') instead of 'input[data-testid="edit-label-input-New Label"]' and the following 2-3 lines...

cy.get('input[data-testid="edit-label-input-New Label"]').should('be.visible');
cy.get('input[data-testid="edit-label-input-New Label"]').clear();
cy.get('input[data-testid="edit-label-input-New Label"]').type('UniqueLabel123{enter}');

// Save changes
modelVersionDetails.findSaveLabelsButton().click();
cy.wait('@UpdatePropertyRow');
});

it('should handle label validation', () => {
modelVersionDetails.findEditLabelsButton().click();

cy.findByTestId('editable-label-Testing label').click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use findLabelInput('Testing label') instead


cy.get('input[data-testid="edit-label-input-Testing label"]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

.should('exist')
.should('be.visible');

const longLabel = 'a'.repeat(64);
modelVersionDetails.findLabelInput('Testing label').clear().type(`${longLabel}{enter}`);
modelVersionDetails.findLabelErrorAlert().should('contain', "can't exceed 63 characters");
modelVersionDetails.findLabel('New Label').should('not.exist');
});
});

describe('Registered deployments tab', () => {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/DashboardDescriptionListGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type EditableProps = {
editButtonTestId?: string;
saveButtonTestId?: string;
cancelButtonTestId?: string;
discardButtonTestId?: string;
};

export type DashboardDescriptionListGroupProps = {
Expand All @@ -36,6 +37,7 @@ export type DashboardDescriptionListGroupProps = {
contentWhenEmpty?: React.ReactNode;
children: React.ReactNode;
groupTestId?: string;
isSaveDisabled?: boolean;
} & (({ isEditable: true } & EditableProps) | ({ isEditable?: false } & Partial<EditableProps>));

const DashboardDescriptionListGroup: React.FC<DashboardDescriptionListGroupProps> = (props) => {
Expand All @@ -57,6 +59,7 @@ const DashboardDescriptionListGroup: React.FC<DashboardDescriptionListGroupProps
editButtonTestId,
saveButtonTestId,
cancelButtonTestId,
isSaveDisabled,
} = props;
return (
<DescriptionListGroup data-testid={groupTestId}>
Expand All @@ -74,7 +77,7 @@ const DashboardDescriptionListGroup: React.FC<DashboardDescriptionListGroupProps
aria-label={`Save edits to ${title}`}
variant="link"
onClick={onSaveEditsClick}
isDisabled={isSavingEdits}
isDisabled={isSavingEdits || isSaveDisabled}
>
<CheckIcon />
</Button>
Expand Down
Loading