Skip to content

Commit ff11435

Browse files
authored
Merge pull request #29 from platform-mesh/feat/link-value
feat: link value
2 parents 6927d6e + fc0a48c commit ff11435

14 files changed

+378
-65
lines changed

projects/wc/_mocks_/ui5-mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ jest.mock('@ui5/webcomponents-ngx', () => {
2929
ToolbarButtonComponent: MockComponent,
3030
ToolbarComponent: MockComponent,
3131
BarComponent: MockComponent,
32+
LinkComponent: MockComponent,
3233
};
3334
});

projects/wc/src/app/components/generic-ui/value-cell/value-cell.constants.ts renamed to projects/wc/src/app/components/generic-ui/value-cell/boolean-value/boolean-cell.constants.ts

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ui5-icon [name]="iconName()" [design]="iconDesign()"></ui5-icon>

projects/wc/src/app/components/generic-ui/value-cell/boolean-value/boolean-value.component.scss

Whitespace-only changes.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import {
2+
ICON_DESIGN_NEGATIVE,
3+
ICON_DESIGN_POSITIVE,
4+
ICON_NAME_NEGATIVE,
5+
ICON_NAME_POSITIVE,
6+
} from './boolean-cell.constants';
7+
import { BooleanValueComponent } from './boolean-value.component';
8+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
9+
import { ComponentFixture, TestBed } from '@angular/core/testing';
10+
11+
describe('BooleanValueComponent', () => {
12+
let component: BooleanValueComponent;
13+
let fixture: ComponentFixture<BooleanValueComponent>;
14+
15+
const makeComponent = (boolValue: boolean) => {
16+
fixture = TestBed.createComponent(BooleanValueComponent);
17+
component = fixture.componentInstance;
18+
19+
fixture.componentRef.setInput('boolValue', boolValue);
20+
21+
fixture.detectChanges();
22+
23+
return { component, fixture };
24+
};
25+
26+
beforeEach(() => {
27+
TestBed.configureTestingModule({
28+
imports: [BooleanValueComponent],
29+
}).overrideComponent(BooleanValueComponent, {
30+
set: {
31+
imports: [],
32+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
33+
},
34+
});
35+
});
36+
37+
it('should create', () => {
38+
const { component } = makeComponent(true);
39+
expect(component).toBeTruthy();
40+
});
41+
42+
it('should set positive icon design and name for true value', () => {
43+
const { component } = makeComponent(true);
44+
45+
expect(component.iconDesign()).toBe(ICON_DESIGN_POSITIVE);
46+
expect(component.iconName()).toBe(ICON_NAME_POSITIVE);
47+
});
48+
49+
it('should set negative icon design and name for false value', () => {
50+
const { component } = makeComponent(false);
51+
52+
expect(component.iconDesign()).toBe(ICON_DESIGN_NEGATIVE);
53+
expect(component.iconName()).toBe(ICON_NAME_NEGATIVE);
54+
});
55+
56+
it('should render ui5-icon for true value', () => {
57+
const { fixture } = makeComponent(true);
58+
const compiled = fixture.nativeElement;
59+
const iconElement = compiled.querySelector('ui5-icon');
60+
61+
expect(iconElement).toBeTruthy();
62+
});
63+
64+
it('should render ui5-icon for false value', () => {
65+
const { fixture } = makeComponent(false);
66+
const compiled = fixture.nativeElement;
67+
const iconElement = compiled.querySelector('ui5-icon');
68+
69+
expect(iconElement).toBeTruthy();
70+
});
71+
72+
it('should update icon when boolValue changes from true to false', () => {
73+
const { component, fixture } = makeComponent(true);
74+
75+
expect(component.iconDesign()).toBe(ICON_DESIGN_POSITIVE);
76+
expect(component.iconName()).toBe(ICON_NAME_POSITIVE);
77+
78+
fixture.componentRef.setInput('boolValue', false);
79+
fixture.detectChanges();
80+
81+
expect(component.iconDesign()).toBe(ICON_DESIGN_NEGATIVE);
82+
expect(component.iconName()).toBe(ICON_NAME_NEGATIVE);
83+
});
84+
85+
it('should update icon when boolValue changes from false to true', () => {
86+
const { component, fixture } = makeComponent(false);
87+
88+
expect(component.iconDesign()).toBe(ICON_DESIGN_NEGATIVE);
89+
expect(component.iconName()).toBe(ICON_NAME_NEGATIVE);
90+
91+
fixture.componentRef.setInput('boolValue', true);
92+
fixture.detectChanges();
93+
94+
expect(component.iconDesign()).toBe(ICON_DESIGN_POSITIVE);
95+
expect(component.iconName()).toBe(ICON_NAME_POSITIVE);
96+
});
97+
98+
it('should have required boolValue input', () => {
99+
const { component } = makeComponent(true);
100+
expect(component.boolValue()).toBe(true);
101+
});
102+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
ICON_DESIGN_NEGATIVE,
3+
ICON_DESIGN_POSITIVE,
4+
ICON_NAME_NEGATIVE,
5+
ICON_NAME_POSITIVE,
6+
} from './boolean-cell.constants';
7+
import { Component, computed, input } from '@angular/core';
8+
import { IconComponent } from '@ui5/webcomponents-ngx';
9+
10+
export type IconDesignType =
11+
| typeof ICON_DESIGN_POSITIVE
12+
| typeof ICON_DESIGN_NEGATIVE;
13+
14+
@Component({
15+
selector: 'wc-boolean-value',
16+
imports: [IconComponent],
17+
templateUrl: './boolean-value.component.html',
18+
styleUrl: './boolean-value.component.scss',
19+
})
20+
export class BooleanValueComponent {
21+
boolValue = input.required<boolean>();
22+
iconDesign = computed<IconDesignType>(() => {
23+
return this.boolValue() ? ICON_DESIGN_POSITIVE : ICON_DESIGN_NEGATIVE;
24+
});
25+
iconName = computed<string>(() => {
26+
return this.boolValue() ? ICON_NAME_POSITIVE : ICON_NAME_NEGATIVE;
27+
});
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ui5-link (click)="stopPropagation($event)" target="_blank" [tooltip]="urlValue()" [href]="urlValue()">Link</ui5-link>

projects/wc/src/app/components/generic-ui/value-cell/link-value/link-value.component.scss

Whitespace-only changes.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { LinkValueComponent } from './link-value.component';
2+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
3+
import { ComponentFixture, TestBed } from '@angular/core/testing';
4+
5+
describe('LinkValueComponent', () => {
6+
let component: LinkValueComponent;
7+
let fixture: ComponentFixture<LinkValueComponent>;
8+
9+
const makeComponent = (urlValue: string) => {
10+
fixture = TestBed.createComponent(LinkValueComponent);
11+
component = fixture.componentInstance;
12+
13+
fixture.componentRef.setInput('urlValue', urlValue);
14+
15+
fixture.detectChanges();
16+
17+
return { component, fixture };
18+
};
19+
20+
beforeEach(() => {
21+
TestBed.configureTestingModule({
22+
imports: [LinkValueComponent],
23+
}).overrideComponent(LinkValueComponent, {
24+
set: {
25+
imports: [],
26+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
27+
},
28+
});
29+
});
30+
31+
it('should create', () => {
32+
const { component } = makeComponent('https://example.com');
33+
expect(component).toBeTruthy();
34+
});
35+
36+
it('should render ui5-link', () => {
37+
const { fixture } = makeComponent('https://example.com');
38+
const compiled = fixture.nativeElement;
39+
const linkElement = compiled.querySelector('ui5-link');
40+
41+
expect(linkElement).toBeTruthy();
42+
expect(linkElement.textContent.trim()).toBe('Link');
43+
});
44+
45+
it('should render ui5-link with different URL', () => {
46+
const { fixture } = makeComponent('http://test.com');
47+
const compiled = fixture.nativeElement;
48+
const linkElement = compiled.querySelector('ui5-link');
49+
50+
expect(linkElement).toBeTruthy();
51+
});
52+
53+
it('should call stopPropagation when link is clicked', () => {
54+
const { component, fixture } = makeComponent('https://example.com');
55+
const compiled = fixture.nativeElement;
56+
const linkElement = compiled.querySelector('ui5-link');
57+
58+
const mockEvent = {
59+
stopPropagation: jest.fn(),
60+
};
61+
62+
component.stopPropagation(mockEvent as any);
63+
64+
expect(mockEvent.stopPropagation).toHaveBeenCalled();
65+
});
66+
67+
it('should update when urlValue changes', () => {
68+
const { fixture } = makeComponent('https://example.com');
69+
const compiled = fixture.nativeElement;
70+
let linkElement = compiled.querySelector('ui5-link');
71+
72+
expect(linkElement).toBeTruthy();
73+
74+
fixture.componentRef.setInput('urlValue', 'https://newurl.com');
75+
fixture.detectChanges();
76+
77+
linkElement = compiled.querySelector('ui5-link');
78+
expect(linkElement).toBeTruthy();
79+
});
80+
81+
it('should have required urlValue input', () => {
82+
const { component } = makeComponent('https://example.com');
83+
expect(component.urlValue()).toBe('https://example.com');
84+
});
85+
86+
it('should handle complex URLs with paths and parameters', () => {
87+
const complexUrl = 'https://example.com/path?param=value&other=123';
88+
const { fixture } = makeComponent(complexUrl);
89+
const compiled = fixture.nativeElement;
90+
const linkElement = compiled.querySelector('ui5-link');
91+
92+
expect(linkElement).toBeTruthy();
93+
});
94+
95+
it('should handle URLs with fragments', () => {
96+
const urlWithFragment = 'https://example.com/page#section';
97+
const { fixture } = makeComponent(urlWithFragment);
98+
const compiled = fixture.nativeElement;
99+
const linkElement = compiled.querySelector('ui5-link');
100+
101+
expect(linkElement).toBeTruthy();
102+
});
103+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, input } from '@angular/core';
2+
import { LinkComponent } from '@ui5/webcomponents-ngx';
3+
4+
@Component({
5+
selector: 'wc-link-value',
6+
imports: [LinkComponent],
7+
templateUrl: './link-value.component.html',
8+
styleUrl: './link-value.component.scss',
9+
})
10+
export class LinkValueComponent {
11+
urlValue = input.required<string>();
12+
13+
public stopPropagation(event: Event) {
14+
event.stopPropagation();
15+
}
16+
}

0 commit comments

Comments
 (0)