not really known
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.

97 lines
2.8 KiB

  1. define(["sugar-web/graphics/radiobuttonsgroup"], function (
  2. radioButtonsGroup) {
  3. 'use strict';
  4. var elem1;
  5. var elem2;
  6. var elem3;
  7. beforeEach(function () {
  8. elem1 = document.createElement('button');
  9. elem2 = document.createElement('button');
  10. elem3 = document.createElement('button');
  11. });
  12. describe("radioToolButton", function () {
  13. var wasClicked;
  14. it("should construct", function () {
  15. var radio = new radioButtonsGroup.RadioButtonsGroup(
  16. [elem1, elem2, elem3]);
  17. expect(radio.elems.length).toBe(3);
  18. });
  19. it("should start active the first by default", function () {
  20. var radio = new radioButtonsGroup.RadioButtonsGroup(
  21. [elem1, elem2, elem3]);
  22. expect(radio.getActive()).toBe(elem1);
  23. });
  24. it("should start active the first with 'active' class", function () {
  25. elem2.className = "active red";
  26. elem3.className = "active blue";
  27. var radio = new radioButtonsGroup.RadioButtonsGroup(
  28. [elem1, elem2, elem3]);
  29. expect(radio.getActive()).toBe(elem2);
  30. });
  31. it("should add 'active' class to the selected item", function () {
  32. var radio = new radioButtonsGroup.RadioButtonsGroup(
  33. [elem1, elem2, elem3]);
  34. var elem = radio.getActive();
  35. expect(elem.classList.contains('active')).toBe(true);
  36. });
  37. it("should change the active one on click", function () {
  38. var radio = new radioButtonsGroup.RadioButtonsGroup(
  39. [elem1, elem2, elem3]);
  40. // let's click elem2
  41. runs(function () {
  42. wasClicked = false;
  43. elem2.onclick = function () {
  44. wasClicked = true;
  45. };
  46. elem2.click();
  47. });
  48. waitsFor(function () {
  49. return wasClicked;
  50. }, "the element should be clicked");
  51. runs(function () {
  52. var elem = radio.getActive();
  53. expect(elem).toBe(elem2);
  54. expect(elem.classList.contains('active')).toBe(true);
  55. });
  56. // now let's click elem1
  57. runs(function () {
  58. wasClicked = false;
  59. elem1.onclick = function () {
  60. wasClicked = true;
  61. };
  62. elem1.click();
  63. });
  64. waitsFor(function () {
  65. return wasClicked;
  66. }, "the element should be clicked");
  67. runs(function () {
  68. var elem = radio.getActive();
  69. expect(elem).toBe(elem1);
  70. expect(elem.classList.contains('active')).toBe(true);
  71. });
  72. });
  73. });
  74. });