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

fix(ontology): fix regex pattern in ontology form (DSP-1139) #483

Merged
merged 3 commits into from Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,7 +2,7 @@
<!-- auto complete list to select resource classes -->
<div class="form-content">
<mat-form-field class="large-field ontology-name">
<input matInput class="ontology-name" [maxlength]="nameMaxLength" [formControl]="ontologyForm.controls['name']"
<input matInput class="ontology-name" autocomplete="off" [maxlength]="nameMaxLength" [formControl]="ontologyForm.controls['name']"
[placeholder]="'Set a unique name *'">
<mat-icon matSuffix [matTooltip]="ontologyNameInfo" matTooltipPosition="above" matTooltipClass="multi-line-tooltip">help</mat-icon>
<mat-hint *ngIf="formErrors.name" class="medium-field">
Expand Down
Expand Up @@ -126,6 +126,50 @@ describe('OntologyFormComponent', () => {

});

it('should test form validity with not allowed names', () => {
const form = ontologyFormComponent.ontologyForm;
expect(form.valid).toBeFalsy();

const nameInput = form.controls.name;

nameInput.setValue('v2onto');
expect(form.valid).toBeFalsy();

nameInput.setValue('my-onto');
expect(form.valid).toBeFalsy();

nameInput.setValue('2ndOnto');
expect(form.valid).toBeFalsy();

nameInput.setValue('-notAllowed');
expect(form.valid).toBeFalsy();

nameInput.setValue('_notAllowed');
expect(form.valid).toBeFalsy();

nameInput.setValue('not-allowed');
expect(form.valid).toBeFalsy();

nameInput.setValue('not_allowed');
expect(form.valid).toBeFalsy();

nameInput.setValue('not.allowed');
expect(form.valid).toBeFalsy();

nameInput.setValue('no$or€');
expect(form.valid).toBeFalsy();

nameInput.setValue('no spaces');
expect(form.valid).toBeFalsy();

nameInput.setValue('ältereOnto');
expect(form.valid).toBeFalsy();

nameInput.setValue('bestOnto');
expect(form.valid).toBeTruthy();

});

it('should test form validity without label', () => {
const form = ontologyFormComponent.ontologyForm;
expect(form.valid).toBeFalsy();
Expand Down
Expand Up @@ -51,8 +51,10 @@ export class OntologyFormComponent implements OnInit {

lastModificationDate: string;

nameRegex = /^(?![vV][0-9]|[0-9]|[\u00C0-\u017F]).[a-zA-Z0-9]+\S*$/;
// regex to check ontology name: shouldn't start with a number or with 'v' followed by a number, spaces or special characters are not allowed
nameRegex = /^(?![vV]+[0-9])+^([a-zA-Z])[a-zA-Z0-9]*$/;

// ontology name must not contain one of the following words
forbiddenNames: string[] = [
'knora',
'salsah',
Expand Down