Commit 8d268273 authored by Simon Knox's avatar Simon Knox

Add proper null check for task item rendering

If description is empty, this.$el was still non-null, but
it was just an HTML comment as a string. So the call to
querySelectorAll failed
parent 9fb2bece
...@@ -95,7 +95,7 @@ export default { ...@@ -95,7 +95,7 @@ export default {
this.renderGFM(); this.renderGFM();
this.updateTaskStatusText(); this.updateTaskStatusText();
if (this.workItemsEnabled && this.$el) { if (this.workItemsEnabled) {
this.renderTaskActions(); this.renderTaskActions();
} }
}, },
...@@ -157,7 +157,12 @@ export default { ...@@ -157,7 +157,12 @@ export default {
} }
}, },
renderTaskActions() { renderTaskActions() {
if (!this.$el?.querySelectorAll) {
return;
}
const taskListFields = this.$el.querySelectorAll('.task-list-item'); const taskListFields = this.$el.querySelectorAll('.task-list-item');
taskListFields.forEach((item, index) => { taskListFields.forEach((item, index) => {
const button = document.createElement('button'); const button = document.createElement('button');
button.classList.add( button.classList.add(
......
...@@ -209,57 +209,79 @@ describe('Description component', () => { ...@@ -209,57 +209,79 @@ describe('Description component', () => {
}); });
describe('with work items feature flag is enabled', () => { describe('with work items feature flag is enabled', () => {
beforeEach(async () => { describe('empty description', () => {
createComponent({ beforeEach(async () => {
props: { createComponent({
descriptionHtml: descriptionHtmlWithCheckboxes, props: {
}, descriptionHtml: '',
provide: {
glFeatures: {
workItems: true,
}, },
}, provide: {
glFeatures: {
workItems: true,
},
},
});
await nextTick();
}); });
await nextTick();
});
it('renders a list of hidden buttons corresponding to checkboxes in description HTML', () => { it('renders without error', () => {
expect(findTaskActionButtons()).toHaveLength(3); expect(findTaskActionButtons()).toHaveLength(0);
});
}); });
it('renders a list of popovers corresponding to checkboxes in description HTML', () => { describe('description with checkboxes', () => {
expect(findPopovers()).toHaveLength(3); beforeEach(async () => {
expect(findPopovers().at(0).props('target')).toBe( createComponent({
findTaskActionButtons().at(0).attributes('id'), props: {
); descriptionHtml: descriptionHtmlWithCheckboxes,
}); },
provide: {
glFeatures: {
workItems: true,
},
},
});
await nextTick();
});
it('does not show a modal by default', () => { it('renders a list of hidden buttons corresponding to checkboxes in description HTML', () => {
expect(findModal().props('visible')).toBe(false); expect(findTaskActionButtons()).toHaveLength(3);
}); });
it('opens a modal when a button on popover is clicked and displays correct title', async () => { it('renders a list of popovers corresponding to checkboxes in description HTML', () => {
findConvertToTaskButton().vm.$emit('click'); expect(findPopovers()).toHaveLength(3);
expect(showModal).toHaveBeenCalled(); expect(findPopovers().at(0).props('target')).toBe(
await nextTick(); findTaskActionButtons().at(0).attributes('id'),
expect(findCreateWorkItem().props('initialTitle').trim()).toBe('todo 1'); );
}); });
it('closes the modal on `closeCreateTaskModal` event', () => { it('does not show a modal by default', () => {
findConvertToTaskButton().vm.$emit('click'); expect(findModal().props('visible')).toBe(false);
findCreateWorkItem().vm.$emit('closeModal'); });
expect(hideModal).toHaveBeenCalled();
});
it('updates description HTML on `onCreate` event', async () => { it('opens a modal when a button on popover is clicked and displays correct title', async () => {
const newTitle = 'New title'; findConvertToTaskButton().vm.$emit('click');
findConvertToTaskButton().vm.$emit('click'); expect(showModal).toHaveBeenCalled();
findCreateWorkItem().vm.$emit('onCreate', newTitle); await nextTick();
expect(hideModal).toHaveBeenCalled(); expect(findCreateWorkItem().props('initialTitle').trim()).toBe('todo 1');
await nextTick(); });
it('closes the modal on `closeCreateTaskModal` event', () => {
findConvertToTaskButton().vm.$emit('click');
findCreateWorkItem().vm.$emit('closeModal');
expect(hideModal).toHaveBeenCalled();
});
it('updates description HTML on `onCreate` event', async () => {
const newTitle = 'New title';
findConvertToTaskButton().vm.$emit('click');
findCreateWorkItem().vm.$emit('onCreate', newTitle);
expect(hideModal).toHaveBeenCalled();
await nextTick();
expect(findTaskSvg().exists()).toBe(true); expect(findTaskSvg().exists()).toBe(true);
expect(wrapper.text()).toContain(newTitle); expect(wrapper.text()).toContain(newTitle);
});
}); });
}); });
}); });
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