Skip to content

Commit

Permalink
[CST-5329] Add validate only check in the Import > Metadata page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sufiyan Shaikh committed Mar 10, 2022
1 parent 22d2c9e commit 2ffb723
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
@@ -1,6 +1,10 @@
<div class="container">
<h2 id="header">{{'admin.metadata-import.page.header' | translate}}</h2>
<p>{{'admin.metadata-import.page.help' | translate}}</p>
<p>
<input type="checkbox" [(ngModel)]="validateOnly" />
<span class="ml-2">{{'admin.metadata-import.page.validateOnly' | translate}}</span>
</p>

<ds-file-dropzone-no-uploader
(onFileAdded)="setFile($event)"
Expand Down
Expand Up @@ -87,8 +87,9 @@ describe('MetadataImportPageComponent', () => {
comp.setFile(fileMock);
});

describe('if proceed button is pressed', () => {
describe('if proceed button is pressed without validate only', () => {
beforeEach(fakeAsync(() => {
comp.validateOnly = false;
const proceed = fixture.debugElement.query(By.css('#proceedButton')).nativeElement;
proceed.click();
fixture.detectChanges();
Expand All @@ -107,6 +108,28 @@ describe('MetadataImportPageComponent', () => {
});
});

describe('if proceed button is pressed with validate only', () => {
beforeEach(fakeAsync(() => {
comp.validateOnly = true;
const proceed = fixture.debugElement.query(By.css('#proceedButton')).nativeElement;
proceed.click();
fixture.detectChanges();
}));
it('metadata-import script is invoked with -f fileName and the mockFile and -v validate-only', () => {
const parameterValues: ProcessParameter[] = [
Object.assign(new ProcessParameter(), { name: '-f', value: 'filename.txt' }),
Object.assign(new ProcessParameter(), { name: '-v', value: true }),
];
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [fileMock]);
});
it('success notification is shown', () => {
expect(notificationService.success).toHaveBeenCalled();
});
it('redirected to process page', () => {
expect(router.navigateByUrl).toHaveBeenCalledWith('/processes/45');
});
});

describe('if proceed is pressed; but script invoke fails', () => {
beforeEach(fakeAsync(() => {
jasmine.getEnv().allowRespy(true);
Expand Down
Expand Up @@ -30,6 +30,11 @@ export class MetadataImportPageComponent {
*/
fileObject: File;

/**
* The validate only flag
*/
validateOnly = true;

public constructor(private location: Location,
protected translate: TranslateService,
protected notificationsService: NotificationsService,
Expand Down Expand Up @@ -62,6 +67,9 @@ export class MetadataImportPageComponent {
const parameterValues: ProcessParameter[] = [
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
];
if (this.validateOnly) {
parameterValues.push(Object.assign(new ProcessParameter(), { name: '-v', value: true }));
}

this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]).pipe(
getFirstCompletedRemoteData(),
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json5
Expand Up @@ -538,6 +538,8 @@

"admin.metadata-import.page.error.addFile": "Select file first!",

"admin.metadata-import.page.validateOnly": "Validate Only",




Expand Down

0 comments on commit 2ffb723

Please sign in to comment.