-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accessiblity: Img tags missing alt tags + tests (#1483)
- Loading branch information
1 parent
771472c
commit 59acc62
Showing
8 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/components/file/details/image-file-viewer/image-file-viewer.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,57 @@ | ||
import { Component, DebugElement, NO_ERRORS_SCHEMA } from "@angular/core"; | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { By } from "@angular/platform-browser"; | ||
import { Subject, of } from "rxjs"; | ||
import { ImageFileViewerComponent } from "./image-file-viewer.component"; | ||
|
||
@Component({ | ||
template: `<bl-image-file-viewer [fileLoader]="fileLoader"></bl-image-file-viewer>`, | ||
}) | ||
class TestComponent { | ||
public fileLoader; | ||
} | ||
|
||
describe("ImageFileViewerComponent", () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
let testComponent: TestComponent; | ||
let de: DebugElement; | ||
let imgEl: DebugElement; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
declarations: [ImageFileViewerComponent, TestComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
}); | ||
|
||
fixture = TestBed.createComponent(TestComponent); | ||
testComponent = fixture.componentInstance; | ||
testComponent.fileLoader = { | ||
filename: "foo.png", | ||
fileChanged: new Subject(), | ||
cache: jasmine.createSpy().and.returnValue(of("/local/path/to/file.txt")), | ||
}; | ||
de = fixture.debugElement.query(By.css("bl-image-file-viewer")); | ||
fixture.detectChanges(); | ||
imgEl = de.query(By.css("img")); | ||
}); | ||
|
||
it("chache the image", () => { | ||
expect(testComponent.fileLoader.cache).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
it("point to the cached file locally", () => { | ||
expect(imgEl).not.toBeFalsy(); | ||
expect(imgEl.nativeElement.getAttribute("src")).toEqual("file:///local/path/to/file.txt"); | ||
}); | ||
|
||
it("it shows an alt text for the image", () => { | ||
expect(imgEl).not.toBeFalsy(); | ||
expect(imgEl.nativeElement.getAttribute("alt")).toEqual("Displaying image foo.png"); | ||
}); | ||
|
||
it("refresh again when file has changed", () => { | ||
testComponent.fileLoader.fileChanged.next(true); | ||
expect(testComponent.fileLoader.cache).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
app/components/file/details/image-file-viewer/image-file-viewer.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<bl-loading [status]="loadingStatus"> | ||
<div class="img-container"> | ||
<img [src]="src" *ngIf="src"> | ||
<img [src]="src" [alt]="imageDescription" *ngIf="src"> | ||
</div> | ||
</bl-loading> |
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
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