-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-133621 / 25.04 / Bring back One Drive (#11357)
- Loading branch information
Showing
96 changed files
with
709 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
36 changes: 36 additions & 0 deletions
36
...ntials-form/provider-forms/one-drive-provider-form/one-drive-provider-form.component.html
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,36 @@ | ||
<ix-oauth-provider-authentication | ||
[oauthUrl]="provider.credentials_oauth" | ||
(authenticated)="onOauthAuthenticated($event)" | ||
></ix-oauth-provider-authentication> | ||
|
||
<ix-fieldset [title]="'Authentication' | translate" [formGroup]="form"> | ||
<ix-input | ||
formControlName="token" | ||
type="password" | ||
[label]="'Access Token' | translate" | ||
[required]="true" | ||
[tooltip]="helptext.token_onedrive.tooltip | translate" | ||
></ix-input> | ||
|
||
<ix-select | ||
formControlName="drives" | ||
[options]="drives$" | ||
[label]="'Drives List' | translate" | ||
[tooltip]="helptext.drives_onedrive.tooltip | translate" | ||
></ix-select> | ||
|
||
<ix-select | ||
formControlName="drive_type" | ||
[label]="'Drive Account Type' | translate" | ||
[required]="true" | ||
[options]="driveTypes$" | ||
[tooltip]="helptext.drive_type_onedrive.tooltip | translate" | ||
></ix-select> | ||
|
||
<ix-input | ||
formControlName="drive_id" | ||
[label]="'Drive ID' | translate" | ||
[required]="true" | ||
[tooltip]="helptext.drive_id_onedrive.tooltip | translate" | ||
></ix-input> | ||
</ix-fieldset> |
142 changes: 142 additions & 0 deletions
142
...als-form/provider-forms/one-drive-provider-form/one-drive-provider-form.component.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,142 @@ | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { mockApi, mockCall } from 'app/core/testing/utils/mock-api.utils'; | ||
import { OneDriveType } from 'app/enums/cloudsync-provider.enum'; | ||
import { CloudSyncProvider } from 'app/interfaces/cloudsync-provider.interface'; | ||
import { DialogService } from 'app/modules/dialog/dialog.service'; | ||
import { IxSelectHarness } from 'app/modules/forms/ix-forms/components/ix-select/ix-select.harness'; | ||
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness'; | ||
import { ApiService } from 'app/modules/websocket/api.service'; | ||
import { | ||
OauthProviderComponent, | ||
} from 'app/pages/credentials/backup-credentials/cloud-credentials-form/oauth-provider/oauth-provider.component'; | ||
import { | ||
OneDriveProviderFormComponent, | ||
} from 'app/pages/credentials/backup-credentials/cloud-credentials-form/provider-forms/one-drive-provider-form/one-drive-provider-form.component'; | ||
|
||
describe('OneDriveProviderFormComponent', () => { | ||
let spectator: Spectator<OneDriveProviderFormComponent>; | ||
let form: IxFormHarness; | ||
const createComponent = createComponentFactory({ | ||
component: OneDriveProviderFormComponent, | ||
detectChanges: false, | ||
imports: [ | ||
ReactiveFormsModule, | ||
OauthProviderComponent, | ||
], | ||
providers: [ | ||
mockProvider(DialogService), | ||
mockApi([ | ||
mockCall('cloudsync.onedrive_list_drives', [ | ||
{ | ||
drive_type: OneDriveType.Business, | ||
drive_id: 'business1', | ||
name: 'ODCMetadataArchive', | ||
description: 'ODC Archived Metadata', | ||
}, | ||
{ | ||
drive_type: OneDriveType.DocumentLibrary, | ||
drive_id: 'library1', | ||
name: 'OneDrive', | ||
description: '', | ||
}, | ||
]), | ||
]), | ||
], | ||
}); | ||
|
||
beforeEach(async () => { | ||
spectator = createComponent(); | ||
spectator.component.provider = { | ||
credentials_oauth: 'http://truenas.com/oauth', | ||
} as CloudSyncProvider; | ||
spectator.detectChanges(); | ||
form = await TestbedHarnessEnvironment.harnessForFixture(spectator.fixture, IxFormHarness); | ||
}); | ||
|
||
it('show existing provider attributes when they are set as form values', async () => { | ||
spectator.component.getFormSetter$().next({ | ||
client_id: 'client', | ||
client_secret: 'secret', | ||
token: 'token', | ||
drive_type: OneDriveType.Personal, | ||
drive_id: 'driveid', | ||
}); | ||
|
||
const values = await form.getValues(); | ||
expect(values).toEqual({ | ||
'OAuth Client ID': 'client', | ||
'OAuth Client Secret': 'secret', | ||
|
||
'Access Token': 'token', | ||
'Drives List': '', | ||
'Drive Account Type': 'PERSONAL', | ||
'Drive ID': 'driveid', | ||
}); | ||
}); | ||
|
||
it('loads a list of OneDrive drives and populates Drives List select when oAuth flow is completed', async () => { | ||
const oauthComponent = spectator.query(OauthProviderComponent); | ||
oauthComponent.form.setValue({ | ||
client_id: 'newclient', | ||
client_secret: 'newsecret', | ||
}); | ||
oauthComponent.authenticated.emit({ | ||
token: 'newtoken', | ||
}); | ||
|
||
expect(spectator.inject(ApiService).call).toHaveBeenCalledWith('cloudsync.onedrive_list_drives', [{ | ||
client_id: 'newclient', | ||
client_secret: 'newsecret', | ||
token: 'newtoken', | ||
}]); | ||
|
||
const drivesSelect = await form.getControl('Drives List') as IxSelectHarness; | ||
expect(await drivesSelect.getOptionLabels()).toEqual([ | ||
'--', | ||
'ODCMetadataArchive - ODC Archived Metadata', | ||
'OneDrive', | ||
]); | ||
}); | ||
|
||
it('updates Drive Account Type and ID when a drive is selected from Drives List', async () => { | ||
const oauthComponent = spectator.query(OauthProviderComponent); | ||
oauthComponent.form.setValue({ | ||
client_id: 'newclient', | ||
client_secret: 'newsecret', | ||
}); | ||
oauthComponent.authenticated.emit({ | ||
token: 'newtoken', | ||
}); | ||
|
||
const drivesSelect = await form.getControl('Drives List') as IxSelectHarness; | ||
await drivesSelect.setValue('ODCMetadataArchive - ODC Archived Metadata'); | ||
|
||
const values = spectator.component.getSubmitAttributes(); | ||
expect(values).toMatchObject({ | ||
drive_id: 'business1', | ||
drive_type: OneDriveType.Business, | ||
}); | ||
}); | ||
|
||
it('returns form attributes for submission when getSubmitAttributes() is called', async () => { | ||
await form.fillForm({ | ||
'OAuth Client ID': 'newclient', | ||
'OAuth Client Secret': 'newsecret', | ||
|
||
'Access Token': 'newtoken', | ||
'Drive Account Type': 'PERSONAL', | ||
'Drive ID': 'driveid', | ||
}); | ||
|
||
const values = spectator.component.getSubmitAttributes(); | ||
expect(values).toEqual({ | ||
client_id: 'newclient', | ||
client_secret: 'newsecret', | ||
token: 'newtoken', | ||
drive_id: 'driveid', | ||
drive_type: OneDriveType.Personal, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.