This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
test.js
99 lines (79 loc) · 3.09 KB
/
test.js
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
var page = require("webpage").create()
page.open("./index.html", function(status) {
var result = page.evaluate(function() {
var buildFailed = false
var thisBuildFailed = false
var messages = []
var firstCell = $(".cell").first()
var lastCell = $(".cell").last()
test("Pen works", function() {
firstCell.mousedown()
expectEqual($(".cell[data-emoji=':star:']").length, 1, "One cell be star")
expectEqual(firstCell.attr("data-emoji"), ":star:", "This cell be star")
})
test("Change emoji paint works", function() {
$(".js-paint").focus()
$("[alt=':100:']").parents(".js-emoji").click()
lastCell.mousedown()
expectEqual($(".js-paint").val(), ":100:", "Paint be 100")
expectEqual(lastCell.attr('data-emoji'), ":100:", "This cell be 100")
expectEqual($(".cell[data-emoji=':100:']").length, 1, "One cell be 100")
})
test("Sip works", function() {
firstCell.find(".js-sip").click()
expectEqual($(".js-paint").val(), ":star:", "Paint be star")
})
test("Erasing works", function() {
firstCell.mousedown()
expectEqual($(".cell[data-emoji=':star:']").length, 0, "No cells be star")
expectEqual(firstCell.attr("data-emoji"), ":white_large_square:", "This cell not star")
})
test("Bucketfy works", function() {
$('.js-bucketfy').click()
firstCell.mousedown()
expectEqual($(".cell[data-emoji=':star:']").length, 143, "All cells but one be star")
})
test("Emoji background works", function() {
$(".js-set-emoji-background").focus()
$("[alt=':scream:']").parents(".js-emoji").click()
expectEqual(Boolean($(".grid").css("background-image").match(/scream.png/)), true, "Background be scream")
})
test("Reset works", function() {
$(".js-reset").click()
expectEqual($(".cell[data-emoji=':white_large_square:']").length, 144, "All cells back to default")
})
test("Output script works", function() {
$(".js-output-script").click()
expectEqual(Boolean($(".js-emoji-script").val()), true, "Emoji script is generated")
expectEqual(Boolean($(".js-hubot-script").val()), true, "Hubot script is generated")
})
function test(topic, testing) {
thisBuildFailed = false
messages.push("# " + topic + "\n")
testing()
if(!thisBuildFailed) {
messages.push("YES!\n\n")
}
}
function expectEqual(evaluation, expectation, message) {
if(evaluation != expectation) {
buildFailed = true
thisBuildFailed = true
messages.push("– " + message + "\n")
messages.push(" Expected " + expectation + ", got " + evaluation + "\n\n")
}
}
return {buildFailed: buildFailed, messages: messages}
})
reveal(result)
})
function reveal(result) {
console.log(result.messages.join(""))
if(result.buildFailed) {
console.log("😢 \x1B[91mNo good, something failed.\x1B[0m 💥\n")
phantom.exit(result.buildFailed)
} else {
console.log("✨ \x1B[96mWho's awesome? You're awesome!\x1B[0m 👍\n")
phantom.exit()
}
}