Commit 356a37cf authored by Phil Hughes's avatar Phil Hughes

added spec to new file dropdown

parent abccda6f
<script> <script>
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import icon from '~/vue_shared/components/icon.vue'; import icon from '~/vue_shared/components/icon.vue';
import newModal from './modal.vue'; import newModal from './modal.vue';
import upload from './upload.vue'; import upload from './upload.vue';
export default { export default {
components: { components: {
icon, icon,
newModal, newModal,
upload, upload,
},
props: {
branch: {
type: String,
required: true,
}, },
props: { path: {
branch: { type: String,
type: String, required: true,
required: true,
},
path: {
type: String,
required: true,
},
}, },
data() { },
return { data() {
openModal: false, return {
modalType: '', openModal: false,
dropdownOpen: false, modalType: '',
}; dropdownOpen: false,
};
},
watch: {
dropdownOpen() {
this.$nextTick(() => {
this.$refs.dropdownMenu.scrollIntoView();
});
}, },
watch: { },
dropdownOpen() { methods: {
this.$nextTick(() => { ...mapActions(['createTempEntry']),
this.$refs.dropdownMenu.scrollIntoView(); createNewItem(type) {
}); this.modalType = type;
}, this.openModal = true;
this.dropdownOpen = false;
}, },
methods: { hideModal() {
...mapActions([ this.openModal = false;
'createTempEntry',
]),
createNewItem(type) {
this.modalType = type;
this.openModal = true;
this.dropdownOpen = false;
},
hideModal() {
this.openModal = false;
},
openDropdown() {
this.dropdownOpen = !this.dropdownOpen;
},
}, },
}; openDropdown() {
this.dropdownOpen = !this.dropdownOpen;
},
},
};
</script> </script>
<template> <template>
......
...@@ -32,12 +32,8 @@ describe('new dropdown component', () => { ...@@ -32,12 +32,8 @@ describe('new dropdown component', () => {
it('renders new file, upload and new directory links', () => { it('renders new file, upload and new directory links', () => {
expect(vm.$el.querySelectorAll('a')[0].textContent.trim()).toBe('New file'); expect(vm.$el.querySelectorAll('a')[0].textContent.trim()).toBe('New file');
expect(vm.$el.querySelectorAll('a')[1].textContent.trim()).toBe( expect(vm.$el.querySelectorAll('a')[1].textContent.trim()).toBe('Upload file');
'Upload file', expect(vm.$el.querySelectorAll('a')[2].textContent.trim()).toBe('New directory');
);
expect(vm.$el.querySelectorAll('a')[2].textContent.trim()).toBe(
'New directory',
);
}); });
describe('createNewItem', () => { describe('createNewItem', () => {
...@@ -81,4 +77,18 @@ describe('new dropdown component', () => { ...@@ -81,4 +77,18 @@ describe('new dropdown component', () => {
.catch(done.fail); .catch(done.fail);
}); });
}); });
describe('dropdownOpen', () => {
it('scrolls dropdown into view', done => {
spyOn(vm.$refs.dropdownMenu, 'scrollIntoView');
vm.dropdownOpen = true;
setTimeout(() => {
expect(vm.$refs.dropdownMenu.scrollIntoView).toHaveBeenCalled();
done();
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment