-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab0ef88
commit ba75b71
Showing
18 changed files
with
668 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ca-content/src/lib/components/search/search-save/dialog/save-search-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<h2 class="aca-save-search-dialog__header" mat-dialog-title>{{"APP.BROWSE.SEARCH.SAVE_SEARCH.MODAL_HEADER" | translate}}</h2> | ||
|
||
<mat-dialog-content> | ||
<form [formGroup]="form" (submit)="submit()"> | ||
<mat-form-field class="aca-save-search-dialog__form-field"> | ||
<mat-label>{{ 'APP.BROWSE.SEARCH.SAVE_SEARCH.NAME_LABEL' | translate }}</mat-label> | ||
<input | ||
id="aca-save-search-dialog-name-input" | ||
[attr.aria-label]="'APP.BROWSE.SEARCH.SAVE_SEARCH.NAME_LABEL' | translate" | ||
matInput | ||
required | ||
[formControlName]="'name'" | ||
adf-auto-focus | ||
/> | ||
|
||
<mat-hint *ngIf="form.controls['name'].dirty"> | ||
<span *ngIf="form.controls['name'].errors?.required"> | ||
{{ 'APP.BROWSE.SEARCH.SAVE_SEARCH.NAME_REQUIRED_ERROR' | translate }} | ||
</span> | ||
</mat-hint> | ||
</mat-form-field> | ||
|
||
<mat-form-field class="aca-save-search-dialog__form-field"> | ||
<mat-label>{{ 'APP.BROWSE.SEARCH.SAVE_SEARCH.DESCRIPTION_LABEL' | translate }}</mat-label> | ||
<textarea | ||
id="aca-save-search-dialog-description-input" | ||
matInput | ||
[attr.aria-label]="'APP.BROWSE.SEARCH.SAVE_SEARCH.DESCRIPTION_LABEL' | translate" | ||
rows="4" | ||
[formControlName]="'description'"></textarea> | ||
</mat-form-field> | ||
</form> | ||
</mat-dialog-content> | ||
|
||
<mat-dialog-actions align="end"> | ||
<button | ||
mat-button | ||
id="aca-save-search-dialog-cancel-button" | ||
mat-dialog-close> | ||
{{ 'APP.BROWSE.SEARCH.SAVE_SEARCH.CANCEL_BUTTON' | translate }} | ||
</button> | ||
|
||
<button id="aca-save-search-dialog-save-button" | ||
mat-flat-button | ||
color="primary" | ||
(click)="submit()" | ||
[disabled]="!form.valid"> | ||
{{'APP.BROWSE.SEARCH.SAVE_SEARCH.SAVE_BUTTON' | translate}} | ||
</button> | ||
</mat-dialog-actions> |
5 changes: 5 additions & 0 deletions
5
...ca-content/src/lib/components/search/search-save/dialog/save-search-dialog.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.aca-save-search-dialog { | ||
.aca-save-search-dialog__form-field { | ||
width: 100%; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...content/src/lib/components/search/search-save/dialog/save-search-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*! | ||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Alfresco Example Content Application | ||
* | ||
* This file is part of the Alfresco Example Content Application. | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* | ||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Alfresco Example Content Application is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { of } from 'rxjs'; | ||
import { SaveSearchDialogComponent } from './save-search-dialog.component'; | ||
import { ContentTestingModule, SavedSearchesService } from '@alfresco/adf-content-services'; | ||
import { provideMockStore } from '@ngrx/store/testing'; | ||
import { AppTestingModule } from '../../../../testing/app-testing.module'; | ||
import { Store } from '@ngrx/store'; | ||
import { SnackbarErrorAction, SnackbarInfoAction } from '@alfresco/aca-shared/store'; | ||
|
||
describe('SaveSearchDialogComponent', () => { | ||
let fixture: ComponentFixture<SaveSearchDialogComponent>; | ||
let component: SaveSearchDialogComponent; | ||
let savedSearchesService: SavedSearchesService; | ||
let store: Store; | ||
|
||
let submitButton: HTMLButtonElement; | ||
const dialogRef = { | ||
close: jasmine.createSpy('close') | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ContentTestingModule, AppTestingModule], | ||
providers: [ | ||
{ provide: MatDialogRef, useValue: dialogRef }, | ||
provideMockStore(), | ||
{ provide: SavedSearchesService, useValue: { saveSearch: () => of() } }, | ||
{ provide: MAT_DIALOG_DATA, useValue: { searchUrl: 'abcdef' } } | ||
] | ||
}); | ||
dialogRef.close.calls.reset(); | ||
fixture = TestBed.createComponent(SaveSearchDialogComponent); | ||
component = fixture.componentInstance; | ||
savedSearchesService = TestBed.inject(SavedSearchesService); | ||
store = TestBed.inject(Store); | ||
|
||
submitButton = fixture.nativeElement.querySelector('#aca-save-search-dialog-save-button'); | ||
component.data = { searchUrl: 'abcdef' }; | ||
}); | ||
|
||
afterEach(() => { | ||
fixture.destroy(); | ||
}); | ||
|
||
it('should not save search if form is invalid', () => { | ||
spyOn(savedSearchesService, 'saveSearch').and.callThrough(); | ||
submitButton.click(); | ||
expect(savedSearchesService.saveSearch).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should save search, show snackbar message and close modal if form is valid', fakeAsync(() => () => { | ||
spyOn(savedSearchesService, 'saveSearch').and.callThrough(); | ||
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarInfoAction('APP.BROWSE.SEARCH.SAVE_SEARCH.SAVE_SUCCESS')); | ||
expect(dialogRef.close).toHaveBeenCalled(); | ||
})); | ||
|
||
it('should save search, show snackbar message and close modal if form is valid', fakeAsync(() => () => { | ||
spyOn(savedSearchesService, 'saveSearch').and.throwError(''); | ||
setFormValuesAndSubmit(); | ||
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('APP.BROWSE.SEARCH.SAVE_SEARCH.SAVE_ERROR')); | ||
expect(dialogRef.close).not.toHaveBeenCalled(); | ||
})); | ||
|
||
function setFormValuesAndSubmit() { | ||
spyOn(store, 'dispatch'); | ||
component.form.controls['name'].setValue('ABCDEF'); | ||
component.form.controls['description'].setValue('TEST'); | ||
submitButton.click(); | ||
tick(); | ||
expect(savedSearchesService.saveSearch).toHaveBeenCalledWith({ | ||
name: 'ABCDEF', | ||
description: 'TEST', | ||
encodedUrl: 'abcdef' | ||
}); | ||
} | ||
}); |
Oops, something went wrong.