Skip to content

Commit

Permalink
Clear the flash_msg_div before displaying new flashes during login
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Dec 5, 2017
1 parent a8407dd commit 661b95b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/miq_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ function miqAjaxAuth(url) {
// TODO vanillaJsAPI.autorenew is called on (non-login) page load - when?
})
.then(null, function() {
clearFlash();
add_flash(__('Incorrect username or password'), 'error', { id: 'auth_failed' });

miqClearLoginFields();
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/miq_flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function add_flash(msg, level, options) {
$('#flash_msg_div').append(textDiv).show();
}

function clearFlash() {
$('#flash_msg_div').empty();
}

function _miqFlashLoad() {
return JSON.parse(sessionStorage.getItem('flash_msgs') || '[]');
}
Expand Down
13 changes: 13 additions & 0 deletions spec/javascripts/miq_flash_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('miq_flash.js', function() {
describe('clearFlash', function() {
beforeEach(function() {
var html = '<html><head></head><body><div id="flash_msg_div">test</div></body></html>';
setFixtures(html);
});

it('clears the flash_msg_div', function() {
clearFlash();
expect($('#flash_msg_div').html()).toEqual('');
});
});
});

0 comments on commit 661b95b

Please sign in to comment.