Skip to content

Commit

Permalink
test: consolidated naming style for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gerdesque committed Nov 7, 2024
1 parent 3053413 commit 11ed210
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
40 changes: 21 additions & 19 deletions __tests__/CanvasDownloadLinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,21 @@ describe('CanvasDownloadLinks', () => {
expect(headingElement.tagName).toBe('H3');
});

it('renders canvas-level renderings', () => {
createWrapper({ canvas });
describe('Canvas Renderings', () => {
it('includes a canvas-level rendering as a download link', () => {
createWrapper({ canvas });

const downloadLink = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
expect(downloadLink).toBeInTheDocument();
const downloadLink = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
expect(downloadLink).toBeInTheDocument();
});
});

describe('Zoomed region link behavior', () => {
describe('Zoomed Region Links', () => {
const infoResponse = {
json: { width: 4000, height: 1000 },
};

it('does not render a zoom link when the viewer is zoomed out to the entire image', () => {
it('does not render a zoom link when viewer is zoomed out to full image', () => {
currentBoundsSpy.mockImplementation(() => ({
x: 0, y: 0, width: 6000, height: 1000,
}));
Expand All @@ -81,7 +83,7 @@ describe('CanvasDownloadLinks', () => {
expect(zoomedLink).not.toBeInTheDocument();
});

it('does not render a link when zoomed into non-image space', () => {
it('does not render a zoom link when zoomed into an area outside of the image bounds', () => {
currentBoundsSpy.mockImplementation(() => ({
x: -100, y: 100, width: 2000, height: 500,
}));
Expand All @@ -92,7 +94,7 @@ describe('CanvasDownloadLinks', () => {
expect(zoomedLink).not.toBeInTheDocument();
});

it('renders a zoomed region link when zoomed into the image', () => {
it('renders a zoomed region link when zoomed into a valid area of the image', () => {
currentBoundsSpy.mockImplementation(() => ({
x: 0, y: 0, width: 2000, height: 500,
}));
Expand All @@ -103,7 +105,7 @@ describe('CanvasDownloadLinks', () => {
expect(zoomedLink).toBeInTheDocument();
});

it('does not render a zoomed region link in non-single view types (e.g., book or gallery view)', () => {
it('does not render a zoomed region link in non-single view types (e.g., book, gallery views)', () => {
currentBoundsSpy.mockImplementation(() => ({
x: 0, y: 0, width: 2000, height: 500,
}));
Expand All @@ -121,8 +123,8 @@ describe('CanvasDownloadLinks', () => {
expect(zoomedLinkGallery).not.toBeInTheDocument();
});

describe('when zoom link is restricted', () => {
it('only renders a whole image link based on the available sizes', () => {
describe('Download Link Size Restrictions', () => {
it('renders only a single download link based on the restricted sizes', () => {
createWrapper({
canvas,
infoResponse: {
Expand All @@ -143,7 +145,7 @@ describe('CanvasDownloadLinks', () => {
});
});

describe('when sizes are defined in the infoResponse', () => {
describe('When Defined Sizes Are Present in infoResponse', () => {
const sizes = [
{ width: 4000, height: 1000 },
{ width: 2000, height: 500 },
Expand All @@ -158,7 +160,7 @@ describe('CanvasDownloadLinks', () => {
OSDReferences.set('wid123', {
current: { viewport },
});
it('renders download links for all sizes in the dialog', () => {
it('renders download links for all specified sizes in the dialog', () => {
createWrapper({ canvas, infoResponse: { json: { sizes } } });

const link1 = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
Expand All @@ -171,17 +173,17 @@ describe('CanvasDownloadLinks', () => {
});
});

describe('when no sizes are defined', () => {
it('renders a link to the full-size image', () => {
describe('When No Sizes Are Defined in infoResponse', () => {
it('renders a single link to the full-size image', () => {
createWrapper({ canvas });

const link = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/full/0/default.jpg?download=true');
});

describe('when the image width exceeds 1000px', () => {
it('renders links to both the full-size and smaller (1000px wide) versions', () => {
describe('For Images Wider Than 1000px', () => {
it('renders links for both full-size and 1000px wide versions', () => {
createWrapper({ canvas });

const link1 = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
Expand All @@ -192,8 +194,8 @@ describe('CanvasDownloadLinks', () => {
});
});

describe('when the image width is less than 1000px', () => {
it('does not render a link to a smaller version', () => {
describe('For Images Less Than 1000px Wide', () => {
it('does not render a smaller version link if image is under 1000px wide', () => {
canvas.getWidth = () => 999;
createWrapper({ canvas });

Expand Down
4 changes: 2 additions & 2 deletions __tests__/ManifestDownloadLinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ManifestDownloadLinks', () => {
},
];

it('renders the heading', () => {
it('displays the heading "Other download options" as an H3 element', () => {
createWrapper({ renderings });

screen.getByRole('heading');
Expand All @@ -35,7 +35,7 @@ describe('ManifestDownloadLinks', () => {
expect(headingElement.tagName).toBe('H3');
});

it('renders a RenderingDownloadLink for each rendering', () => {
it('renders a download link for each item in the renderings list', () => {
createWrapper({ renderings });

const pdfLinkElement = screen.getByRole('link', { name: /Link to the PDF/i });
Expand Down
13 changes: 7 additions & 6 deletions __tests__/MiradorDownloadDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ function createWrapper(props) {
}

describe('Dialog', () => {
it('does not render anything if the open prop is false', () => {
it('does not render content when the open prop is false', () => {
createWrapper({ open: false });
expect(screen.queryByTestId('dialog-content')).toBeNull();
});

it('renders a CanvasDownloadLinks component for every canvas', () => {
it('renders a CanvasDownloadLinks component with headings for each canvas', () => {
const mockCanvas = (id) => ({
id,
getHeight: () => 4000,
Expand All @@ -47,7 +47,7 @@ describe('Dialog', () => {
expect(headingXyz.tagName).toBe('H3');
});

it('has a close button that triggers the closeDialog prop', async () => {
it('calls the closeDialog function when the close button is clicked', async () => {
const closeDialog = jest.fn();
createWrapper({ closeDialog });
const closeButton = await screen.findByText(/Close/);
Expand All @@ -56,12 +56,13 @@ describe('Dialog', () => {
});

describe('ManifestDownloadLinks', () => {
it('is not rendered if the manifest has no renderings', () => {
it('does not render when there are no manifest renderings', () => {
createWrapper();
const manifestLinks = screen.queryByText('ManifestDownloadLinks');
expect(manifestLinks).not.toBeInTheDocument();
});
it('rendered if the manifest has renderings', () => {

it('renders when the manifest contains renderings', () => {
const rendering = { id: '', getLabel: () => ({ getValue: () => 'ManifestDownloadLinks' }), getFormat: () => {} };
createWrapper({
manifest: {
Expand Down Expand Up @@ -151,7 +152,7 @@ describe('mapStateToProps', () => {
const mapStateToProps = miradorDownloadDialog.mapStateToProps(state, props);

describe('infoResponse', () => {
it('gets the correct info response from state', () => {
it('fetches the correct info response for the given canvas ID', () => {
expect(mapStateToProps.infoResponse('http://example.com/abc123/canvas/0').json.sizes.length).toBe(6);
});
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/RenderingDownloadLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ describe('RenderingDownloadLink', () => {
getFormat: () => ({ value: 'application/pdf' }),
};

it('renders a Link for the rendering', () => {
it('displays a download link with the label text from the rendering', () => {
createWrapper({ rendering });

const link = screen.getByRole('link', { name: /Link to the PDF/i });
expect(link).toBeInTheDocument();
});

it('links the label and includes the format (unlinked)', () => {
it('renders the download link with the correct URL and format information', () => {
createWrapper({ rendering });

const link = screen.getByRole('link', { name: /Link to the PDF/i });
Expand Down
8 changes: 4 additions & 4 deletions __tests__/miradorDownloadPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function createWrapper(props) {
}

describe('miradorDownloadPlugin', () => {
it('has the correct target', () => {
it('sets the correct target to "WindowTopBarPluginMenu"', () => {
expect(miradorDownloadPlugin.target).toBe('WindowTopBarPluginMenu');
});
describe('renders a component', () => {
it('renders a thing', () => {
describe('Component Rendering', () => {
it('displays a "Download" element when rendered', () => {
createWrapper();
const downloadElement = screen.queryByText(/Download/i);
expect(downloadElement).toBeInTheDocument();
Expand All @@ -26,7 +26,7 @@ describe('miradorDownloadPlugin', () => {
});

describe('MenuItem', () => {
it('calls the openShareDialog and handleClose props when clicked', async () => {
it('triggers both openDownloadDialog and handleClose when "Download" is clicked', async () => {
const handleClose = jest.fn();
const openDownloadDialog = jest.fn();
createWrapper({ handleClose, openDownloadDialog });
Expand Down

0 comments on commit 11ed210

Please sign in to comment.