summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/feedback_box.spec.js
blob: d40ccf51a63039875255bc916cc63ab7ff298b12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
describeComponent('mail_view/ui/feedback_box', function () {
  'use strict';
  var feedbackCache;

  beforeEach(function () {
    feedbackCache = require('feedback/feedback_cache');
    Pixelated.mockBloodhound();
    this.setupComponent('<div></div>');
  });


  describe('close button behavior', function () {

    it('should fire Show no message selected if the close button is clicked', function () {
      var spy = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
      this.component.select('closeButton').click();
      expect(spy).toHaveBeenTriggeredOn(document);
    });

  });

  describe('caching feedback data', function () {
    it('should cache textbox feedback data', function () {
      this.component.select('textBox').val('Pixelated is Awesome!');
      this.component.select('textBox').trigger("change");
      expect(feedbackCache.getCache()).toEqual('Pixelated is Awesome!');
    });

    it('should have its textbox feedback field, filled with feedbackCache value, when setup', function(){
      feedbackCache.setCache("foo bar");

      this.setupComponent('<div></div>');
      expect(this.component.select('textBox').val()).toEqual('foo bar');
    });


  });

  describe('when submit feedback', function () {

    it('should fire submit feedback event', function () {
      var spy = spyOnEvent(document, Pixelated.events.feedback.submit);

      this.component.select('textBox').val('Pixelated is Awesome!');
      this.component.select('submitButton').click();
      expect(spy).toHaveBeenTriggeredOnAndWith(document, {feedback: 'Pixelated is Awesome!'});
    });

    it('should close feedback box after submit', function () {
      var spy = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

      this.component.trigger(document, Pixelated.events.feedback.submitted);
      expect(spy).toHaveBeenTriggeredOn(document);
      expect(feedbackCache.getCache()).toEqual('');
    });

    it('should shows success message after submit', function () {
      var spy = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);

      this.component.trigger(document, Pixelated.events.feedback.submitted);
      expect(spy).toHaveBeenTriggeredOnAndWith(document, {message: 'Thanks for your feedback!'});
    });

  });

});