Commit 7896f605 authored by Nathan Friend's avatar Nathan Friend

Fix v-model support in ref selector component

Updates the ref selector component to properly implement v-model.
parent a6875e5f
...@@ -74,6 +74,18 @@ export default { ...@@ -74,6 +74,18 @@ export default {
return !this.showBranchesSection && !this.showTagsSection && !this.showCommitsSection; return !this.showBranchesSection && !this.showTagsSection && !this.showCommitsSection;
}, },
}, },
watch: {
// Keep the Vuex store synchronized if the parent
// component updates the selected ref through v-model
value: {
immediate: true,
handler() {
if (this.value !== this.selectedRef) {
this.setSelectedRef(this.value);
}
},
},
},
created() { created() {
this.setProjectId(this.projectId); this.setProjectId(this.projectId);
this.search(this.query); this.search(this.query);
......
...@@ -26,11 +26,12 @@ describe('Ref selector component', () => { ...@@ -26,11 +26,12 @@ describe('Ref selector component', () => {
let tagsApiCallSpy; let tagsApiCallSpy;
let commitApiCallSpy; let commitApiCallSpy;
const createComponent = () => { const createComponent = (props = {}) => {
wrapper = mount(RefSelector, { wrapper = mount(RefSelector, {
propsData: { propsData: {
projectId, projectId,
value: '', value: '',
...props,
}, },
listeners: { listeners: {
// simulate a parent component v-model binding // simulate a parent component v-model binding
...@@ -163,6 +164,38 @@ describe('Ref selector component', () => { ...@@ -163,6 +164,38 @@ describe('Ref selector component', () => {
}); });
describe('post-initialization behavior', () => { describe('post-initialization behavior', () => {
describe('when a ref is pre-selected', () => {
const preselectedRef = fixtures.branches[0].name;
beforeEach(() => {
createComponent({ value: preselectedRef });
return waitForRequests();
});
it('renders the pre-selected ref name', () => {
expect(findButtonContent().text()).toBe(preselectedRef);
});
});
describe('when the selected ref is updated by the parent component', () => {
const updatedRef = fixtures.branches[0].name;
beforeEach(() => {
createComponent();
return waitForRequests();
});
it('renders the updated ref name', () => {
wrapper.setProps({ value: updatedRef });
return localVue.nextTick().then(() => {
expect(findButtonContent().text()).toBe(updatedRef);
});
});
});
describe('when the search query is updated', () => { describe('when the search query is updated', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
......
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