Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ describe('AddDeviceEnterpriseComponent', () => {
it('should create', () => {
expect(component).toBeTruthy()
})

it('should default useTLS and allowSelfSigned to true', () => {
expect(component.form.get('useTLS')?.value).toBe(true)
expect(component.form.get('allowSelfSigned')?.value).toBe(true)
})

it('should submit form when valid', () => {
component.form.setValue({
hostname: 'example.com',
friendlyName: 'Test Device',
username: 'testuser',
password: 'password',
tenantId: '',
useTLS: false,
allowSelfSigned: false
useTLS: true,
allowSelfSigned: true
})
component.submitForm()

Expand All @@ -72,8 +78,8 @@ describe('AddDeviceEnterpriseComponent', () => {
username: 'testuser',
password: 'password',
tenantId: '',
useTLS: false,
allowSelfSigned: false,
useTLS: true,
allowSelfSigned: true,
tags: ['']
})
expect(dialogCloseSpy).toHaveBeenCalledWith({ submitted: true })
Expand All @@ -86,12 +92,70 @@ describe('AddDeviceEnterpriseComponent', () => {
username: '',
password: '',
tenantId: '',
useTLS: false,
allowSelfSigned: false
useTLS: true,
allowSelfSigned: true
})
component.submitForm()

expect(addDeviceSpy).not.toHaveBeenCalled()
expect(dialogCloseSpy).not.toHaveBeenCalled()
})
})

describe('AddDeviceEnterpriseComponent with existing device', () => {
let component: AddDeviceEnterpriseComponent
let fixture: ComponentFixture<AddDeviceEnterpriseComponent>

beforeEach(() => {
const deviceService = jasmine.createSpyObj('DevicesService', ['addDevice', 'editDevice'])
deviceService.addDevice.and.returnValue(of({}))
deviceService.editDevice.and.returnValue(of({}))

TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
MatDialogModule,
MatCheckboxModule,
MatInputModule,
MatFormFieldModule,
FormsModule,
ReactiveFormsModule,
MatChipsModule,
AddDeviceEnterpriseComponent
],
providers: [
provideTranslateService(),
{ provide: DevicesService, useValue: deviceService },
{
provide: MAT_DIALOG_DATA,
useValue: {
hostname: 'test-device.local',
friendlyName: 'Existing Device',
username: 'admin',
password: 'testpass',
useTLS: false,
allowSelfSigned: false,
guid: 'test-guid-456',
tags: ['existing']
}
},
{
provide: MatDialogRef,
useValue: {
close: () => {
/* empty */
}
}
}
]
})
fixture = TestBed.createComponent(AddDeviceEnterpriseComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should preserve loaded TLS values instead of applying the defaults', () => {
expect(component.form.get('useTLS')?.value).toBe(false)
expect(component.form.get('allowSelfSigned')?.value).toBe(false)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class AddDeviceEnterpriseComponent {
]],
password: ['', [Validators.required, Validators.minLength(8)]],
tenantId: [''],
useTLS: [false],
allowSelfSigned: [false]
useTLS: [true],
allowSelfSigned: [true]
})
public readonly separatorKeysCodes: number[] = [ENTER, COMMA]
public tags: string[] = []
Expand Down
Loading