|
| 1 | +describe( 'Toasts:', function() { |
| 2 | + var toastOutDuration = 375; |
| 3 | + var toastInDuration = 300; |
| 4 | + var toast; |
| 5 | + |
| 6 | + describe('Toast javascript functions', function() { |
| 7 | + // Toast out animation duration does not count as part of its timer. |
| 8 | + it('should display and remove a toast', function(done) { |
| 9 | + Materialize.toast('Test toast', toastInDuration); |
| 10 | + |
| 11 | + setTimeout(function() { |
| 12 | + toast = $('.toast'); |
| 13 | + expect(toast.length).toBe(1); |
| 14 | + expect(toast).toBeVisible(); |
| 15 | + expect(toast.text()).toBe('Test toast'); |
| 16 | + setTimeout(function() { |
| 17 | + toast = $('.toast'); |
| 18 | + expect(toast).toBeVisible(); |
| 19 | + expect(toast.length).toBe(1, 'because toast duration still on going'); |
| 20 | + setTimeout(function() { |
| 21 | + toast = $('.toast'); |
| 22 | + expect(toast.length).toBe(0, 'because toast should be removed by now'); |
| 23 | + done(); |
| 24 | + }, toastOutDuration + 90); // .1s leeway is given |
| 25 | + }, 10); |
| 26 | + }, toastInDuration); |
| 27 | + }); |
| 28 | + |
| 29 | + it('Opens a toast with HTML content', function() { |
| 30 | + var $toastContent = $('<span>I am toast content</span>'); |
| 31 | + Materialize.toast($toastContent, 400); |
| 32 | + toast = $('.toast'); |
| 33 | + expect(toast.first('span').text()).toBe('I am toast content'); |
| 34 | + expect(toast.first('span').text()).not.toBe('I am toast') |
| 35 | + }); |
| 36 | + |
| 37 | + it('Toasts should call the callback function when dismissed', |
| 38 | + function(done) { |
| 39 | + var boolObj = {wasCalled: false}; |
| 40 | + var callback = function() { |
| 41 | + boolObj.wasCalled = true; |
| 42 | + }; |
| 43 | + Materialize.toast('I am a toast', 100, '', callback); |
| 44 | + setTimeout(function() { |
| 45 | + expect(boolObj.wasCalled).toBe(true, |
| 46 | + 'because the callback set it to true'); |
| 47 | + done(); |
| 48 | + }, 500); |
| 49 | + }); |
| 50 | + |
| 51 | + it('Apply two custom class to a toast', function() { |
| 52 | + Materialize.toast('Hi', 400, 'round flat'); |
| 53 | + toast = $('.toast'); |
| 54 | + expect(toast.closest('.round.flat').length).toBe(1, |
| 55 | + 'because the class parameter was passed with two classes'); |
| 56 | + }); |
| 57 | + |
| 58 | + }); |
| 59 | + |
| 60 | + |
| 61 | +}); |
0 commit comments