diff --git a/app/assets/javascripts/blob/template_selector.js b/app/assets/javascripts/blob/template_selector.js index 6cfe354d277d0c30e574e3c11fa1e06dbac675a0..b0de4dc86281f338f19508220521291733dc5ea8 100644 --- a/app/assets/javascripts/blob/template_selector.js +++ b/app/assets/javascripts/blob/template_selector.js @@ -83,6 +83,7 @@ export default class TemplateSelector { if (this.editor instanceof $) { this.editor.get(0).dispatchEvent(this.autosizeUpdateEvent); + this.editor.trigger('input'); } } diff --git a/app/assets/javascripts/templates/issuable_template_selector.js b/app/assets/javascripts/templates/issuable_template_selector.js index 78a1c4fa8a85f65c582dc275e29a6d5a4f642713..10ad41709305a4c0545ceb720f8fb376ff111014 100644 --- a/app/assets/javascripts/templates/issuable_template_selector.js +++ b/app/assets/javascripts/templates/issuable_template_selector.js @@ -31,7 +31,8 @@ export default class IssuableTemplateSelector extends TemplateSelector { }); 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); } else { this.reset(); @@ -109,6 +110,7 @@ export default class IssuableTemplateSelector extends TemplateSelector { } else { this.setEditorContent(this.currentTemplate, { skipFocus: false }); } + return; } } diff --git a/app/views/shared/form_elements/_apply_template_warning.html.haml b/app/views/shared/form_elements/_apply_template_warning.html.haml index 9027264d2215fa3af4e71ee44bc3cc31de8ecbd9..09ca59a520c1424ec900d70a76d0e17d55e8e472 100644 --- a/app/views/shared/form_elements/_apply_template_warning.html.haml +++ b/app/views/shared/form_elements/_apply_template_warning.html.haml @@ -2,7 +2,7 @@ .offset-sm-2.col-sm-10 .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") %p @@ -10,5 +10,5 @@ %button.js-override-template.btn.btn-warning.mr-2{ type: 'button' } = _("Apply template") - %button.js-cancel-btn.btn.btn-inverted{ type: 'button' } + %button.js-close-btn.js-cancel-btn.btn.btn-inverted{ type: 'button' } = _("Cancel") diff --git a/spec/features/projects/issuable_templates_spec.rb b/spec/features/projects/issuable_templates_spec.rb index c06fee92d09d7f3168739f0dc5ca36efcf616313..4b6f1672f08f0907fce45f7e54223ac5fcdaf97a 100644 --- a/spec/features/projects/issuable_templates_spec.rb +++ b/spec/features/projects/issuable_templates_spec.rb @@ -131,8 +131,15 @@ end 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(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 it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then applies template change' do