-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.spec.ts
96 lines (76 loc) · 2.72 KB
/
app.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { FormsModule } from '@angular/forms';
import { InputTextModule } from 'primeng/inputtext';
import { ButtonModule } from 'primeng/button';
import { DropdownModule } from 'primeng/dropdown';
interface Property {
name: string;
title?: string;
type: string;
description?: string;
properties?: Property[];
children?: Property[]; // Explicitly typed as an array of `Property`
stringOption?: string;
stringValue?: string;
required?: boolean;
}
describe('AppComponent', () => {
let component: AppComponent;
let httpMock: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AppComponent, // Add AppComponent to imports instead of declarations
HttpClientTestingModule,
FormsModule,
InputTextModule,
ButtonModule,
DropdownModule
]
}).compileComponents();
const fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
httpMock = TestBed.inject(HttpTestingController);
});
afterEach(() => {
httpMock.verify();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
describe('addProperty', () => {
it('should add a top-level property', () => {
component.addProperty();
expect(component.properties.length).toBe(1);
expect(component.properties[0].name).toBe('');
});
it('should add a nested property', () => {
const parent: Property = { name: 'parent', type: 'object', children: [] }; // Initialize children
component.addProperty(parent);
expect(parent.children!.length).toBe(1);
expect(parent.children![0].name).toBe(''); // Safe access since children is initialized
});
});
describe('removeProperty', () => {
it('should remove a property from the properties array', () => {
component.addProperty();
expect(component.properties.length).toBe(1);
component.removeProperty(component.properties, 0);
expect(component.properties.length).toBe(0);
});
});
describe('updateConstWithTitle', () => {
it('should update the const property based on the title', () => {
component.baseSchema.title = 'Test Title';
component.updateConstWithTitle();
expect(component.baseSchema.compositionType[0]?.properties?.type?.const).toBe('fdc3.testtitle');
});
});
});