Commit 381d3054 authored by Fatih Acet's avatar Fatih Acet Committed by Kushal Pandya

Fix cancel button in issue template update warning

This commit also does the following:

- Adds an extra spec to validate close and
dismiss buttons
- Adds an extra assertion to validate template
warning element not found on the DOM
- Fixes resetting template content for new issues
- Fixes content saving to localStorage when
template changed
parent 7fb94850
...@@ -83,6 +83,7 @@ export default class TemplateSelector { ...@@ -83,6 +83,7 @@ export default class TemplateSelector {
if (this.editor instanceof $) { if (this.editor instanceof $) {
this.editor.get(0).dispatchEvent(this.autosizeUpdateEvent); this.editor.get(0).dispatchEvent(this.autosizeUpdateEvent);
this.editor.trigger('input');
} }
} }
......
...@@ -31,7 +31,8 @@ export default class IssuableTemplateSelector extends TemplateSelector { ...@@ -31,7 +31,8 @@ export default class IssuableTemplateSelector extends TemplateSelector {
}); });
this.templateWarningEl.find('.js-close-btn').on('click', () => { this.templateWarningEl.find('.js-close-btn').on('click', () => {
if (this.previousSelectedIndex) { // Explicitly check against 0 value
if (this.previousSelectedIndex !== undefined) {
this.dropdown.data('glDropdown').selectRowAtIndex(this.previousSelectedIndex); this.dropdown.data('glDropdown').selectRowAtIndex(this.previousSelectedIndex);
} else { } else {
this.reset(); this.reset();
...@@ -109,6 +110,7 @@ export default class IssuableTemplateSelector extends TemplateSelector { ...@@ -109,6 +110,7 @@ export default class IssuableTemplateSelector extends TemplateSelector {
} else { } else {
this.setEditorContent(this.currentTemplate, { skipFocus: false }); this.setEditorContent(this.currentTemplate, { skipFocus: false });
} }
return; return;
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.offset-sm-2.col-sm-10 .offset-sm-2.col-sm-10
.warning_message.mb-0{ role: 'alert' } .warning_message.mb-0{ role: 'alert' }
%btn.js-close-btn.close{ type: "button", "aria-hidden": true, "aria-label": _("Close") } %btn.js-close-btn.js-dismiss-btn.close{ type: "button", "aria-hidden": true, "aria-label": _("Close") }
= sprite_icon("close") = sprite_icon("close")
%p %p
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
%button.js-override-template.btn.btn-warning.mr-2{ type: 'button' } %button.js-override-template.btn.btn-warning.mr-2{ type: 'button' }
= _("Apply template") = _("Apply template")
%button.js-cancel-btn.btn.btn-inverted{ type: 'button' } %button.js-close-btn.js-cancel-btn.btn.btn-inverted{ type: 'button' }
= _("Cancel") = _("Cancel")
...@@ -131,8 +131,15 @@ describe 'issuable templates', :js do ...@@ -131,8 +131,15 @@ describe 'issuable templates', :js do
end end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then cancels template change' do it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then cancels template change' do
page.find('.js-template-warning .js-cancel-btn').click page.find('.js-template-warning .js-close-btn.js-cancel-btn').click
expect(find('textarea')['value']).to eq(updated_description) expect(find('textarea')['value']).to eq(updated_description)
expect(page).not_to have_content template_override_warning
end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then dismiss the template warning' do
page.find('.js-template-warning .js-close-btn.js-dismiss-btn').click
expect(find('textarea')['value']).to eq(updated_description)
expect(page).not_to have_content template_override_warning
end end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then applies template change' do it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then applies template change' do
......
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