Skip to content

Commit

Permalink
Add translations back in and check dropdown urls, instead of text, as…
Browse files Browse the repository at this point in the history
… translations aren't in scope in the tests.
  • Loading branch information
lfarrell committed Nov 5, 2024
1 parent 3ea8a9e commit 3f78b78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a @click.prevent="modal_open = true" class="download login-modal-link button action" href="#">Contact Wilson/Log in to access</a>
</div>
<div v-else-if="showNonImageDownload(recordData)" class="actionlink download">
<a class="download button action" :href="nonImageDownloadLink(recordData.id)"><i class="fa fa-download"></i> Download</a>
<a class="download button action" :href="nonImageDownloadLink(recordData.id)"><i class="fa fa-download"></i> {{ t('full_record.download') }}</a>
</div>
<div v-else-if="showImageDownload(recordData) && hasDownloadOptions(recordData)" class="dropdown actionlink download image-download-options">
<div class="dropdown actionlink download image-download-options">
Expand All @@ -14,13 +14,13 @@
</div>
<div class="dropdown-menu table-downloads" :class="{ 'show-list': download_options_open }" id="dropdown-menu" role="menu" :aria-hidden="!download_options_open">
<div class="dropdown-content">
<a v-if="validSizeOption(recordData, 800)" :href="imgDownloadLink(recordData.id, '800')" class="dropdown-item">Small JPG (800px)</a>
<a v-if="validSizeOption(recordData, 1600)" :href="imgDownloadLink(recordData.id, '1600')" class="dropdown-item">Medium JPG (1600px)</a>
<a v-if="validSizeOption(recordData, 2500)" :href="imgDownloadLink(recordData.id, '2500')" class="dropdown-item">Large JPG (2500px)</a>
<a v-if="validSizeOption(recordData, 800)" :href="imgDownloadLink(recordData.id, '800')" class="dropdown-item">{{ t('full_record.small') }} JPG (800px)</a>
<a v-if="validSizeOption(recordData, 1600)" :href="imgDownloadLink(recordData.id, '1600')" class="dropdown-item">{{ t('full_record.medium') }} JPG (1600px)</a>
<a v-if="validSizeOption(recordData, 2500)" :href="imgDownloadLink(recordData.id, '2500')" class="dropdown-item">{{ t('full_record.large') }} JPG (2500px)</a>
<template v-if="hasPermission(recordData, 'viewOriginal')">
<a :href="imgDownloadLink(recordData.id, 'max')" class="dropdown-item">Full Size JPG</a>
<a :href="imgDownloadLink(recordData.id, 'max')" class="dropdown-item">{{ t('full_record.full_size') }} JPG</a>
<hr class="dropdown-divider">
<a :href="originalImgDownloadLink(recordData.id)" class="dropdown-item">Original File</a>
<a :href="originalImgDownloadLink(recordData.id)" class="dropdown-item">{{ t('full_record.original_file') }}</a>
</template>
</div>
</div>
Expand Down
51 changes: 26 additions & 25 deletions static/js/vue-cdr-access/tests/unit/downloadOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const record = {
]
}

const uuid = '4db695c0-5fd5-4abf-9248-2e115d43f57d';

const div = document.createElement('div')
div.id = 'document'
document.body.appendChild(div);


let wrapper, store;

describe('downloadOption.vue', () => {
Expand Down Expand Up @@ -109,49 +110,49 @@ describe('downloadOption.vue', () => {

it('displays a download button with all download options for image with viewOriginal', async () => {
const updated_data = cloneDeep(record);
updated_data.dataFileUrl = 'content/4db695c0-5fd5-4abf-9248-2e115d43f57d';
updated_data.dataFileUrl = `content/${uuid}`;
updated_data.resourceType = 'File';
await setRecordPermissions(updated_data, ['viewAccessCopies', 'viewReducedResImages', 'viewOriginal']);

expect(wrapper.find('.dropdown-menu').exists()).toBe(true);
await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Small JPG (800px)');
expect(dropdown_items[1].text()).toEqual('Medium JPG (1600px)');
expect(dropdown_items[2].text()).toEqual('Large JPG (2500px)');
expect(dropdown_items[3].text()).toEqual('Full Size JPG');
expect(dropdown_items[4].text()).toEqual('Original File');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/800`);
expect(dropdown_items[1].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/1600`);
expect(dropdown_items[2].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/2500`);
expect(dropdown_items[3].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/max`);
expect(dropdown_items[4].attributes('href')).toEqual(`/content/${uuid}?dl=true`);
expect(dropdown_items.length).toEqual(5);
});

it('displays a download button with reduced download options for image with only viewReducedResImages', async () => {
const updated_data = cloneDeep(record);
updated_data.dataFileUrl = 'content/4db695c0-5fd5-4abf-9248-2e115d43f57d';
updated_data.dataFileUrl = `content/${uuid}`;
updated_data.resourceType = 'File';
await setRecordPermissions(updated_data, ['viewAccessCopies', 'viewReducedResImages']);

expect(wrapper.find('.dropdown-menu').exists()).toBe(true);

await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Small JPG (800px)');
expect(dropdown_items[1].text()).toEqual('Medium JPG (1600px)');
expect(dropdown_items[2].text()).toEqual('Large JPG (2500px)');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/800`);
expect(dropdown_items[1].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/1600`);
expect(dropdown_items[2].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/2500`);
expect(dropdown_items.length).toEqual(3);
});

it('shows a download button with no reduced download options when viewOriginal set and image is smaller than min size', async () => {
const updated_data = cloneDeep(record);
updated_data.dataFileUrl = 'content/4db695c0-5fd5-4abf-9248-2e115d43f57d';
updated_data.dataFileUrl = `content/${uuid}`;
updated_data.resourceType = 'File';
updated_data.datastream[1] = "original_file|image/jpeg|tinyz||69490|urn:sha1:0d48dadb5d61ae0d41b4998280a3c39577a2f94a||640x480";
await setRecordPermissions(updated_data, ['viewAccessCopies', 'viewReducedResImages', 'viewOriginal']);

expect(wrapper.find('.dropdown-menu').exists()).toBe(true);
await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Full Size JPG');
expect(dropdown_items[1].text()).toEqual('Original File');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/max`);
expect(dropdown_items[1].attributes('href')).toEqual(`/content/${uuid}?dl=true`);
expect(dropdown_items.length).toEqual(2);
});

Expand All @@ -167,16 +168,16 @@ describe('downloadOption.vue', () => {

it('shows a download button with partial reduced download options with viewReducedResImages when image is smaller than largest size', async () => {
const updated_data = cloneDeep(record);
updated_data.dataFileUrl = 'content/4db695c0-5fd5-4abf-9248-2e115d43f57d';
updated_data.dataFileUrl = `content/${uuid}`;
updated_data.resourceType = 'File';
updated_data.datastream[1] = "original_file|image/jpeg|midz||69490|urn:sha1:0d48dadb5d61ae0d41b4998280a3c39577a2f94a||1700x1200";
await setRecordPermissions(updated_data, ['viewAccessCopies', 'viewReducedResImages']);

expect(wrapper.find('.dropdown-menu').exists()).toBe(true);
await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Small JPG (800px)');
expect(dropdown_items[1].text()).toEqual('Medium JPG (1600px)');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/800`);
expect(dropdown_items[1].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/1600`);
expect(dropdown_items.length).toEqual(2);
});

Expand Down Expand Up @@ -204,9 +205,9 @@ describe('downloadOption.vue', () => {
expect(wrapper.find('.dropdown-menu').exists()).toBe(true);
await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Small JPG (800px)');
expect(dropdown_items[1].text()).toEqual('Full Size JPG');
expect(dropdown_items[2].text()).toEqual('Original File');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/800`);
expect(dropdown_items[1].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/max`);
expect(dropdown_items[2].attributes('href')).toEqual(`/content/${uuid}?dl=true`);
expect(dropdown_items.length).toEqual(3);
});

Expand All @@ -221,11 +222,11 @@ describe('downloadOption.vue', () => {
expect(wrapper.find('.dropdown-menu').exists()).toBe(true);
await wrapper.find('button.download-images').trigger('click'); // Open
const dropdown_items = wrapper.findAll('.dropdown-item');
expect(dropdown_items[0].text()).toEqual('Small JPG (800px)');
expect(dropdown_items[1].text()).toEqual('Medium JPG (1600px)');
expect(dropdown_items[2].text()).toEqual('Large JPG (2500px)');
expect(dropdown_items[3].text()).toEqual('Full Size JPG');
expect(dropdown_items[4].text()).toEqual('Original File');
expect(dropdown_items[0].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/800`);
expect(dropdown_items[1].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/1600`);
expect(dropdown_items[2].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/2500`);
expect(dropdown_items[3].attributes('href')).toEqual(`/services/api/downloadImage/${uuid}/max`);
expect(dropdown_items[4].attributes('href')).toEqual(`/content/${uuid}?dl=true`);
expect(dropdown_items.length).toEqual(5);
});

Expand Down

0 comments on commit 3f78b78

Please sign in to comment.