88507 Improved test

- Refactored the test for the download button
- This way we're checking the actual href on the button, not the component's property
This commit is contained in:
Jens Vannerum
2022-03-17 11:49:53 +01:00
parent 4a8f6c357f
commit f00664b281
2 changed files with 7 additions and 3 deletions

View File

@@ -20,7 +20,8 @@
<div class="btn-group relationship-action-buttons"> <div class="btn-group relationship-action-buttons">
<a *ngIf="bitstreamDownloadUrl != null" [href]="bitstreamDownloadUrl" <a *ngIf="bitstreamDownloadUrl != null" [href]="bitstreamDownloadUrl"
class="btn btn-outline-primary btn-sm" class="btn btn-outline-primary btn-sm"
title="{{'item.edit.bitstreams.edit.buttons.download' | translate}}"> title="{{'item.edit.bitstreams.edit.buttons.download' | translate}}"
data-test="download-button">
<i class="fas fa-download fa-fw"></i> <i class="fas fa-download fa-fw"></i>
</a> </a>
<button [routerLink]="['/bitstreams/', bitstream.id, 'edit']" class="btn btn-outline-primary btn-sm" <button [routerLink]="['/bitstreams/', bitstream.id, 'edit']" class="btn btn-outline-primary btn-sm"

View File

@@ -11,6 +11,7 @@ import { ResponsiveTableSizes } from '../../../../shared/responsive-table-sizes/
import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes'; import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes';
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
import { getBitstreamDownloadRoute } from '../../../../app-routing-paths'; import { getBitstreamDownloadRoute } from '../../../../app-routing-paths';
import { By } from '@angular/platform-browser';
let comp: ItemEditBitstreamComponent; let comp: ItemEditBitstreamComponent;
let fixture: ComponentFixture<ItemEditBitstreamComponent>; let fixture: ComponentFixture<ItemEditBitstreamComponent>;
@@ -119,8 +120,10 @@ describe('ItemEditBitstreamComponent', () => {
}); });
describe('when the component loads', () => { describe('when the component loads', () => {
it('should contain bitstreamDownloadUrl with the correct url to the bitstream\'s download page', () => { it('the download button should contain the link to the bitstreams download page', () => {
expect(comp.bitstreamDownloadUrl).toEqual(getBitstreamDownloadRoute(bitstream)); fixture.detectChanges();
const downloadBtnHref = fixture.debugElement.query(By.css('[data-test="download-button"]')).nativeElement.getAttribute('href');
expect(downloadBtnHref).toEqual(comp.bitstreamDownloadUrl);
}); });
}); });
}); });