mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
* [ADF-2065] created dialog component for content node selector * [ADF-2065] removing SiteModel from site dropdown to use SitePaging model of js-api * [ADF-2065] - removed site model and updated documentation * [ADF-2065] fixed test for site component * [ADF-2065] refactored content node selector and created content node selector dialog * [ADF-2065] fixed test on site-api service * [ADF-2065] added a new content node dialog service to centralise the logic for content node dialog * [ADF-2065] start adding test for node-actions service| * [ADF-2065] added test for node-actions service * [ADF-2065] added test for node action service * [ADF-2065] renamed components to keep backward compatibility * [ADF-2065] added input just for backward compatibility * [ADF-2065] added some changes for backward compatibility and updated documentation * [ADF-2065] updated documentation for content node selector
263 lines
9.1 KiB
TypeScript
263 lines
9.1 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright 2016 Alfresco Software, Ltd.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import { DebugElement } from '@angular/core';
|
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
import { By } from '@angular/platform-browser';
|
|
import { MaterialModule } from '../material.module';
|
|
import { DropdownSitesComponent } from './sites-dropdown.component';
|
|
|
|
declare let jasmine: any;
|
|
|
|
let sitesList = {
|
|
'list': {
|
|
'pagination': {
|
|
'count': 2,
|
|
'hasMoreItems': false,
|
|
'totalItems': 2,
|
|
'skipCount': 0,
|
|
'maxItems': 100
|
|
},
|
|
'entries': [
|
|
{
|
|
'entry': {
|
|
'role': 'SiteManager',
|
|
'visibility': 'PUBLIC',
|
|
'guid': 'fake-1',
|
|
'description': 'fake-test-site',
|
|
'id': 'fake-test-site',
|
|
'preset': 'site-dashboard',
|
|
'title': 'fake-test-site'
|
|
}
|
|
},
|
|
{
|
|
'entry': {
|
|
'role': 'SiteManager',
|
|
'visibility': 'PUBLIC',
|
|
'guid': 'fake-2',
|
|
'description': 'This is a Sample Alfresco Team site.',
|
|
'id': 'swsdp',
|
|
'preset': 'site-dashboard',
|
|
'title': 'fake-test-2'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
describe('DropdownSitesComponent', () => {
|
|
|
|
let component: any;
|
|
let fixture: ComponentFixture<DropdownSitesComponent>;
|
|
let debug: DebugElement;
|
|
let element: HTMLElement;
|
|
|
|
beforeEach(async(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
imports: [
|
|
MaterialModule
|
|
],
|
|
declarations: [
|
|
DropdownSitesComponent
|
|
]
|
|
}).compileComponents();
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
fixture = TestBed.createComponent(DropdownSitesComponent);
|
|
debug = fixture.debugElement;
|
|
element = fixture.nativeElement;
|
|
component = fixture.componentInstance;
|
|
});
|
|
|
|
describe('Rendering tests', () => {
|
|
|
|
function openSelectbox() {
|
|
const selectBox = debug.query(By.css(('[data-automation-id="site-my-files-select"] .mat-select-trigger')));
|
|
selectBox.triggerEventHandler('click', null);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
jasmine.Ajax.install();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jasmine.Ajax.uninstall();
|
|
fixture.destroy();
|
|
TestBed.resetTestingModule();
|
|
});
|
|
|
|
it('Dropdown sites should be rendered', async(() => {
|
|
fixture.detectChanges();
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
expect(element.querySelector('#site-dropdown-container')).toBeDefined();
|
|
expect(element.querySelector('#site-dropdown')).toBeDefined();
|
|
expect(element.querySelector('#site-dropdown-container')).not.toBeNull();
|
|
expect(element.querySelector('#site-dropdown')).not.toBeNull();
|
|
});
|
|
|
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
status: 200,
|
|
contentType: 'json',
|
|
responseText: sitesList
|
|
});
|
|
}));
|
|
|
|
it('should show the "My files" option by default', async(() => {
|
|
component.hideMyFiles = false;
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
|
|
|
openSelectbox();
|
|
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
expect(window.document.querySelector('[data-automation-id="site-my-files-option"]')).not.toBeNull();
|
|
});
|
|
}));
|
|
|
|
it('should hide the "My files" option if the developer desires that way', async(() => {
|
|
component.hideMyFiles = true;
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
|
|
|
openSelectbox();
|
|
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
expect(window.document.querySelector('[data-automation-id="site-my-files-option"]')).toBeNull();
|
|
});
|
|
}));
|
|
|
|
it('should show the default placeholder label by default', async(() => {
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
|
|
|
openSelectbox();
|
|
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
expect(fixture.nativeElement.innerText.trim()).toContain('DROPDOWN.PLACEHOLDER_LABEL');
|
|
});
|
|
}));
|
|
|
|
it('should show custom placeholder label when the \'placeholder\' input property is given a value', async(() => {
|
|
component.placeholder = 'NODE_SELECTOR.SELECT_LOCATION';
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
|
|
|
openSelectbox();
|
|
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
expect(fixture.nativeElement.innerText.trim()).toContain('NODE_SELECTOR.SELECT_LOCATION');
|
|
});
|
|
}));
|
|
|
|
it('should load custom sites when the \'siteList\' input property is given a value', async(() => {
|
|
component.siteList = {
|
|
'list': {
|
|
'entries': [
|
|
{
|
|
'entry': {
|
|
'guid': '-my-',
|
|
'title': 'PERSONAL_FILES'
|
|
}
|
|
},
|
|
{
|
|
'entry': {
|
|
'guid': '-mysites-',
|
|
'title': 'FILE_LIBRARIES'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
fixture.detectChanges();
|
|
|
|
openSelectbox();
|
|
|
|
let options: any = [];
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
options = debug.queryAll(By.css('mat-option'));
|
|
options[0].triggerEventHandler('click', null);
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
component.change.subscribe(() => {
|
|
expect(options[0].attributes['ng-reflect-value']).toBe('default');
|
|
expect(options[1].attributes['ng-reflect-value']).toBe('-my-');
|
|
expect(options[2].attributes['ng-reflect-value']).toBe('-mysites-');
|
|
});
|
|
}));
|
|
|
|
it('should load sites by default', (done) => {
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
status: 200,
|
|
contentType: 'json',
|
|
responseText: sitesList
|
|
});
|
|
|
|
openSelectbox();
|
|
|
|
let options: any = [];
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
options = debug.queryAll(By.css('mat-option'));
|
|
options[0].triggerEventHandler('click', null);
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
component.change.subscribe(() => {
|
|
expect(options[0].attributes['ng-reflect-value']).toBe('default');
|
|
expect(options[1].attributes['ng-reflect-value']).toBe('fake-1');
|
|
expect(options[2].attributes['ng-reflect-value']).toBe('fake-2');
|
|
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should raise an event when a site is selected', (done) => {
|
|
fixture.detectChanges();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
status: 200,
|
|
contentType: 'json',
|
|
responseText: sitesList
|
|
});
|
|
|
|
fixture.whenStable().then(() => {
|
|
fixture.detectChanges();
|
|
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
|
fixture.detectChanges();
|
|
let options: any = debug.queryAll(By.css('mat-option'));
|
|
options[1].triggerEventHandler('click', null);
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
component.change.subscribe((site) => {
|
|
expect(site.entry.guid).toBe('fake-1');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|