diff --git a/app/assets/javascripts/miq_flash.js b/app/assets/javascripts/miq_flash.js index 5a0e6ee899c3..9537a734bd45 100644 --- a/app/assets/javascripts/miq_flash.js +++ b/app/assets/javascripts/miq_flash.js @@ -1,6 +1,6 @@ // add a flash message to an existing #flash_msg_div // levels are error, warning, info, success -function add_flash(msg, level, options) { +window.add_flash = function(msg, level, options) { level = level || 'success'; options = options || {}; var cls = { alert: '', icon: '' }; @@ -68,7 +68,7 @@ function add_flash(msg, level, options) { } } -function clearFlash() { +window.clearFlash = function() { $('#flash_msg_div').empty(); } diff --git a/app/javascript/spec/helpers/old_js_file_require_helper.js b/app/javascript/spec/helpers/old_js_file_require_helper.js index a0968c3a7d2f..8521c1c508de 100644 --- a/app/javascript/spec/helpers/old_js_file_require_helper.js +++ b/app/javascript/spec/helpers/old_js_file_require_helper.js @@ -1,2 +1,4 @@ global.window = global; require('../../../assets/javascripts/miq_application.js'); +require('../../../assets/javascripts/miq_flash.js'); + diff --git a/app/javascript/spec/helpers/set_fixtures_helper.js b/app/javascript/spec/helpers/set_fixtures_helper.js new file mode 100644 index 000000000000..0d46501b91b6 --- /dev/null +++ b/app/javascript/spec/helpers/set_fixtures_helper.js @@ -0,0 +1,4 @@ +global.window = global; +window.setFixtures = function(html) { + $('html').html(html); +}; diff --git a/spec/javascripts/miq_flash_spec.js b/app/javascript/spec/old_js/miq_flash.spec.js similarity index 84% rename from spec/javascripts/miq_flash_spec.js rename to app/javascript/spec/old_js/miq_flash.spec.js index 00052dcef289..6a286c74945d 100644 --- a/spec/javascripts/miq_flash_spec.js +++ b/app/javascript/spec/old_js/miq_flash.spec.js @@ -1,29 +1,32 @@ -describe('miq_flash.js', function() { - describe('clearFlash', function() { - beforeEach(function() { +require('../helpers/set_fixtures_helper.js'); +require('../helpers/old_js_file_require_helper.js'); + +describe('miq_flash.js', () => { + describe('clearFlash', () => { + beforeEach(() => { var html = '
test
'; setFixtures(html); }); - it('clears the flash_msg_div', function() { + it('clears the flash_msg_div', () => { clearFlash(); expect($('#flash_msg_div').html()).toEqual(''); }); }); - describe('longAlert', function() { - beforeEach(function() { + describe('longAlert', () => { + beforeEach(() => { var html = '
'; setFixtures(html); }); - it('displays flash_msg_div "View More" button', function() { + it('displays flash_msg_div "View More" button', () => { // Expect alert msg div to add the "See More" button to the div. add_flash("Lorem ipsum dolor sit amet, usu ei mollis vivendum, ancillae indoctum philosophia an pri, affert partiendo cum ne. Nec animal tincidunt philosophia ea. Ne mea liber gloriatur, ignota dictas mei ne. Omittam eleifend consequuntur vix eu, everti accusata accommodare et eam. Ut vidit semper instructior duo, usu in autem inermis. Viris pertinax constituto per id, at debet apeirian persecuti has. Nostrum expetenda qui ad, mazim iriure id duo, est alii wisi at.", 'error' , {long_alert: true}); var flash_msg_div = '
Lorem ipsum dolor sit amet, usu ei mollis vivendum, ancillae indoctum philosophia an pri, affert partiendo cum ne. Nec animal tincidunt philosophia ea. Ne mea liber gloriatur, ignota dictas mei ne. Omittam eleifend consequuntur vix eu, everti accusata accommodare et eam. Ut vidit semper instructior duo, usu in autem inermis. Viris pertinax constituto per id, at debet apeirian persecuti has. Nostrum expetenda qui ad, mazim iriure id duo, est alii wisi at.
' expect($('#flash_msg_div').html()).toEqual(flash_msg_div); }); - it('does not display flash_msg_div "See More" button', function() { + it('does not display flash_msg_div "See More" button', () => { // Expect alert msg div to *not add* the "See More" button to the div. add_flash("This is a really long alert!", 'error'); var flash_msg_div = '
This is a really long alert!
'