ui.spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* global expect, it, describe, spyOn, DebugUI */
  2. /* eslint no-redeclare: 0 */
  3. /*
  4. jasmine tests for Snowflake UI
  5. */
  6. var document = {
  7. getElementById: function() {
  8. return {};
  9. },
  10. createTextNode: function(txt) {
  11. return txt;
  12. }
  13. };
  14. describe('UI', function() {
  15. it('activates debug mode when badge does not exist', function() {
  16. var u;
  17. spyOn(document, 'getElementById').and.callFake(function(id) {
  18. if ('badge' === id) {
  19. return null;
  20. }
  21. return {};
  22. });
  23. u = new DebugUI();
  24. expect(document.getElementById.calls.count()).toEqual(2);
  25. expect(u.$status).not.toBeNull();
  26. expect(u.$msglog).not.toBeNull();
  27. });
  28. it('sets status message when in debug mode', function() {
  29. var u;
  30. u = new DebugUI();
  31. u.$status = {
  32. innerHTML: '',
  33. appendChild: function(txt) {
  34. return this.innerHTML = txt;
  35. }
  36. };
  37. u.setStatus('test');
  38. expect(u.$status.innerHTML).toEqual('Status: test');
  39. });
  40. it('sets message log css correctly for debug mode', function() {
  41. var u;
  42. u = new DebugUI();
  43. u.setActive(true);
  44. expect(u.$msglog.className).toEqual('active');
  45. u.setActive(false);
  46. expect(u.$msglog.className).toEqual('');
  47. });
  48. it('logs to the textarea correctly when debug mode', function() {
  49. var u;
  50. u = new DebugUI();
  51. u.$msglog = {
  52. value: '',
  53. scrollTop: 0,
  54. scrollHeight: 1337
  55. };
  56. u.log('test');
  57. expect(u.$msglog.value).toEqual('test\n');
  58. expect(u.$msglog.scrollTop).toEqual(1337);
  59. });
  60. });