summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/services/delete_service.spec.js
blob: 9872a644a9733e23d533732ac2c61acd2b2a6803 (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
describeComponent('services/delete_service', function () {
  'use strict';

  var i18n;

  beforeEach( function () {
    this.setupComponent();
    i18n = require('views/i18n');
  });

  var mailWithoutTrashTag = {
    ident: 42,
    isInTrash: function() { return false; },
    tags: ['inbox', 'test']
  };

  var mailWithTrashTag = {
    ident: 34,
    isInTrash: function() { return true; },
    tags: ['inbox', 'test', 'trash']
  };

  it('add Trash tag when deleting an email that does not have it', function () {
    var mailDeleteEvent = spyOnEvent(document, Pixelated.events.mail.delete);
    var openNoMessageSelectedEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

    this.component.trigger(document, Pixelated.events.ui.mail.delete, {mail: mailWithoutTrashTag});

    var expectedDeleteEventData = {
      mail: mailWithoutTrashTag,
      successMessage: i18n('Your message was moved to trash!')
    };

    expect(mailDeleteEvent).toHaveBeenTriggeredOnAndWith(document, expectedDeleteEventData);
  });

  it('removes permanently email that has Trash tag', function(){
    var mailDeleteEvent = spyOnEvent(document, Pixelated.events.mail.delete);
    var openNoMessageSelectedEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

    this.component.trigger(document, Pixelated.events.ui.mail.delete, {mail: mailWithTrashTag});

    var expectedDeleteEventData = {
      mail: mailWithTrashTag,
      successMessage: i18n('Your message was permanently deleted!')
    };

    expect(mailDeleteEvent).toHaveBeenTriggeredOnAndWith(document, expectedDeleteEventData );
  });

});