This repository was archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathaction.js
More file actions
123 lines (97 loc) · 4.69 KB
/
action.js
File metadata and controls
123 lines (97 loc) · 4.69 KB
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
/**
* action.js
* Test action page is rendered correctly
*/
var x = require('casper').selectXPath;
casper.test.begin("Test action page is rendered correctly", 22, function suite(test) {
casper.login("QA_TEST_CAMPAIGN_ACTION@example.com", "QA_TEST_CAMPAIGN_ACTION");
// ## Header
casper.thenOpen(url + "/campaigns/test-campaign", function() {
// We expect to see the title and subtitle of the campaign
test.assertSelectorHasText("header[role='banner'].-hero .__title", "Test Campaign", "Title of campaign is printed in H1.");
test.assertSelectorHasText("header[role='banner'].-hero .__subtitle", "This is a test unsponsored campaign.", "Subtitle of campaign is printed in H2.");
});
// ## Know It
casper.then(function() {
test.assertSelectorHasText("#know .container__title", "Step 1: Know It", "\"Know It\" banner exists.");
this.captureSelector("tmp/tests/step1.png", "#know");
test.assertNotVisible("[data-modal]", "Modals are hidden on page load.")
casper.click(x('//*[text()="Check out our FAQs"]'));
this.waitUntilVisible("#modal-faq", function() {
test.assertSelectorHasText("#modal-faq", "Why is 'fee awesome?", "FAQ modal displays on click.");
});
});
casper.then(function() {
casper.click("#modal-faq .js-close-modal");
this.waitWhileVisible("#modal-faq", function() {
test.assert(true, "Clicking the close button hides the modal.")
});
});
casper.then(function() {
casper.click(x('//*[text()="Learn more about Coffee"]'));
this.waitUntilVisible("#modal-facts", function() {
test.assertSelectorHasText("#modal-facts", "1 in 3 teenagers have slept through math", "Fact modal displays on click.");
});
});
// ## Plan It
casper.then(function() {
test.assertSelectorHasText("#plan .container__title", "Step 2: Plan It", "\"Plan It\" banner exists.");
this.captureSelector("tmp/tests/step2.png", "#plan");
});
// ## Do It
casper.then(function() {
test.assertSelectorHasText("#do .container__title", "Step 3: Do It", "\"Do It\" banner exists.");
this.captureSelector("tmp/tests/step3.png", "#do");
// @NOTE: Can't use assertVisible() because of "visually-hidden" mixin trickiness.
test.assertExists("#tip-1.is-active", "First tip is visible on page load.");
test.assertDoesntExist("#tip-2.is-active", "Second tip is hidden on page load.");
casper.click(x('//*[text()="Give Him \'Fee"]'));
test.assertDoesntExist("#tip-1.is-active", "First tip is hidden after clicking second tip link.");
test.assertExists("#tip-2.is-active", "Second tip is visible after clicking second tip link.");
});
// ## Prove It
casper.then(function() {
test.assertSelectorHasText("#prove .container__title", "Step 4: Prove It", "\"Prove It\" banner exists.");
this.captureSelector("tmp/tests/step4.png", "#prove");
casper.click(".info-bar .help a");
this.waitUntilVisible("#modal-contact-form", function() {
test.assertSelectorHasText("#modal-contact-form", "Enter your question below.", "Zendesk modal displays on click.");
});
});
casper.then(function() {
casper.click("#modal-contact-form .js-close-modal");
});
// ## Report Back
casper.then(function() {
casper.click(x('//*[text()="Submit Your Pic"]'));
this.waitUntilVisible("[data-modal]", function() {
test.assertSelectorHasText("#modal-report-back", "Prove It", "Report Back modal displays on click.");
});
});
casper.then(function() {
this.fill("form[action='/campaigns/test-campaign']", {
"files[reportback_file]": "tests/fixtures/reportback-image.png",
"quantity": "10",
"why_participated": "Test response."
}, true);
});
// Confirmation page
casper.then(function() {
test.assertSelectorHasText("header[role='banner'] .__title", "You did it!", "Confirmation page shown after report back.");
test.assertSelectorHasText("header[role='banner'] .__subtitle", "You sure drank that 'fee. Good work!", "Campaign confirmation message is shown in subtitle.");
test.assertElementCount(".gallery .gallery-item", 3, "Three suggested campaigns are shown.");
casper.click(x('//*[text()="Back to Test Campaign"]'));
});
// Check that reportback submitted successfully.
casper.then(function() {
casper.click(x('//*[text()="Update Submission"]'));
this.waitUntilVisible("[data-modal]", function() {
test.assertExists("#modal-report-back .submitted-image img", "Submitted report back image is shown.")
test.assertField("quantity", "10", "Submitted quantity is shown for editing.")
test.assertField("why_participated", "Test response.", "Submitted 'Why Participated?' is shown for editing.")
});
});
casper.run(function() {
test.done();
});
});