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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ 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}`);
}

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

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

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,31 @@ describe('Model version details', () => {
modelVersionDetails.findModelVersionDropdownItem('Version 2').click();
modelVersionDetails.findVersionId().contains('2');
});

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

modelVersionDetails.findAddLabelButton().click();

modelVersionDetails.findLabel('New Label').should('exist');

modelVersionDetails.findLabel('New Label').click().type('Updated Label{enter}');

modelVersionDetails.findSaveLabelsButton().should('exist').click();
});

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

modelVersionDetails.findLabelInput('Testing label').click();

modelVersionDetails.findLabelInput('Testing label').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