-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-128968: NAs-128968: TrueCloud Backup shows non-Storj credentials
- Loading branch information
1 parent
8f2e519
commit 706da7f
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/app/modules/custom-selects/cloud-credentials-select/cloud-credentials-select.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |