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

feat(expert search): implement default gravsearch as placeholder #1247

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TestHostCreateListComponent {
/**
* test component that mocks StringLiteralInputComponent
*/
@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EditListItemComponent } from './edit-list-item.component';
import { MockProvider } from 'ng-mocks';
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';


/**
* test host component to simulate parent component for updating an existing child node.
*/
Expand Down Expand Up @@ -70,7 +71,7 @@ class TestHostInsertChildNodeComponent {
constructor() {}
}

@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ import { ApplicationStateService } from '@dasch-swiss/vre/shared/app-state-servi
import { MockProvider } from 'ng-mocks';
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';


@Component({
selector: 'dasch-swiss-app-progress-indicator',
template: '',
})
class MockProgressIndicatorComponent {}

/**
* test host component to simulate parent component.
*/
Expand Down Expand Up @@ -84,7 +91,7 @@ class TestHostComponent implements OnInit {
/**
* test component that mocks StringLiteralInputComponent
*/
@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
Expand Down Expand Up @@ -128,6 +135,7 @@ describe('ListItemFormComponent', () => {
StringifyStringLiteralPipe,
TruncatePipe,
MockStringLiteralInputComponent,
MockProgressIndicatorComponent,
],
imports: [
BrowserAnimationsModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class ListHostComponent {
};
}

@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ResourceClassFormComponent } from './resource-class-form.component';
import { MockProvider } from 'ng-mocks';
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';


/**
* test host component to simulate parent component.
*/
Expand All @@ -46,10 +47,9 @@ import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';
})
class TestHostResourceClassFormComponent {}

@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
@Input() textarea: boolean;
@Input() value: StringLiteral[] = [];
@Input() disabled: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { MockProvider } from 'ng-mocks';
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';
import {convertToParamMap} from "@angular/router";

@Component({ selector: 'app-string-literal-input', template: '' })
@Component({ selector: 'dasch-swiss-app-string-literal', template: '' })
class MockStringLiteralInputComponent {
@Input() placeholder = 'Label';
@Input() language: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/dsp-app/src/app/project/project.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MockOntologyClassesComponent {
}

@Component({
selector: 'app-progress-indicator',
selector: 'dasch-swiss-app-progress-indicator',
template: '',
})
class MockProgressIndicatorComponent {}
Expand Down
9 changes: 9 additions & 0 deletions apps/dsp-app/src/app/user/account/account.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ import { StatusComponent } from '@dsp-app/src/app/main/status/status.component';
import { TestConfig } from '@dsp-app/src/test.config';
import { PasswordFormComponent } from '../user-form/password-form/password-form.component';
import { AccountComponent } from './account.component';
import { Component } from '@angular/core';

@Component({
selector: 'dasch-swiss-app-progress-indicator',
template: '',
})
class MockProgressIndicatorComponent {}


describe('AccountComponent', () => {
let component: AccountComponent;
Expand All @@ -32,6 +40,7 @@ describe('AccountComponent', () => {
PasswordFormComponent,
DialogComponent,
StatusComponent,
MockProgressIndicatorComponent
],
imports: [
BrowserAnimationsModule,
Expand Down
16 changes: 15 additions & 1 deletion apps/dsp-app/src/app/user/profile/profile.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ import { DialogComponent } from '@dsp-app/src/app/main/dialog/dialog.component';
import { StatusComponent } from '@dsp-app/src/app/main/status/status.component';
import { TestConfig } from '@dsp-app/src/test.config';
import { ProfileComponent } from './profile.component';
import { Component } from '@angular/core';


@Component({
selector: 'dasch-swiss-app-progress-indicator',
template: '',
})
class MockProgressIndicatorComponent {}


describe('ProfileComponent', () => {
let component: ProfileComponent;
let fixture: ComponentFixture<ProfileComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ProfileComponent, DialogComponent, StatusComponent],
declarations: [
ProfileComponent,
DialogComponent,
StatusComponent,
MockProgressIndicatorComponent
],
imports: [
BrowserAnimationsModule,
MatButtonModule,
Expand Down
2 changes: 1 addition & 1 deletion apps/dsp-app/src/app/user/user.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';
* test component to simulate child component, here progress-indicator from action module.
*/
@Component({
selector: 'app-progress-indicator',
selector: 'dasch-swiss-app-progress-indicator',
template: '',
})
class TestProgressIndicatorComponent {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<form [formGroup]="expertSearchForm" class="expert-search-form app-form-content">
<mat-form-field class="textarea-field large-field">
<mat-label>Write your Gravsearch query</mat-label>
<textarea matInput [formControlName]="'gravsearchquery'" cdkTextareaAutosize cdkAutosizeMinRows="12"
<textarea
#textArea
matInput
[formControlName]="'gravsearchquery'"
[placeholder]='defaultGravsearchQuery'
cdkTextareaAutosize cdkAutosizeMinRows="12"
cdkAutosizeMaxRows="24" class="textarea-field-content">
</textarea>
<mat-error *ngIf="expertSearchForm.controls.gravsearchquery.hasError('forbiddenName')">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,6 @@ describe('ExpertSearchComponent', () => {
expect(testHostComponent.expertSearch).toBeTruthy();
});

it('should init the form with the default query', () => {
const textarea = hostCompDe.query(
By.css('textarea.textarea-field-content')
);
const textareaEle = textarea.nativeElement;

expect(textareaEle.value).toBe(
`PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

CONSTRUCT {
?book knora-api:isMainResource true .
?book incunabula:title ?title .

} WHERE {
?book a incunabula:book .
?book incunabula:title ?title .
}
`
);
});

it('should reset the form', () => {
const resetBtn = hostCompDe.query(By.css('button.reset'));
const textarea = hostCompDe.query(
Expand All @@ -138,115 +116,33 @@ CONSTRUCT {
const resetEle = resetBtn.nativeElement;
const textareaEle = textarea.nativeElement;

// delete textarea content displayed by default to make a change
textareaEle.value = '';
expect(textareaEle.value).toBe('');
// mock enter some characters into textarea
textareaEle.value = 'some text';

resetEle.click();

testHostFixture.detectChanges();

// reset the textarea content
expect(textareaEle.value).toBe(
`PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

CONSTRUCT {
?book knora-api:isMainResource true .
?book incunabula:title ?title .

} WHERE {
?book a incunabula:book .
?book incunabula:title ?title .
}
`
);
});

it('should register the query in the params service', () => {
const expectedGravsearch = `PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

CONSTRUCT {
?book knora-api:isMainResource true .
?book incunabula:title ?title .

} WHERE {
?book a incunabula:book .
?book incunabula:title ?title .
}

OFFSET 0
`;
const submitBtn = hostCompDe.query(By.css('button[type="submit"]'));
const submitBtnEle = submitBtn.nativeElement;

submitBtnEle.click();
testHostFixture.detectChanges();

expect(
searchParamsServiceSpy.changeSearchParamsMsg
).toHaveBeenCalledTimes(1);
expect(gravsearchSearchParams).toBeDefined();
expect(gravsearchSearchParams.generateGravsearch(0)).toEqual(
expectedGravsearch
''
);
});

it('should emit the Gravsearch query', () => {
const expectedGravsearch = `PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

CONSTRUCT {
?book knora-api:isMainResource true .
?book incunabula:title ?title .

} WHERE {
?book a incunabula:book .
?book incunabula:title ?title .
}

OFFSET 0
`;

const submitBtn = hostCompDe.query(By.css('button[type="submit"]'));
const submitBtnEle = submitBtn.nativeElement;

expect(testHostComponent.gravsearchQ).toBeUndefined();

submitBtnEle.click();
testHostFixture.detectChanges();

expect(testHostComponent.gravsearchQ).toBeDefined();
expect(testHostComponent.gravsearchQ.query).toEqual(expectedGravsearch);
expect(testHostComponent.gravsearchQ.mode).toEqual('gravsearch');
});

it('should not return an invalid query', () => {
// if no query is entered
expect(
testHostComponent.expertSearch.expertSearchForm.valid
).toBeTruthy();
).toBeFalsy();

const textarea = hostCompDe.query(
By.css('textarea.textarea-field-content')
);
const textareaEle = textarea.nativeElement;

expect(textareaEle.value).toBe(
`PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

CONSTRUCT {
?book knora-api:isMainResource true .
?book incunabula:title ?title .

} WHERE {
?book a incunabula:book .
?book incunabula:title ?title .
}
`
);
expect(textareaEle.value).toBe('');

// mock enter a wrong gravsearch query into textarea: "OFFSET 0" is not allowed in the query.
textareaEle.value = `PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/v2#>

Expand Down