mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix start process testing (#5778)
This commit is contained in:
@@ -18,7 +18,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { FormFieldModel } from './../core/form-field.model';
|
||||
import { FormModel } from './../core/form.model';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
import { HyperlinkWidgetComponent } from './hyperlink.widget';
|
||||
import { setupTestBed } from '../../../../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
@@ -87,7 +86,7 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
widget.field = null;
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.linkUrl).toBe(WidgetComponent.DEFAULT_HYPERLINK_URL);
|
||||
expect(widget.linkUrl).toBe(HyperlinkWidgetComponent.DEFAULT_HYPERLINK_URL);
|
||||
});
|
||||
|
||||
it('should return default url for missing field property', () => {
|
||||
@@ -96,7 +95,7 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.linkUrl).toBe(WidgetComponent.DEFAULT_HYPERLINK_URL);
|
||||
expect(widget.linkUrl).toBe(HyperlinkWidgetComponent.DEFAULT_HYPERLINK_URL);
|
||||
});
|
||||
|
||||
it('should prepend url with scheme', () => {
|
||||
@@ -106,7 +105,7 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.linkUrl).toBe(`${WidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`);
|
||||
expect(widget.linkUrl).toBe(`${HyperlinkWidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`);
|
||||
});
|
||||
|
||||
it('should not prepend url with scheme', () => {
|
||||
@@ -119,6 +118,42 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
expect(widget.linkUrl).toBe(url);
|
||||
});
|
||||
|
||||
it('should value property content be use as link if present', () => {
|
||||
const url = 'www.alfresco.com';
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
value: url
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.linkUrl).toBe(`${HyperlinkWidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`);
|
||||
});
|
||||
|
||||
it('should use value property content over hyperlinkUrl ', () => {
|
||||
const url = 'www.alfresco.com';
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
value: url,
|
||||
hyperlinkUrl: 'www.alfresco-test.com'
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.linkUrl).toBe(`${HyperlinkWidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`);
|
||||
});
|
||||
|
||||
it('should use value property id displayText is not present ', () => {
|
||||
const url = 'www.alfresco.com';
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
displayText: url
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
fixture.detectChanges();
|
||||
const hyperlinkWidgetLink = element.querySelector('a');
|
||||
expect(hyperlinkWidgetLink.innerText).toBe(url);
|
||||
});
|
||||
|
||||
it('should be able to set label property', () => {
|
||||
const label = 'Label';
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
|
@@ -15,11 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormService } from './../../../services/form.service';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
import { FormFieldModel } from '../core';
|
||||
|
||||
@Component({
|
||||
selector: 'hyperlink-widget',
|
||||
@@ -40,11 +41,14 @@ import { WidgetComponent } from './../widget.component';
|
||||
})
|
||||
export class HyperlinkWidgetComponent extends WidgetComponent implements OnInit {
|
||||
|
||||
linkUrl: string = WidgetComponent.DEFAULT_HYPERLINK_URL;
|
||||
static DEFAULT_HYPERLINK_URL: string = '#';
|
||||
static DEFAULT_HYPERLINK_SCHEME: string = 'http://';
|
||||
|
||||
linkUrl: string = '#';
|
||||
linkText: string = null;
|
||||
|
||||
constructor(public formService: FormService) {
|
||||
super(formService);
|
||||
super(formService);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -54,4 +58,20 @@ export class HyperlinkWidgetComponent extends WidgetComponent implements OnInit
|
||||
}
|
||||
}
|
||||
|
||||
protected getHyperlinkUrl(field: FormFieldModel) {
|
||||
let value = field.value || field.hyperlinkUrl;
|
||||
|
||||
if (value && !/^https?:\/\//i.test(value)) {
|
||||
value = `${HyperlinkWidgetComponent.DEFAULT_HYPERLINK_SCHEME}${value}`;
|
||||
}
|
||||
|
||||
return value || HyperlinkWidgetComponent.DEFAULT_HYPERLINK_URL;
|
||||
}
|
||||
|
||||
protected getHyperlinkText(field: FormFieldModel) {
|
||||
if (field) {
|
||||
return field.displayText || field.hyperlinkUrl || field.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -42,9 +42,6 @@ import { FormFieldModel } from './core/index';
|
||||
})
|
||||
export class WidgetComponent implements AfterViewInit {
|
||||
|
||||
static DEFAULT_HYPERLINK_URL: string = '#';
|
||||
static DEFAULT_HYPERLINK_SCHEME: string = 'http://';
|
||||
|
||||
/** Does the widget show a read-only value? (ie, can't be edited) */
|
||||
@Input()
|
||||
readOnly: boolean = false;
|
||||
@@ -101,24 +98,6 @@ export class WidgetComponent implements AfterViewInit {
|
||||
this.fieldChanged.emit(field);
|
||||
}
|
||||
|
||||
protected getHyperlinkUrl(field: FormFieldModel) {
|
||||
let url = WidgetComponent.DEFAULT_HYPERLINK_URL;
|
||||
if (field && field.hyperlinkUrl) {
|
||||
url = field.hyperlinkUrl;
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
url = `${WidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
protected getHyperlinkText(field: FormFieldModel) {
|
||||
if (field) {
|
||||
return field.displayText || field.hyperlinkUrl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
event(event: Event): void {
|
||||
this.formService.formEvents.next(event);
|
||||
}
|
||||
|
Reference in New Issue
Block a user