1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { SmbJoinAuthFormComponent } from './smb-join-auth-form.component';
4 import { ToastrModule } from 'ngx-toastr';
5 import { SharedModule } from '~/app/shared/shared.module';
6 import { provideHttpClient } from '@angular/common/http';
7 import { provideHttpClientTesting } from '@angular/common/http/testing';
8 import { provideRouter } from '@angular/router';
9 import { ReactiveFormsModule } from '@angular/forms';
10 import { SmbService } from '~/app/shared/api/smb.service';
11 import { JOIN_AUTH_RESOURCE } from '../smb.model';
12 import { of } from 'rxjs';
14 export const FOO_JOIN_AUTH = {
20 resource_type: JOIN_AUTH_RESOURCE
23 describe('SmbJoinAuthFormComponent', () => {
24 let component: SmbJoinAuthFormComponent;
25 let fixture: ComponentFixture<SmbJoinAuthFormComponent>;
26 let createJoinAuth: jasmine.Spy;
27 let getJoinAuth: jasmine.Spy;
29 beforeEach(async () => {
30 await TestBed.configureTestingModule({
31 imports: [ToastrModule.forRoot(), SharedModule, ReactiveFormsModule],
32 declarations: [SmbJoinAuthFormComponent],
33 providers: [provideHttpClient(), provideHttpClientTesting(), provideRouter([])]
34 }).compileComponents();
36 fixture = TestBed.createComponent(SmbJoinAuthFormComponent);
37 component = fixture.componentInstance;
39 createJoinAuth = spyOn(TestBed.inject(SmbService), 'createJoinAuth');
40 getJoinAuth = spyOn(TestBed.inject(SmbService), 'getJoinAuth');
41 fixture.detectChanges();
44 it('should create', () => {
45 expect(component).toBeTruthy();
48 it('should set form invalid if any required fields are missing', () => {
49 component.form.controls['authId'].setValue('');
50 component.form.controls['username'].setValue('');
51 component.form.controls['password'].setValue('');
52 expect(component.form.valid).not.toBeNull();
55 it('should submit the form', () => {
56 component.form.controls['authId'].setValue('foo');
57 component.form.controls['username'].setValue('user');
58 component.form.controls['password'].setValue('pass');
59 component.form.controls['linkedToCluster'].setValue(undefined);
63 expect(createJoinAuth).toHaveBeenCalledWith(FOO_JOIN_AUTH);
66 describe('when editing', () => {
68 component.editing = true;
69 getJoinAuth.and.returnValue(of(FOO_JOIN_AUTH));
71 fixture.detectChanges();
74 it('should get resource data and set form fields with it', () => {
75 expect(getJoinAuth).toHaveBeenCalled();
76 expect(component.form.value).toEqual({
80 linkedToCluster: undefined