You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
25 KiB

  1. /// <reference path="../../../toastr.js" />
  2. /// <reference path="../qunit/qunit.js" />
  3. (function () {
  4. var iconClasses = {
  5. error: 'toast-error',
  6. info: 'toast-info',
  7. success: 'toast-success',
  8. warning: 'toast-warning'
  9. };
  10. var positionClasses = {
  11. topRight: 'toast-top-right',
  12. bottomRight: 'toast-bottom-right',
  13. bottomLeft: 'toast-bottom-left',
  14. topLeft: 'toast-top-left',
  15. topCenter: 'toast-top-center',
  16. bottomCenter: 'toast-bottom-center'
  17. };
  18. var sampleMsg = 'I don\'t think they really exist';
  19. var sampleTitle = 'ROUS';
  20. var selectors = {
  21. container: 'div#toast-container',
  22. toastInfo: 'div#toast-container > div.toast-info',
  23. toastWarning: 'div#toast-container > div.toast-success',
  24. toastError: 'div#toast-container > div.toast-error',
  25. toastSuccess: 'div#toast-container > div.toast-success'
  26. };
  27. toastr.options = {
  28. timeOut: 2000,
  29. extendedTimeOut: 0,
  30. fadeOut: 0,
  31. fadeIn: 0,
  32. showDuration: 0,
  33. hideDuration: 0,
  34. debug: false
  35. };
  36. var delay = toastr.options.timeOut + 500;
  37. // 'Clears' must go first
  38. module('clear');
  39. asyncTest('clear - show 3 toasts, clear the 2nd', 1, function () {
  40. //Arrange
  41. var $toast = [];
  42. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  43. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  44. $toast[2] = toastr.info(sampleMsg, sampleTitle + '-3');
  45. var $container = toastr.getContainer();
  46. //Act
  47. toastr.clear($toast[1]);
  48. //Assert
  49. setTimeout(function () {
  50. //debugger;
  51. //console.log($container.children().length);
  52. ok($container && $container.children().length === 2);
  53. //Teardown
  54. resetContainer();
  55. start();
  56. }, 1000);
  57. });
  58. asyncTest('clear - show 3 toasts, clear all 3, 0 left', 1, function () {
  59. //Arrange
  60. var $toast = [];
  61. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  62. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  63. $toast[2] = toastr.info(sampleMsg, sampleTitle + '-3');
  64. var $container = toastr.getContainer();
  65. //Act
  66. toastr.clear();
  67. //Assert
  68. setTimeout(function () {
  69. ok($container && $container.children().length === 0);
  70. //Teardown
  71. resetContainer();
  72. start();
  73. }, delay);
  74. });
  75. test('clear - after clear with force option toast with focus disappears', 1, function () {
  76. //Arrange
  77. var $toast;
  78. var msg = sampleMsg + '<br/><br/><button type="button">Clear</button>';
  79. //Act
  80. $toast = toastr.info(msg, sampleTitle + '-1');
  81. $toast.find('button').focus();
  82. toastr.clear($toast, { force: true });
  83. var $container = toastr.getContainer();
  84. //Assert
  85. ok($container && $container.children().length === 0, 'Focused toast after a clear with force is not visible');
  86. //Teardown
  87. resetContainer();
  88. });
  89. asyncTest('clear and show - show 2 toasts, clear both, then show 1 more', 2, function () {
  90. //Arrange
  91. var $toast = [];
  92. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  93. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  94. var $container = toastr.getContainer();
  95. toastr.clear();
  96. //Act
  97. setTimeout(function () {
  98. $toast[2] = toastr.info(sampleMsg, sampleTitle + '-3-Visible');
  99. //Assert
  100. equal($toast[2].find('div.toast-title').html(), sampleTitle + '-3-Visible', 'Finds toast after a clear');
  101. ok($toast[2].is(':visible'), 'Toast after a clear is visible');
  102. //Teardown
  103. resetContainer();
  104. start();
  105. }, delay);
  106. });
  107. asyncTest('clear and show - clear removes toast container', 2, function () {
  108. //Arrange
  109. var $toast = [];
  110. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  111. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  112. var $container = toastr.getContainer();
  113. toastr.clear();
  114. //Act
  115. setTimeout(function () {
  116. //Assert
  117. equal($(selectors.container).length, 0, 'Toast container does not exist');
  118. ok(!$toast[1].is(':visible'), 'Toast after a clear is visible');
  119. //Teardown
  120. resetContainer();
  121. start();
  122. }, delay);
  123. });
  124. asyncTest('clear and show - after clear new toast creates container', 1, function () {
  125. //Arrange
  126. var $toast = [];
  127. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  128. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  129. var $container = toastr.getContainer();
  130. toastr.clear();
  131. //Act
  132. setTimeout(function () {
  133. $toast[2] = toastr.info(sampleMsg, sampleTitle + '-3-Visible');
  134. //Assert
  135. equal($(selectors.container).find('div.toast-title').html(), sampleTitle + '-3-Visible', 'Finds toast after a clear'); //Teardown
  136. resetContainer();
  137. start();
  138. }, delay);
  139. });
  140. test('clear and show - after clear all toasts new toast still appears', 1, function () {
  141. //Arrange
  142. var $toast = [];
  143. //Act
  144. $toast[0] = toastr.info(sampleMsg, sampleTitle + '-1');
  145. $toast[1] = toastr.info(sampleMsg, sampleTitle + '-2');
  146. toastr.clear();
  147. $toast[2] = toastr.info(sampleMsg, sampleTitle + '-3-Visible');
  148. //Assert
  149. ok($toast[2].is(':visible'), 'Toast after a clear is visible');
  150. //Teardown
  151. resetContainer();
  152. });
  153. module('info');
  154. test('info - pass title and message', 3, function () {
  155. //Arrange
  156. //Act
  157. var $toast = toastr.info(sampleMsg, sampleTitle);
  158. //Assert
  159. equal($toast.find('div.toast-title').html(), sampleTitle, 'Sets title');
  160. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  161. ok($toast.hasClass(iconClasses.info), 'Sets info icon');
  162. //Teardown
  163. $toast.remove();
  164. clearContainerChildren();
  165. });
  166. test('info - pass message, but no title', 3, function () {
  167. //Arrange
  168. //Act
  169. var $toast = toastr.info(sampleMsg);
  170. //Assert
  171. equal($toast.find('div.toast-title').length, 0, 'Sets null title');
  172. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  173. ok($toast.hasClass(iconClasses.info), 'Sets info icon');
  174. //Teardown
  175. $toast.remove();
  176. clearContainerChildren();
  177. });
  178. test('info - pass no message nor title', 3, function () {
  179. //Arrange
  180. //Act
  181. var $toast = toastr.info(); //Assert
  182. equal($toast.find('div.toast-title').length, 0, 'Sets null title');
  183. equal($toast.find('div.toast-message').html(), null, 'Sets message');
  184. ok($toast.hasClass(iconClasses.info), 'Sets info icon');
  185. //Teardown
  186. $toast.remove();
  187. clearContainerChildren();
  188. });
  189. module('warning');
  190. test('warning - pass message and title', 3, function () {
  191. //Arrange
  192. //Act
  193. var $toast = toastr.warning(sampleMsg, sampleTitle);
  194. //Assert
  195. equal($toast.find('div.toast-title').html(), sampleTitle, 'Sets title');
  196. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  197. ok($toast.hasClass(iconClasses.warning), 'Sets warning icon');
  198. //Teardown
  199. $toast.remove();
  200. clearContainerChildren();
  201. });
  202. test('warning - pass message, but no title', 3, function () {
  203. //Arrange
  204. //Act
  205. var $toast = toastr.warning(sampleMsg);
  206. //Assert
  207. equal($toast.find('div.toast-title').length, 0, 'Sets empty title');
  208. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  209. ok($toast.hasClass(iconClasses.warning), 'Sets warning icon');
  210. //Teardown
  211. $toast.remove();
  212. clearContainerChildren();
  213. });
  214. test('warning - no message nor title', 3, function () {
  215. //Arrange
  216. //Act
  217. var $toast = toastr.warning('');
  218. //Assert
  219. equal($toast.find('div.toast-title').length, 0, 'Sets null title');
  220. equal($toast.find('div.toast-message').length, 0, 'Sets empty message');
  221. ok($toast.hasClass(iconClasses.warning), 'Sets warning icon');
  222. //Teardown
  223. $toast.remove();
  224. clearContainerChildren();
  225. });
  226. module('error');
  227. test('error - pass message and title', 3, function () {
  228. //Arrange
  229. //Act
  230. var $toast = toastr.error(sampleMsg, sampleTitle);
  231. //Assert
  232. equal($toast.find('div.toast-title').html(), sampleTitle, 'Sets title');
  233. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  234. ok($toast.hasClass(iconClasses.error), 'Sets error icon');
  235. //Teardown
  236. $toast.remove();
  237. clearContainerChildren();
  238. });
  239. test('error - pass message, but no title', 3, function () {
  240. //Arrange
  241. //Act
  242. var $toast = toastr.error(sampleMsg); //Assert
  243. equal($toast.find('div.toast-title').length, 0, 'Sets empty title');
  244. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  245. ok($toast.hasClass(iconClasses.error), 'Sets error icon');
  246. //Teardown
  247. $toast.remove();
  248. clearContainerChildren();
  249. });
  250. test('error - no message nor title', 3, function () {
  251. //Arrange
  252. //Act
  253. var $toast = toastr.error('');
  254. //Assert
  255. equal($toast.find('div.toast-title').length, 0, 'Sets empty title');
  256. equal($toast.find('div.toast-message').length, 0, 'Sets empty message');
  257. ok($toast.hasClass(iconClasses.error), 'Sets error icon');
  258. //Teardown
  259. $toast.remove();
  260. clearContainerChildren();
  261. });
  262. module('success');
  263. test('success - pass message and title', 3, function () {
  264. //Arrange
  265. //Act
  266. var $toast = toastr.success(sampleMsg, sampleTitle);
  267. //Assert
  268. equal($toast.find('div.toast-title').html(), sampleTitle, 'Sets title');
  269. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  270. ok($toast.hasClass(iconClasses.success), 'Sets success icon');
  271. //Teardown
  272. $toast.remove();
  273. clearContainerChildren();
  274. });
  275. test('success - pass message, but no title', 3, function () {
  276. //Arrange
  277. //Act
  278. var $toast = toastr.success(sampleMsg);
  279. //Assert
  280. equal($toast.find('div.toast-title').length, 0, 'Sets empty title');
  281. equal($toast.find('div.toast-message').html(), sampleMsg, 'Sets message');
  282. ok($toast.hasClass(iconClasses.success), 'Sets success icon');
  283. //Teardown
  284. $toast.remove();
  285. clearContainerChildren();
  286. });
  287. test('success - no message nor title', 3, function () {
  288. //Arrange
  289. //Act
  290. var $toast = toastr.success('');
  291. //Assert
  292. equal($toast.find('div.toast-title').length, 0, 'Sets null title');
  293. equal($toast.find('div.toast-message').length, 0, 'Sets empty message');
  294. ok($toast.hasClass(iconClasses.success), 'Sets success icon'); //Teardown
  295. $toast.remove();
  296. clearContainerChildren();
  297. });
  298. module('escape html', {
  299. teardown: function () {
  300. toastr.options.escapeHtml = false;
  301. }
  302. });
  303. test('info - escape html', 2, function () {
  304. //Arrange
  305. toastr.options.escapeHtml = true;
  306. //Act
  307. var $toast = toastr.info('html <strong>message</strong>', 'html <u>title</u>');
  308. //Assert
  309. equal($toast.find('div.toast-title').html(), 'html &lt;u&gt;title&lt;/u&gt;', 'Title is escaped');
  310. equal($toast.find('div.toast-message').html(), 'html &lt;strong&gt;message&lt;/strong&gt;', 'Message is escaped');
  311. //Teardown
  312. $toast.remove();
  313. clearContainerChildren();
  314. });
  315. test('warning - escape html', 2, function () {
  316. //Arrange
  317. toastr.options.escapeHtml = true;
  318. //Act
  319. var $toast = toastr.warning('html <strong>message</strong>', 'html <u>title</u>');
  320. //Assert
  321. equal($toast.find('div.toast-title').html(), 'html &lt;u&gt;title&lt;/u&gt;', 'Title is escaped');
  322. equal($toast.find('div.toast-message').html(), 'html &lt;strong&gt;message&lt;/strong&gt;', 'Message is escaped');
  323. //Teardown
  324. $toast.remove();
  325. clearContainerChildren();
  326. });
  327. test('error - escape html', 2, function () {
  328. //Arrange
  329. toastr.options.escapeHtml = true;
  330. //Act
  331. var $toast = toastr.error('html <strong>message</strong>', 'html <u>title</u>');
  332. //Assert
  333. equal($toast.find('div.toast-title').html(), 'html &lt;u&gt;title&lt;/u&gt;', 'Title is escaped');
  334. equal($toast.find('div.toast-message').html(), 'html &lt;strong&gt;message&lt;/strong&gt;', 'Message is escaped');
  335. //Teardown
  336. $toast.remove();
  337. clearContainerChildren();
  338. });
  339. test('success - escape html', 2, function () {
  340. //Arrange
  341. toastr.options.escapeHtml = true;
  342. //Act
  343. var $toast = toastr.success('html <strong>message</strong>', 'html <u>title</u>');
  344. //Assert
  345. equal($toast.find('div.toast-title').html(), 'html &lt;u&gt;title&lt;/u&gt;', 'Title is escaped');
  346. equal($toast.find('div.toast-message').html(), 'html &lt;strong&gt;message&lt;/strong&gt;', 'Message is escaped');
  347. //Teardown
  348. $toast.remove();
  349. clearContainerChildren();
  350. });
  351. module('closeButton', {
  352. teardown: function () {
  353. toastr.options.closeButton = false;
  354. }
  355. });
  356. test('close button disabled', 1, function () {
  357. //Arrange
  358. toastr.options.closeButton = false;
  359. //Act
  360. var $toast = toastr.success('');
  361. //Assert
  362. equal($toast.find('button.toast-close-button').length, 0, 'close button should not exist with closeButton=false');
  363. //Teardown
  364. $toast.remove();
  365. clearContainerChildren();
  366. });
  367. test('close button enabled', 1, function () {
  368. //Arrange
  369. toastr.options.closeButton = true;
  370. //Act
  371. var $toast = toastr.success('');
  372. //Assert
  373. equal($toast.find('button.toast-close-button').length, 1, 'close button should exist with closeButton=true');
  374. //Teardown
  375. $toast.remove();
  376. clearContainerChildren();
  377. });
  378. test('close button has type=button', 1, function () {
  379. //Arrange
  380. toastr.options.closeButton = true;
  381. //Act
  382. var $toast = toastr.success('');
  383. //Assert
  384. equal($toast.find('button[type="button"].toast-close-button').length, 1, 'close button should have type=button');
  385. //Teardown
  386. $toast.remove();
  387. clearContainerChildren();
  388. });
  389. asyncTest('close button duration', 1, function () {
  390. //Arrange
  391. toastr.options.closeButton = true;
  392. toastr.options.closeDuration = 0;
  393. toastr.options.hideDuration = 2000;
  394. var $container = toastr.getContainer();
  395. //Act
  396. var $toast = toastr.success('');
  397. $toast.find('button.toast-close-button').click();
  398. setTimeout(function () {
  399. //Assert
  400. ok($container && $container.children().length === 0, 'close button should support own hide animation');
  401. //Teardown
  402. toastr.options.hideDuration = 0;
  403. resetContainer();
  404. start();
  405. }, 500);
  406. });
  407. module('progressBar', {
  408. teardown: function () {
  409. toastr.options.progressBar = false;
  410. }
  411. });
  412. test('progress bar disabled', 1, function () {
  413. //Arrange
  414. toastr.options.progressBar = false;
  415. //Act
  416. var $toast = toastr.success('');
  417. //Assert
  418. equal($toast.find('div.toast-progress').length, 0, 'progress bar should not exist with progressBar=false');
  419. //Teardown
  420. $toast.remove();
  421. clearContainerChildren();
  422. });
  423. test('progress bar enabled', 1, function () {
  424. //Arrange
  425. toastr.options.progressBar = true;
  426. //Act
  427. var $toast = toastr.success('');
  428. //Assert
  429. equal($toast.find('div.toast-progress').length, 1, 'progress bar should exist with progressBar=true');
  430. //Teardown
  431. $toast.remove();
  432. clearContainerChildren();
  433. });
  434. module('event');
  435. asyncTest('event - onShown is executed', 1, function () {
  436. // Arrange
  437. var run = false;
  438. var onShown = function () { run = true; };
  439. toastr.options.onShown = onShown;
  440. // Act
  441. var $toast = toastr.success(sampleMsg, sampleTitle);
  442. setTimeout(function () {
  443. // Assert
  444. ok(run);
  445. //Teardown
  446. $toast.remove();
  447. clearContainerChildren();
  448. start();
  449. }, delay);
  450. });
  451. asyncTest('event - onHidden is executed', 1, function () {
  452. //Arrange
  453. var run = false;
  454. var onHidden = function () { run = true; };
  455. toastr.options.onHidden = onHidden;
  456. toastr.options.timeOut = 1;
  457. //Act
  458. var $toast = toastr.success(sampleMsg, sampleTitle);
  459. setTimeout(function () {
  460. // Assert
  461. ok(run); //Teardown
  462. $toast.remove();
  463. clearContainerChildren();
  464. start();
  465. }, delay);
  466. });
  467. asyncTest('event - onShown and onHidden are both executed', 2, function () {
  468. //Arrange
  469. var onShowRun = false;
  470. var onHideRun = false;
  471. var onShow = function () { onShowRun = true; };
  472. var onHide = function () { onHideRun = true; };
  473. toastr.options.onShown = onShow;
  474. toastr.options.onHidden = onHide;
  475. toastr.options.timeOut = 1;
  476. //Act
  477. var $toast = toastr.success(sampleMsg, sampleTitle);
  478. setTimeout(function () {
  479. // Assert
  480. ok(onShowRun);
  481. ok(onHideRun);
  482. //Teardown
  483. $toast.remove();
  484. clearContainerChildren();
  485. start();
  486. }, delay);
  487. });
  488. test('event - message appears when no show or hide method functions provided', 1, function () {
  489. //Arrange
  490. //Act
  491. var $toast = toastr.success(sampleMsg, sampleTitle);
  492. //Assert
  493. ok($toast.hasClass(iconClasses.success), 'Sets success icon');
  494. //Teardown
  495. $toast.remove();
  496. clearContainerChildren();
  497. });
  498. test('event - prevent duplicate sequential toasts.', 1, function(){
  499. toastr.options.preventDuplicates = true;
  500. var $toast = [];
  501. $toast[0] = toastr.info(sampleMsg, sampleTitle);
  502. $toast[1] = toastr.info(sampleMsg, sampleTitle);
  503. $toast[2] = toastr.info(sampleMsg + " 1", sampleTitle);
  504. $toast[3] = toastr.info(sampleMsg, sampleTitle);
  505. var $container = toastr.getContainer();
  506. ok($container && $container.children().length === 3);
  507. clearContainerChildren();
  508. });
  509. test('event - prevent duplicate sequential toasts, but allow previous after clear.', 1, function(){
  510. toastr.options.preventDuplicates = true;
  511. var $toast = [];
  512. $toast[0] = toastr.info(sampleMsg, sampleTitle);
  513. $toast[1] = toastr.info(sampleMsg, sampleTitle);
  514. clearContainerChildren();
  515. $toast[3] = toastr.info(sampleMsg, sampleTitle);
  516. var $container = toastr.getContainer();
  517. ok($container && $container.children().length === 1);
  518. clearContainerChildren();
  519. });
  520. test('event - allow duplicate sequential toasts.', 1, function(){
  521. toastr.options.preventDuplicates = false;
  522. var $toast = [];
  523. $toast[0] = toastr.info(sampleMsg, sampleTitle);
  524. $toast[1] = toastr.info(sampleMsg, sampleTitle);
  525. $toast[1] = toastr.info(sampleMsg, sampleTitle);
  526. var $container = toastr.getContainer();
  527. ok($container && $container.children().length === 3);
  528. clearContainerChildren();
  529. });
  530. test('event - allow preventDuplicates option to be overridden.', 1, function() {
  531. var $toast = [];
  532. $toast[0] = toastr.info(sampleMsg, sampleTitle, {
  533. preventDuplicates: true
  534. });
  535. $toast[1] = toastr.info(sampleMsg, sampleTitle, {
  536. preventDuplicates: true
  537. });
  538. $toast[2] = toastr.info(sampleMsg, sampleTitle);
  539. var $container = toastr.getContainer();
  540. ok($container && $container.children().length === 2);
  541. clearContainerChildren();
  542. });
  543. module('order of appearance');
  544. test('Newest toast on top', 1, function () {
  545. //Arrange
  546. resetContainer();
  547. toastr.options.newestOnTop = true;
  548. //Act
  549. var $first = toastr.success("First toast");
  550. var $second = toastr.success("Second toast");
  551. //Assert
  552. var containerHtml = toastr.getContainer().html();
  553. ok(containerHtml.indexOf("First toast") > containerHtml.indexOf("Second toast"), 'Newest toast is on top');
  554. //Teardown
  555. $first.remove();
  556. $second.remove();
  557. resetContainer();
  558. });
  559. test('Oldest toast on top', 1, function () {
  560. //Arrange
  561. resetContainer();
  562. toastr.options.newestOnTop = false;
  563. //Act
  564. var $first = toastr.success("First toast");
  565. var $second = toastr.success("Second toast");
  566. //Assert
  567. var containerHtml = toastr.getContainer().html();
  568. ok(containerHtml.indexOf("First toast") < containerHtml.indexOf("Second toast"), 'Oldest toast is on top');
  569. //Teardown
  570. $first.remove();
  571. $second.remove();
  572. resetContainer();
  573. });
  574. // These must go last
  575. module('positioning');
  576. test('Container - position top-right', 1, function () {
  577. //Arrange
  578. resetContainer();
  579. toastr.options.positionClass = positionClasses.topRight;
  580. //Act
  581. var $toast = toastr.success(sampleMsg);
  582. var $container = toastr.getContainer();
  583. //Assert
  584. ok($container.hasClass(positionClasses.topRight), 'Has position top right');
  585. //Teardown
  586. $toast.remove();
  587. resetContainer();
  588. });
  589. test('Container - position bottom-right', 1, function () {
  590. //Arrange
  591. resetContainer();
  592. toastr.options.positionClass = positionClasses.bottomRight;
  593. //Act
  594. var $toast = toastr.success(sampleMsg);
  595. var $container = toastr.getContainer();
  596. //Assert
  597. ok($container.hasClass(positionClasses.bottomRight), 'Has position bottom right');
  598. //Teardown
  599. $toast.remove();
  600. resetContainer();
  601. });
  602. test('Container - position bottom-left', 1, function () {
  603. //Arrange
  604. resetContainer();
  605. //$(selectors.container).remove()
  606. toastr.options.positionClass = positionClasses.bottomLeft;
  607. //Act
  608. var $toast = toastr.success(sampleMsg);
  609. var $container = toastr.getContainer();
  610. //Assert
  611. ok($container.hasClass(positionClasses.bottomLeft), 'Has position bottom left');
  612. //Teardown
  613. $toast.remove();
  614. resetContainer();
  615. });
  616. test('Container - position top-left', 1, function () {
  617. //Arrange
  618. resetContainer();
  619. toastr.options.positionClass = positionClasses.topLeft;
  620. //Act
  621. var $toast = toastr.success(sampleMsg);
  622. var $container = toastr.getContainer();
  623. //Assert
  624. ok($container.hasClass(positionClasses.topLeft), 'Has position top left');
  625. //Teardown
  626. $toast.remove();
  627. resetContainer();
  628. });
  629. test('Container - position top-center', 1, function () {
  630. //Arrange
  631. resetContainer();
  632. toastr.options.positionClass = positionClasses.topCenter;
  633. //Act
  634. var $toast = toastr.success(sampleMsg);
  635. var $container = toastr.getContainer();
  636. //Assert
  637. ok($container.hasClass(positionClasses.topCenter), 'Has position top center');
  638. //Teardown
  639. $toast.remove();
  640. resetContainer();
  641. });
  642. test('Container - position bottom-center', 1, function () {
  643. //Arrange
  644. resetContainer();
  645. toastr.options.positionClass = positionClasses.bottomCenter;
  646. //Act
  647. var $toast = toastr.success(sampleMsg);
  648. var $container = toastr.getContainer();
  649. //Assert
  650. ok($container.hasClass(positionClasses.bottomCenter), 'Has position bottom center');
  651. //Teardown
  652. $toast.remove();
  653. resetContainer();
  654. });
  655. function resetContainer() {
  656. var $container = toastr.getContainer();
  657. if ($container) {
  658. $container.remove();
  659. }
  660. $(selectors.container).remove();
  661. clearContainerChildren();
  662. }
  663. function clearContainerChildren() {
  664. toastr.clear();
  665. }
  666. })();