Skip to content

Commit

Permalink
Resolve setFixtures function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Nov 7, 2018
1 parent bcbe889 commit 7fbb879
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/miq_flash.js
Original file line number Diff line number Diff line change
@@ -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: '' };
Expand Down Expand Up @@ -68,7 +68,7 @@ function add_flash(msg, level, options) {
}
}

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

Expand Down
2 changes: 2 additions & 0 deletions app/javascript/spec/helpers/old_js_file_require_helper.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
global.window = global;
require('../../../assets/javascripts/miq_application.js');
require('../../../assets/javascripts/miq_flash.js');

4 changes: 4 additions & 0 deletions app/javascript/spec/helpers/set_fixtures_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global.window = global;
window.setFixtures = function(html) {
$('html').html(html);
};
Original file line number Diff line number Diff line change
@@ -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 = '<html><head></head><body><div id="flash_msg_div">test</div></body></html>';
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 = '<html><head></head><body><div id="flash_msg_div"></div></body></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 = '<div class="flash_text_div"><div class="alert alert-danger text-overflow-pf"><button class="close" data-dismiss="alert"><span class="pficon pficon-close"></span></button><span class="pficon pficon-error-circle-o"></span><strong>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.</strong><div class="alert_expand_link" style="display: none;"><strong><a href="#">View More</a></strong></div></div></div>'
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 = '<div class="flash_text_div"><div class="alert alert-danger"><button class="close" data-dismiss="alert"><span class="pficon pficon-close"></span></button><span class="pficon pficon-error-circle-o"></span><strong>This is a really long alert!</strong></div></div>'
Expand Down

0 comments on commit 7fbb879

Please sign in to comment.