-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create UI for single use links (#1638)
* Create UI for single use links * Add tests and pin copy messages to the top of the visible page
- Loading branch information
Showing
7 changed files
with
271 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
static/js/vue-cdr-access/src/components/full_record/singleUseLink.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<template> | ||
<div class="header-button-single-download"> | ||
<div class="actionlink single-download"> | ||
<div class="single-use-msg-text" :class="{'display-msg': this.message !== ''}"> | ||
{{ this.message }} | ||
</div> | ||
<a class="button action" id="single-use-link" href="#" @click.prevent="createLink()">{{ $t('full_record.download_single_use') }}</a> | ||
<ul> | ||
<li v-for="single_use_link in single_use_links"> | ||
<div class="download-link-wrapper"> | ||
<div>{{ $t('full_record.created_link', { link: single_use_link.link, expire_time: single_use_link.expires }) }}</div> | ||
<a @click.prevent="copyUrl(single_use_link.link)" href="#" class="download button action">Copy</a> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import axios from 'axios'; | ||
export default { | ||
name: 'singleUseLink', | ||
props: { | ||
uuid: String | ||
}, | ||
data() { | ||
return { | ||
single_use_links: [], | ||
message: '' | ||
} | ||
}, | ||
methods: { | ||
createLink() { | ||
axios({ | ||
method: 'post', | ||
url: `/services/api/single_use_link/create/${this.uuid}` | ||
}).then((response) => { | ||
this.single_use_links.push(response.data) | ||
}).catch((error) => { | ||
console.log(error); | ||
this.message = this.$t('full_record.created_link_failed', { uuid: this.uuid}); | ||
this.fadeOutMsg(); | ||
}); | ||
}, | ||
async copyUrl(text) { | ||
try { | ||
await navigator.clipboard.writeText(text); | ||
this.message = this.$t('full_record.copied_link', { text: text}); | ||
} catch(err) { | ||
this.message = this.$t('full_record.copied_link_failed', { text: text}); | ||
} | ||
this.fadeOutMsg(); | ||
}, | ||
fadeOutMsg() { | ||
setTimeout(() => this.message = '', 3000); | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.header-button-single-download { | ||
text-align: right; | ||
.single-download { | ||
display: block; | ||
a { | ||
float: right; | ||
max-width: 210px; | ||
} | ||
ul { | ||
margin-top: 10px; | ||
li { | ||
.download-link-wrapper { | ||
align-items: center; | ||
display: inline-flex; | ||
margin: 5px auto; | ||
div { | ||
background-color: white; | ||
padding: 15px; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.single-use-msg-text { | ||
display: none; | ||
} | ||
.display-msg { | ||
background: white; | ||
border: 1px solid; | ||
border-radius: 5px; | ||
display: block; | ||
height: auto; | ||
padding: 5px; | ||
position: fixed; | ||
right: 10px; | ||
text-align: center; | ||
top: 10px; | ||
width: 250px; | ||
z-index: 599; | ||
} | ||
} | ||
@media (max-width: 768px) { | ||
.header-button-single-download { | ||
text-align: left; | ||
.single-download { | ||
display: block; | ||
a { | ||
float: none; | ||
} | ||
ul { | ||
li { | ||
margin-left: 0; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import singleUseLink from '@/components/full_record/singleUseLink.vue'; | ||
import {createI18n} from 'vue-i18n'; | ||
import translations from '@/translations'; | ||
import moxios from 'moxios'; | ||
|
||
const uuid = '9f7f3746-0237-4261-96a2-4b4765d4ae03'; | ||
const response_date = { link: `https://test.edu`, expires: '24hrs', id: uuid }; | ||
let wrapper; | ||
|
||
describe('singleUseLink.vue', () => { | ||
const i18n = createI18n({ | ||
locale: 'en', | ||
fallbackLocale: 'en', | ||
messages: translations | ||
}); | ||
|
||
beforeEach(() => { | ||
wrapper = shallowMount(singleUseLink, { | ||
global: { | ||
plugins: [i18n] | ||
}, | ||
props: { | ||
uuid: '9f7f3746-0237-4261-96a2-4b4765d4ae03' | ||
} | ||
}); | ||
|
||
moxios.install(); | ||
}); | ||
|
||
afterEach(function () { | ||
moxios.uninstall(); | ||
}); | ||
|
||
it("creates single use links", (done) => { | ||
expect(wrapper.find('.download-link-wrapper').exists()).toBe(false); | ||
|
||
moxios.stubRequest(`/services/api/single_use_link/create/${uuid}`, { | ||
status: 200, | ||
response: JSON.stringify(response_date) | ||
}); | ||
|
||
moxios.wait(async () => { | ||
await wrapper.find('#single-use-link').trigger('click'); | ||
expect(wrapper.find('.download-link-wrapper').exists()).toBe(true); | ||
expect(wrapper.find('.download-link-wrapper div').text()) | ||
.toEqual(`Created link ${response_date.link} expires in ${response_date.expires}`); | ||
expect(wrapper.find('.download-link-wrapper a').exists()).toBe(true); // Copy button | ||
done(); | ||
}); | ||
}); | ||
|
||
it("does not create single use links on response errors", (done) => { | ||
expect(wrapper.find('.download-link-wrapper').exists()).toBe(false); | ||
|
||
moxios.stubRequest(`/services/api/single_use_link/create/${uuid}`, { | ||
status: 404, | ||
response: JSON.stringify('No record here') | ||
}); | ||
|
||
moxios.wait(async () => { | ||
await wrapper.find('#single-use-link').trigger('click'); | ||
expect(wrapper.find('.download-link-wrapper').exists()).toBe(false); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("copies single use links", async () => { | ||
Object.assign(window.navigator, { | ||
clipboard: { | ||
writeText: jest.fn().mockImplementation(() => Promise.resolve()), | ||
}, | ||
}); | ||
|
||
await wrapper.setData({ single_use_links: [response_date] }); | ||
await wrapper.find('.download-link-wrapper a').trigger('click'); | ||
expect(window.navigator.clipboard.writeText) | ||
.toHaveBeenCalledWith(response_date.link); | ||
}); | ||
}); |