summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/mail_view.spec.js
blob: 86b40591cf101bad98d3ffd4c08131401644a005 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
describeComponent('mail_view/ui/mail_view', function () {
  'use strict';

  var mail;

  var testData;

  beforeEach(function () {
    mail = {ident: 1, header: { date: '12/12/12T12:12' }, tags: ['inbox']};
    testData = {mail: Pixelated.testData().parsedMail.simpleTextPlain};
    Pixelated.mockBloodhound();
    this.setupComponent('<div></div>', {mail: mail});
  });

  it('triggers mail:want on ui:openMail', function () {
    var spyEvent = spyOnEvent(document, Pixelated.events.mail.want);

    this.setupComponent('<div></div>', {ident: mail.ident });

    expect(spyEvent).toHaveBeenTriggeredOn(document);
    expect(spyEvent.mostRecentCall.data.mail).toEqual(1);
  });

  it('triggers dispatchers.rightPane.openNoMessageSelected when getting mail.notFound', function () {
    var openNoMessageSelectedEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

    this.component.trigger(this.component, Pixelated.events.mail.notFound);

    expect(openNoMessageSelectedEvent).toHaveBeenTriggeredOn(document);
  });


  it('removes the tag from the mail when the tag label is clicked', function() {
    var updateSpy = spyOnEvent(document, Pixelated.events.mail.tags.update);

    testData.mail.tags = ['inbox', 'other'];
    this.component.displayMail({}, testData);
    this.component.removeTag('inbox');

    expect(updateSpy).toHaveBeenTriggeredOn(document);
    expect(updateSpy.mostRecentCall.data.tags).toEqual(['other']);
  });

  it('removes the tag from email even if tag is highlighted', function () {
    var updateSpy = spyOnEvent(document, Pixelated.events.mail.tags.update);

    testData.mail.tags = ['tag', 'other'];
    this.component.displayMail({}, testData);

    var inboxTag = this.component.$node.find('.tag[data-tag="tag"]');
    inboxTag.html('<em class="search-highlight">' + inboxTag.text() + '</em>');

    this.component.$node.find('.search-highlight').click();

    expect(updateSpy).toHaveBeenTriggeredOn(document);
    expect(updateSpy.mostRecentCall.data.tags).toEqual(['other']);
  });

  it('removes numeric tag from the mail when its label is clicked', function() {
    var updateSpy = spyOnEvent(document, Pixelated.events.mail.tags.update);

    testData.mail.tags = ['inbox', '12345'];
    this.component.displayMail({}, testData);
    this.component.removeTag(12345);

    expect(updateSpy).toHaveBeenTriggeredOn(document);
    expect(updateSpy.mostRecentCall.data.tags).toEqual(['inbox']);
  });

  it('remove tag triggers refreshTagList event', function(){
    var refreshTagListEvent = spyOnEvent(document, Pixelated.events.dispatchers.tags.refreshTagList);
    this.component.displayMail({}, testData);
    this.component.removeTag('inbox');
    expect(refreshTagListEvent).toHaveBeenTriggeredOn(document);
  });

  it('verifies if new tag input is hidden when rendering mail view', function() {

    this.component.displayMail({}, testData);

    var newTagInputComponent = this.component.select('newTagInput');
    expect(newTagInputComponent.attr('style').trim()).toEqual('display: none;');
  });

  it('verifies if new tag input is shown when clicking on new tag button ', function() {
   this.component.displayMail({}, testData);

    var newTagInputComponent = this.component.select('newTagInput');
    var addNewComponent = this.component.select('addNew');

    this.component.select('newTagButton').click();

    expect(newTagInputComponent.attr('style').trim()).not.toEqual('display: none;');
    expect(addNewComponent.attr('style').trim()).toEqual('display: none;');
  });

  it('hides new tag button when pressing esc key', function(){
    this.component.displayMail({}, testData);
    this.component.select('newTagButton').click();

    var e = creatingEvent('keydown', 27);
    var newTagInputComponent = this.component.select('newTagInput');
    var addNewComponent = this.component.select('addNew');

    newTagInputComponent.trigger(e);

    expect(newTagInputComponent.attr('style').trim()).toEqual('display: none;');
    expect(addNewComponent.attr('style').trim()).not.toEqual('display: none;');
  });

  it('assumes that the mail is encrypted and valid if at least one of the locks are valid', function() {
    var email = testData;
    email.security_casing = {locks: [{state: 'valid'}, {state: 'failure'}]};
    expect(this.component.checkEncrypted(email)).toEqual('encrypted encryption-valid');
  });

  it('assumes that the mail is encrypted and failure if all the locks are failed', function() {
    var email = testData;
    email.security_casing = {locks: [{state: 'failure'}, {state: 'failure'}]};
    expect(this.component.checkEncrypted(email)).toEqual('encrypted encryption-failure');
  });

  it('assumes that the mail is not encrypted if it doesn\'t have any locks', function() {
    var email = testData;
    email.security_casing = {locks: []};
    expect(this.component.checkEncrypted(email)).toEqual('not-encrypted');
  });

  it('assumes that the mail is signed only if all imprints are valid', function() {
    var email = testData;
    email.security_casing = {imprints: [{state: 'valid', seal: {trust: 'marginal', validity: 'marginal'}}, {state: 'valid', seal: {trust: 'marginal', validity: 'marginal'}}]};
    expect(this.component.checkSigned(email)).toEqual('signed');
  });

  it('assumes that the mail is signed with failures if there is a revoke or expire', function() {
    var email = testData;
    email.security_casing = {imprints: [{state: 'valid', seal: {trust: 'marginal', validity: 'marginal'}}, {state: 'from_revoked', seal: {trust: 'marginal', validity: 'marginal'}}]};
    expect(this.component.checkSigned(email)).toEqual('signed signature-revoked');
  });

  it('assumes that mail is not trusted if its signature contains no_trust from the user', function() {
    var email = testData;
    email.security_casing = {imprints: [{seal: {trust: 'no_trust', validity: 'ultimate'}}]};
    expect(this.component.checkSigned(email)).toEqual('signed signature-not-trusted');
  });

  it('uses validity when trust is not present', function() {
    var email = testData;
    email.security_casing = {imprints: [{seal: { validity: 'no_trust'}}]};
    expect(this.component.checkSigned(email)).toEqual('signed signature-not-trusted');
  });

  it('assumes not trusted when the signature is not found', function(){
    var email = testData;
    email.security_casing = {imprints: [{seal: null}]};
    expect(this.component.checkSigned(email)).toEqual('signed signature-not-trusted');
  });

  it('assumes that the mail is not signed if there are no imprints', function() {
    var email = testData;
    email.security_casing = {imprints: []};
    expect(this.component.checkSigned(email)).toEqual('not-signed');
  });

  it('assumes that there is no signature info to show', function() {
    var email = testData;
    email.security_casing = {imprints: [{state: 'no_signature_information'}]};
    expect(this.component.checkSigned(email)).toEqual('');
  });

  it('shows that mail is encrypted if it is', function() {
    spyOn(this.component, 'checkEncrypted').and.returnValue('encrypted');
    this.component.displayMail({}, testData);
    expect(this.component.$node.find('.encrypted')).toExist();
  });

  it('shows that mail is signed if it is', function() {
    spyOn(this.component, 'checkSigned').and.returnValue('signed');
    this.component.displayMail({}, testData);
    expect(this.component.$node.find('.signed')).toExist();
  });

  it('shows that mail is not encrypted if it isn\'t', function() {
    spyOn(this.component, 'checkEncrypted').and.returnValue('not-encrypted');
    this.component.displayMail({}, testData);
    expect(this.component.$node.find('.not-encrypted')).toExist();
  });

  it('shows that mail is not signed if it isn\'t', function() {
    spyOn(this.component, 'checkEncrypted').and.returnValue('not-signed');
    this.component.displayMail({}, testData);
    expect(this.component.$node.find('.not-signed')).toExist();
  });

  it('creates new tag when pressing Enter key on new tag input', function(){
    var tagsUpdateEvent = spyOnEvent(document, Pixelated.events.mail.tags.update);

    this.component.displayMail({}, testData);
    this.component.select('newTagButton').click();

    var newTagInputComponent = this.component.select('newTagInput');
    newTagInputComponent.val('Test');

    var e = creatingEvent('keydown', 13); //ENTER KEY EVENT
    newTagInputComponent.trigger(e);

    var tags = testData.mail.tags.slice();
    tags.push('Test');
    expect(tagsUpdateEvent).toHaveBeenTriggeredOnAndWith(document, { ident: testData.mail.ident, tags: tags});
  });

  it('creates new tag when pressing Enter key on new tag input', function(){
    var tagsUpdateEvent = spyOnEvent(document, Pixelated.events.mail.tags.update);

    this.component.displayMail({}, testData);
    this.component.select('newTagButton').click();

    var newTagInputComponent = this.component.select('newTagInput');
    newTagInputComponent.val('    ');

    var e = creatingEvent('keydown', 13); //ENTER KEY EVENT
    newTagInputComponent.trigger(e);

    expect(tagsUpdateEvent).not.toHaveBeenTriggeredOnAndWith(document);
  });

  it('trigger mail delete event when moving email to trash', function(){
    var mailDeleteEvent = spyOnEvent(document, Pixelated.events.ui.mail.delete);

    Foundation.global.namespace = '';
    $(document).foundation();

    this.component.displayMail({}, testData);
    this.component.moveToTrash();

    expect(mailDeleteEvent).toHaveBeenTriggeredOnAndWith(document, { mail: this.component.attr.mail });
  });

  it('shows no message selected pane when deleting the email being composed', function() {
    var openNoMessageSelectedPaneEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
    var mails = [{ident: 123}];
    this.component.attr.mail = mails[0];

    this.component.trigger(document, Pixelated.events.mail.deleted, {mails: mails});

    expect(openNoMessageSelectedPaneEvent).toHaveBeenTriggeredOn(document);
  });

  it('does not show no message selected pane when deleting a different set of emails', function() {
    var openNoMessageSelectedPaneEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
    var mails = [{ident: 321}];
    this.component.attr.mail = {ident: 123};

    this.component.trigger(document, Pixelated.events.mail.deleted, {mails: mails});

    expect(openNoMessageSelectedPaneEvent).not.toHaveBeenTriggeredOn(document);
  });

  it('opens the no message selected pane when clicking the close button', function() {
    var openNoMessageSelectedEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

    this.component.displayMail({}, testData);
    this.component.select('closeMailButton').click();

    expect(openNoMessageSelectedEvent).toHaveBeenTriggeredOn(document);
  });

  function creatingEvent(event, keyCode) {
    var e = $.Event(event);
    e.which = keyCode;
    return e;
  }
});