Skip to content

Commit

Permalink
NAS-128968: NAs-128968: TrueCloud Backup shows non-Storj credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKarpov98 committed May 14, 2024
1 parent 8f2e519 commit 706da7f
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
import { Observable, of } from 'rxjs';
import { CloudSyncProviderName } from 'app/enums/cloudsync-provider.enum';
import { CloudCredentialsFormComponent } from 'app/pages/credentials/backup-credentials/cloud-credentials-form/cloud-credentials-form.component';
import { CloudCredentialService } from 'app/services/cloud-credential.service';
import { CloudCredentialsSelectComponent } from './cloud-credentials-select.component';

class MockTranslateService {
translate(key: string): Observable<string> {
return of(key);
}
}

const cloudCredentialServiceMock = {
getCloudSyncCredentials: jest.fn(() => of([
{ id: '1', name: 'AWS S3', provider: CloudSyncProviderName.AmazonS3 },
{ id: '2', name: 'Dropbox', provider: CloudSyncProviderName.Dropbox },
])),
};

describe('CloudCredentialsSelectComponent', () => {
let component: CloudCredentialsSelectComponent;
let fixture: ComponentFixture<CloudCredentialsSelectComponent>;
let cloudCredentialService: jest.Mocked<CloudCredentialService>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CloudCredentialsSelectComponent],
providers: [
{
provide: CloudCredentialService,
useValue: cloudCredentialServiceMock,
},
{
provide: TranslateService,
useClass: MockTranslateService,
},
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();

fixture = TestBed.createComponent(CloudCredentialsSelectComponent);
component = fixture.componentInstance;
cloudCredentialService = TestBed.inject(CloudCredentialService) as jest.Mocked<CloudCredentialService>;
});

it('should fetch options correctly', async () => {
const options = await fixture.componentInstance.fetchOptions().toPromise();
expect(options).toEqual([
{ label: 'AWS S3 (Amazon S3)', value: '1' },
{ label: 'Dropbox (Dropbox)', value: '2' },
]);
expect(cloudCredentialService.getCloudSyncCredentials).toHaveBeenCalled();
});

it('should fetch and filter options correctly', async () => {
component.filterByProviders = [CloudSyncProviderName.AmazonS3];

const options = await fixture.componentInstance.fetchOptions().toPromise();
expect(options).toEqual([{ label: 'AWS S3 (Amazon S3)', value: '1' }]);
expect(cloudCredentialService.getCloudSyncCredentials).toHaveBeenCalled();
});

it('should return the correct form component type', () => {
expect(component.getFormComponentType()).toBe(CloudCredentialsFormComponent);
});
});

0 comments on commit 706da7f

Please sign in to comment.