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 dfbd016
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 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
2 changes: 1 addition & 1 deletion src/services/utility-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function fileDownload(fileUrl, fileName, fileExt = '', machineGenerated =

// Handle download based on the URL format
// TODO:: research for a better way to handle this
if (!fileUrl.endsWith(extension)) {
if (fileUrl.endsWith('transcripts') || fileUrl.endsWith('captions')) {
// For URLs of format: http://.../<filename>.<file_extension>
fetch(fileUrl)
.then((response) => {
Expand Down

0 comments on commit dfbd016

Please sign in to comment.