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
|
define([], function() {
'use strict';
function toBeRenderedInMatcher () {
return {
compare: function (mail, node) {
var result = {}, subject, tags, from, date, messages = [], notMessages = [];
subject = node.find('#mail-' + mail.ident + ' .subject-and-tags')[0];
tags = _.map(node.find('#mail-' + mail.ident + ' .subject-and-tags .tag'), function (tag) { return tag.textContent; });
date = node.find('#mail-' + mail.ident + ' .received-date');
from = node.find('#mail-' + mail.ident + ' .from');
if (subject && subject.textContent.trim() === mail.header.subject) {
result.pass = true;
notMessages.push('not to be rendered with subject ' + mail.header.subject);
} else {
result.pass = false;
messages.push('to be rendered with subject ' + mail.header.subject + ', but was rendered with subject ' + subject.textContent.trim());
}
if (tags && tags.join(', ') === mail.tags.join(', ')) {
result.pass &= true;
notMessages.push('not to be rendered with tags ' + mail.tags.join(', '));
} else {
result.pass |= false;
messages.push('to be rendered with tags ' + mail.tags.join(', ') + ', but was rendered with subject ' + tags.join(', '));
}
if (date && date.text().trim() === mail.header.date.split('T')[0]) {
result.pass &= true;
notMessages.push('not to be rendered with date ' + mail.header.date.split('T')[0]);
} else {
result.pass |= false;
messages.push('to be rendered with date ' + mail.header.date.split('T')[0] + ', but was rendered with date ' + date.text().trim());
}
if (from && from.text().trim() === mail.header.from) {
result.pass &= true;
notMessages.push('not to be rendered with from ' + mail.header.from);
} else {
result.pass |= false;
messages.push('to be rendered with from ' + mail.header.from + ', but was rendered with from ' + from.text().trim());
}
if (result.pass) {
result.message = 'Expected mail ' + mail.ident + ' ' + notMessages.join(', ');
} else {
result.message = 'Expected mail ' + mail.ident + ' ' + messages.join(', ');
}
return result;
}
};
}
function toBeRenderedSelectedInMatcher () {
return {
compare: function (mail, node) {
var result = {}, toBeRendered, mailNode;
toBeRendered = toBeRenderedInMatcher().compare(mail, node);
mailNode = node.find('#mail-' + mail.ident);
result.pass = toBeRendered.pass && mailNode.hasClass('selected');
if (result.pass) {
result.message = toBeRendered.message + '\nExpected mail ' + mail.ident + ' to not be selected in ' + mailNode.html();
} else {
result.message = toBeRendered.message + '\nExpected mail ' + mail.ident + ' to be selected in ' + mailNode.html();
}
return result;
}
};
}
return {
toBeRenderedIn: toBeRenderedInMatcher,
toBeRenderedSelectedIn: toBeRenderedSelectedInMatcher
};
});
|