Skip to content

Commit 2b4c50f

Browse files
committed
feat: add tests
1 parent 4de8655 commit 2b4c50f

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

projects/wc/src/app/components/organization-management/organization-management.component.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,44 @@ describe('OrganizationManagementComponent', () => {
239239

240240
expect(window.location.href).toBe('https://validorg.test.com');
241241
});
242+
243+
it('should return non-local message for organization creation when not in local setup', () => {
244+
// Mock window.location.hostname to simulate non-local setup
245+
const originalHostname = window.location.hostname;
246+
Object.defineProperty(window.location, 'hostname', {
247+
value: 'production.example.com',
248+
writable: true,
249+
});
250+
251+
const message = component['getMessageForOrganizationCreation']('testOrg');
252+
expect(message).toBe(
253+
'A new organization has been created. Select it from the list to switch.',
254+
);
255+
256+
// Restore original hostname
257+
Object.defineProperty(window.location, 'hostname', {
258+
value: originalHostname,
259+
writable: true,
260+
});
261+
});
262+
263+
it('should return Negative state for invalid and touched form control', () => {
264+
const formControl = {
265+
invalid: true,
266+
touched: true,
267+
} as any;
268+
269+
const result = component.getValueState(formControl);
270+
expect(result).toBe('Negative');
271+
});
272+
273+
it('should return None state for valid form control', () => {
274+
const formControl = {
275+
invalid: false,
276+
touched: true,
277+
} as any;
278+
279+
const result = component.getValueState(formControl);
280+
expect(result).toBe('None');
281+
});
242282
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { k8sNameValidator } from './k8s-name-validator';
2+
import { AbstractControl } from '@angular/forms';
3+
4+
describe('k8sNameValidator', () => {
5+
const createControl = (value: any): AbstractControl =>
6+
({
7+
value,
8+
}) as AbstractControl;
9+
10+
it('should return null when control value is null', () => {
11+
const control = createControl(null);
12+
const result = k8sNameValidator(control);
13+
expect(result).toBeNull();
14+
});
15+
16+
it('should return null when control value is undefined', () => {
17+
const control = createControl(undefined);
18+
const result = k8sNameValidator(control);
19+
expect(result).toBeNull();
20+
});
21+
22+
it('should return null when control value is empty string', () => {
23+
const control = createControl('');
24+
const result = k8sNameValidator(control);
25+
expect(result).toBeNull();
26+
});
27+
28+
it('should return null for valid k8s name (single character)', () => {
29+
const control = createControl('a');
30+
const result = k8sNameValidator(control);
31+
expect(result).toBeNull();
32+
});
33+
34+
it('should return null for valid k8s name (with numbers and hyphens)', () => {
35+
const control = createControl('my-app-123');
36+
const result = k8sNameValidator(control);
37+
expect(result).toBeNull();
38+
});
39+
40+
it('should return null for valid k8s name (maximum length)', () => {
41+
const control = createControl('a'.repeat(63));
42+
const result = k8sNameValidator(control);
43+
expect(result).toBeNull();
44+
});
45+
46+
it('should return error for invalid k8s name starting with number', () => {
47+
const control = createControl('123invalid');
48+
const result = k8sNameValidator(control);
49+
expect(result).toEqual({ k8sNameInvalid: true });
50+
});
51+
52+
it('should return error for invalid k8s name starting with uppercase', () => {
53+
const control = createControl('Invalid');
54+
const result = k8sNameValidator(control);
55+
expect(result).toEqual({ k8sNameInvalid: true });
56+
});
57+
58+
it('should return error for invalid k8s name ending with hyphen', () => {
59+
const control = createControl('invalid-');
60+
const result = k8sNameValidator(control);
61+
expect(result).toEqual({ k8sNameInvalid: true });
62+
});
63+
64+
it('should return error for invalid k8s name with uppercase letters', () => {
65+
const control = createControl('Invalid-Name');
66+
const result = k8sNameValidator(control);
67+
expect(result).toEqual({ k8sNameInvalid: true });
68+
});
69+
70+
it('should return error for invalid k8s name exceeding maximum length', () => {
71+
const control = createControl('a'.repeat(64));
72+
const result = k8sNameValidator(control);
73+
expect(result).toEqual({ k8sNameInvalid: true });
74+
});
75+
76+
it('should return error for invalid k8s name with special characters', () => {
77+
const control = createControl('invalid@name');
78+
const result = k8sNameValidator(control);
79+
expect(result).toEqual({ k8sNameInvalid: true });
80+
});
81+
82+
it('should handle non-string values by converting to string', () => {
83+
const control = createControl(123);
84+
const result = k8sNameValidator(control);
85+
expect(result).toEqual({ k8sNameInvalid: true });
86+
});
87+
});

0 commit comments

Comments
 (0)