Skip to content

Commit

Permalink
Show only valid profile in modal; fix condition to not download profi…
Browse files Browse the repository at this point in the history
…le if redirect button clicked (#569)
  • Loading branch information
sofyakurilova authored Jul 3, 2024
1 parent 10d311d commit cdf5847
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('DownloadReportZipComponent', () => {
tick();

expect(testrunServiceMock.downloadZip).toHaveBeenCalled();
expect(router.url).not.toBe(Routes.RiskAssessment);
openSpy.calls.reset();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export class DownloadReportZipComponent
}
if (profile === null) {
this.route.navigate([Routes.RiskAssessment]);
}

if (this.url != null) {
} else if (this.url != null) {
this.testrunService.downloadZip(this.getZipLink(this.url), profile);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DownloadZipModalComponent } from './download-zip-modal.component';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { PROFILE_MOCK, PROFILE_MOCK_2 } from '../../mocks/profile.mock';
import {
PROFILE_MOCK,
PROFILE_MOCK_2,
PROFILE_MOCK_3,
} from '../../mocks/profile.mock';
import { of } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TestRunService } from '../../services/test-run.service';
Expand Down Expand Up @@ -41,7 +45,7 @@ describe('DownloadZipModalComponent', () => {
TestBed.overrideProvider(MAT_DIALOG_DATA, {
useValue: {
hasProfiles: true,
profiles: [PROFILE_MOCK_2, PROFILE_MOCK],
profiles: [PROFILE_MOCK_2, PROFILE_MOCK, PROFILE_MOCK_3],
},
});

Expand Down Expand Up @@ -106,7 +110,7 @@ describe('DownloadZipModalComponent', () => {
closeSpy.calls.reset();
});

it('should have sorted profiles', async () => {
it('should have filtered and sorted profiles', async () => {
expect(component.profiles).toEqual([PROFILE_MOCK, PROFILE_MOCK_2]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
MatDialogRef,
} from '@angular/material/dialog';
import { EscapableDialogComponent } from '../escapable-dialog/escapable-dialog.component';
import { Profile, RiskResultClassName } from '../../model/profile';
import {
Profile,
ProfileStatus,
RiskResultClassName,
} from '../../model/profile';
import { MatButtonModule } from '@angular/material/button';
import { CommonModule, NgForOf, NgIf } from '@angular/common';
import { MatFormField } from '@angular/material/form-field';
Expand Down Expand Up @@ -47,7 +51,9 @@ export class DownloadZipModalComponent extends EscapableDialogComponent {
) {
super(dialogRef);
if (data.hasProfiles) {
this.profiles = [...data.profiles] as Profile[];
this.profiles = data.profiles.filter(
profile => profile.status === ProfileStatus.VALID
);
this.profiles.sort((a, b) =>
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
);
Expand Down
2 changes: 2 additions & 0 deletions modules/ui/src/app/mocks/profile.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export const PROFILE_MOCK: Profile = {
};

export const PROFILE_MOCK_2: Profile = {
status: ProfileStatus.VALID,
name: 'Second profile name',
questions: [],
};

export const PROFILE_MOCK_3: Profile = {
status: ProfileStatus.DRAFT,
name: 'Third profile name',
questions: [],
};
Expand Down

0 comments on commit cdf5847

Please sign in to comment.