|
| 1 | +import {Constants} from "../../../../scripts/constants"; |
| 2 | + |
| 3 | +import {PdfPreviewPage, PdfPreviewPageProp} from "../../../../scripts/clipperUI/components/previewViewer/pdfPreviewPage"; |
| 4 | + |
| 5 | +import {HelperFunctions} from "../../../helperFunctions"; |
| 6 | + |
| 7 | +import {pdfDataUrls, pdfDataUrlDimensions} from "./pdfDataUrls"; |
| 8 | + |
| 9 | +QUnit.module("pdfPreviewPage", {}); |
| 10 | + |
| 11 | +test("Given that the page is selected, the image container's opacity should be set to 1", () => { |
| 12 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 13 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 14 | + imgUrl={pdfDataUrls[0]} index={0} showPageNumber={false} isSelected={true} />); |
| 15 | + |
| 16 | + let container = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.pdfPreviewImageCanvas)[0]; |
| 17 | + ok(!container.classList.contains(Constants.Classes.unselected), "The unselected class should not be applied to the container"); |
| 18 | + strictEqual(HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.unselected).length, 0, |
| 19 | + "The unselected class should not be applied anywhere"); |
| 20 | +}); |
| 21 | + |
| 22 | +test("Given that the page is not selected, the image container's opacity should be set to 0.3", () => { |
| 23 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 24 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 25 | + imgUrl={pdfDataUrls[0]} index={0} showPageNumber={false} isSelected={false} />); |
| 26 | + |
| 27 | + let container = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.pdfPreviewImageCanvas)[0]; |
| 28 | + ok(container.classList.contains(Constants.Classes.unselected), "The unselected class should be applied to the container"); |
| 29 | + strictEqual(HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.unselected).length, 1, |
| 30 | + "The unselected class should only be applied once in the component"); |
| 31 | +}); |
| 32 | + |
| 33 | +// Note: Because we fade out the page numbers using a css class, we check for opacity to determine if the number is in view |
| 34 | + |
| 35 | +test("Given that showPageNumber is true, the page number should be shown", () => { |
| 36 | + let index = 19; |
| 37 | + let expectedPageNumber = "" + (index + 1); |
| 38 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 39 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 40 | + imgUrl={pdfDataUrls[0]} index={index} showPageNumber={true} isSelected={true} />); |
| 41 | + |
| 42 | + let overlay = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.overlay)[0] as HTMLElement; |
| 43 | + strictEqual(overlay.innerText, expectedPageNumber, "The page number shown should be the index + 1"); |
| 44 | + ok(!overlay.classList.contains(Constants.Classes.overlayHidden), "The overlay should not be hidden"); |
| 45 | +}); |
| 46 | + |
| 47 | +test("Given that showPageNumber is true, but the page is not selected, the page number should still be shown", () => { |
| 48 | + let index = 19; |
| 49 | + let expectedPageNumber = "" + (index + 1); |
| 50 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 51 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 52 | + imgUrl={pdfDataUrls[0]} index={index} showPageNumber={true} isSelected={false} />); |
| 53 | + |
| 54 | + let overlay = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.overlay)[0] as HTMLElement; |
| 55 | + strictEqual(overlay.innerText, expectedPageNumber, "The page number shown should be the index + 1"); |
| 56 | + ok(!overlay.classList.contains(Constants.Classes.overlayHidden), "The overlay should not be hidden"); |
| 57 | +}); |
| 58 | + |
| 59 | +test("Given that showPageNumber is true, but the imgUrl is undefined, the page number should still be shown", () => { |
| 60 | + let index = 19; |
| 61 | + let expectedPageNumber = "" + (index + 1); |
| 62 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 63 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 64 | + index={index} showPageNumber={true} isSelected={true} />); |
| 65 | + |
| 66 | + let overlay = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.overlay)[0] as HTMLElement; |
| 67 | + strictEqual(overlay.innerText, expectedPageNumber, "The page number shown should be the index + 1"); |
| 68 | + ok(!overlay.classList.contains(Constants.Classes.overlayHidden), "The overlay should not be hidden"); |
| 69 | +}); |
| 70 | + |
| 71 | +test("Given that showPageNumber is true and the index is 0, the page number should be shown", () => { |
| 72 | + let index = 0; |
| 73 | + let expectedPageNumber = "" + (index + 1); |
| 74 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 75 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 76 | + imgUrl={pdfDataUrls[0]} index={index} showPageNumber={true} isSelected={true} />); |
| 77 | + |
| 78 | + let overlay = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.overlay)[0] as HTMLElement; |
| 79 | + strictEqual(overlay.innerText, expectedPageNumber, "The page number shown should be the index + 1"); |
| 80 | + ok(!overlay.classList.contains(Constants.Classes.overlayHidden), "The overlay should not be hidden"); |
| 81 | +}); |
| 82 | + |
| 83 | +test("Given that showPageNumber is false, the page number should not be shown", () => { |
| 84 | + let pdfPreviewPage = HelperFunctions.mountToFixture( |
| 85 | + <PdfPreviewPage viewportDimensions={{ width: 50, height: 50 }} |
| 86 | + imgUrl={pdfDataUrls[0]} index={10} showPageNumber={false} isSelected={true} />); |
| 87 | + |
| 88 | + let overlay = HelperFunctions.getFixture().getElementsByClassName(Constants.Classes.overlay)[0] as HTMLElement; |
| 89 | + ok(overlay.classList.contains(Constants.Classes.overlayHidden), "The overlay should be hidden"); |
| 90 | +}); |
0 commit comments