Skip to content

Commit

Permalink
Reabsed from main and fixed broken code from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Dananji committed Jul 18, 2023
1 parent 42caf74 commit 7ddca07
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/SupplementalFiles/SupplementalFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SupplementalFiles = ({ itemHeading = "Item files", sectionHeading = "Secti

const handleDownload = (event, file) => {
event.preventDefault();
fileDownload(file.id, file.filename);
fileDownload(file.id, file.filename, file.fileExt);
};

return (
Expand Down
7 changes: 4 additions & 3 deletions src/components/SupplementalFiles/SupplementalFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ describe('SupplementalFiles', () => {
expect(screen.queryByTestId('supplemental-files-empty')).not.toBeInTheDocument();
});
test('renders file labels', () => {
expect(screen.getByText('Captions in WebVTT format (.vtt)')).toBeInTheDocument();
expect(screen.queryAllByText('Captions in WebVTT format (.vtt)')).toHaveLength(2);
expect(screen.getByText('Transcript file (.vtt)')).toBeInTheDocument();
});
test('file download is invoked by clicking on links', () => {
let fileDownloadMock = jest.spyOn(utils, 'fileDownload')
.mockImplementation(jest.fn());
let fileLink = screen.getByText('Captions in WebVTT format (.vtt)');
let fileLink = screen.getAllByText('Captions in WebVTT format (.vtt)')[0];
expect(fileLink.getAttribute('href')).toEqual('https://example.com/manifest/lunchroom_manners.vtt');

// Click on file link
Expand All @@ -36,7 +36,8 @@ describe('SupplementalFiles', () => {
expect(fileDownloadMock).toHaveBeenCalledTimes(1);
expect(fileDownloadMock).toHaveBeenCalledWith(
'https://example.com/manifest/lunchroom_manners.vtt',
'Captions in WebVTT format'
'Captions in WebVTT format',
'vtt'
);
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/services/iiif-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export function getRenderingFiles(manifest) {
id: id,
label: `${filename} (.${extension})`,
filename: filename,
fileExt: extension,
};
return file;
};
Expand All @@ -429,7 +430,7 @@ export function getRenderingFiles(manifest) {
}
// Use label of canvas or fallback to canvas id
let canvasLabel = canvas.getLabel().getValues()[0] || "Section " + (index + 1);
canvasFiles.push({label: getLabelValue(canvasLabel), files: files});
canvasFiles.push({ label: getLabelValue(canvasLabel), files: files });
});

return { manifest: manifestFiles, canvas: canvasFiles };
Expand All @@ -448,6 +449,7 @@ export function getSupplementingFiles(manifest) {
id: id,
label: `${filename} (.${extension})`,
filename: filename,
fileExt: extension,
};
return file;
};
Expand All @@ -459,7 +461,7 @@ export function getSupplementingFiles(manifest) {
if (annotationJSON?.length) {
const annotationPage = annotationJSON[0];
if (annotationPage) {
annotations = annotationPage.items.filter( annotation => annotation.motivation == "supplementing" && annotation.body.id );
annotations = annotationPage.items.filter(annotation => annotation.motivation == "supplementing" && annotation.body.id);
}
}

Expand All @@ -471,7 +473,7 @@ export function getSupplementingFiles(manifest) {

// Use label of canvas or fallback to canvas id
let canvasLabel = canvas.getLabel().getValues()[0] || "Section " + (index + 1);
canvasFiles.push({label: getLabelValue(canvasLabel), files: files});
canvasFiles.push({ label: getLabelValue(canvasLabel), files: files });
});

return canvasFiles;
Expand Down
6 changes: 3 additions & 3 deletions src/services/iiif-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('iiif-parser', () => {

describe('getSupplementingFiles()', () => {
it('with `TextualBody` supplementing annotations', () => {
const files = iiifParser.getSupplementingFiles(manifest, 0);
const files = iiifParser.getSupplementingFiles(manifest);
expect(files.length).toBe(2);
expect(files[0].label).toBe('Section 1');
expect(files[0].files.length).toBe(0);
Expand All @@ -391,14 +391,14 @@ describe('iiif-parser', () => {
});

it('with supplementing annotations', () => {
const files = iiifParser.getSupplementingFiles(lunchroomManifest, 0);
const files = iiifParser.getSupplementingFiles(lunchroomManifest);
expect(files.length).toBe(2);
expect(files[0].label).toBe('Lunchroom Manners');
expect(files[0].files.length).toBe(1);
expect(files[0].files[0].label).toEqual('Captions in WebVTT format (.vtt)');
expect(files[0].files[0].filename).toEqual('Captions in WebVTT format');
expect(files[1].label).toBe('Section 2');
expect(files[1].files.length).toBe(0);
expect(files[1].files.length).toBe(2);
});
});

Expand Down

0 comments on commit 7ddca07

Please sign in to comment.