Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit dc02d7c

Browse files
committed
Merge pull request #2833 from DFurnes/campaign-tests
Campaign tests
2 parents e535a96 + f6c0821 commit dc02d7c

File tree

8 files changed

+181
-24
lines changed

8 files changed

+181
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
tmp/
12
.vagrant
23
*.DS_Store
34
html/

scripts/tests/before_tests.sh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,51 @@
55
# Tasks to run before functional testing.
66
# ==============================================================================
77

8-
printf "\n\033[1;33mPerforming pre-test steps...\033[00m\n"
8+
printf "\033[1;33mPerforming pre-test steps...\033[00m\n"
99

1010
cd /var/www/vagrant/html
1111

1212
# Clear out localhost from flood table (prevents "more than 5 failed login attempts" error)
13+
echo "Clearing localhost from flood table..."
1314
drush sql-query "DELETE FROM flood WHERE identifier LIKE '%127.0.0.1';"
1415

15-
1616
# Create fresh test accounts
17+
drush_get_uid_from_email() {
18+
drush user-information $1 | grep "User ID" | sed -e 's/[ ]*User ID[ ]*\:[ ]*//g' | sed -e 's/[ ]*//g'
19+
}
20+
1721
drush_create_test_user() {
18-
{
19-
USERNAME=$1
20-
drush user-create $USERNAME --mail="$USERNAME@example.com" --password="$USERNAME"
21-
} &> /dev/null
22+
USERNAME=$1
23+
drush user-create $USERNAME --mail="$USERNAME@example.com" --password="$USERNAME"
2224
}
2325

2426
drush_delete_user_with_email() {
27+
uid=$(drush_get_uid_from_email $1)
2528
{
26-
drush user-information $1 | grep "User ID" | sed -e 's/[ ]*User ID[ ]*\:[ ]*//g' | xargs -i drush user-cancel {} -y &> /dev/null
29+
if [[ $uid -ne 0 ]]
30+
then
31+
drush user-cancel "$uid" -y --quiet
32+
fi
2733
} &> /dev/null
2834
}
2935

30-
echo "Creating fresh test accounts..."
31-
## Delete users created during previous test runs...
36+
drush_signup_user() {
37+
uid=$(drush_get_uid_from_email $2)
38+
drush php-eval "dosomething_signup_create($1, $uid)"
39+
}
40+
41+
echo "Deleting users created during previous test runs..."
3242
drush_delete_user_with_email QA_TEST_ACCOUNT@example.com
3343
drush_delete_user_with_email QA_TEST_USER_REGISTER@example.com
3444
drush_delete_user_with_email QA_TEST_CAMPAIGN_SIGNUP_EXISTING@example.com
3545
drush_delete_user_with_email QA_TEST_CAMPAIGN_SIGNUP_NEW@example.com
46+
drush_delete_user_with_email QA_TEST_CAMPAIGN_ACTION@example.com
3647

37-
## Make fresh test accounts...
48+
echo "Making fresh test accounts..."
3849
drush_create_test_user QA_TEST_ACCOUNT
3950
drush_create_test_user QA_TEST_CAMPAIGN_SIGNUP_EXISTING
51+
drush_create_test_user QA_TEST_CAMPAIGN_ACTION
4052

53+
echo "Signing action page test account up for test campaign..."
54+
example_campaign_nid=1261
55+
drush_signup_user $example_campaign_nid QA_TEST_CAMPAIGN_ACTION@example.com

scripts/tests/common.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ var url = casper.cli.get('url');
99
casper.options.viewportSize = { width: 1280, height: 1024 };
1010

1111
// Use to log in before performing a test.
12-
casper.login = function() {
13-
this.echo("Logging in as test user.");
12+
casper.login = function(username, password) {
13+
// If no arguments are given, log in using default test account
14+
username = typeof username == "string" ? username : "QA_TEST_ACCOUNT@example.com";
15+
password = typeof password == "string" ? password : "QA_TEST_ACCOUNT";
16+
17+
this.echo("Logging in as: " + username);
1418

1519
// Go home and login.
1620
casper.thenOpen(url + "/user", function() {
1721
this.fill('form[action="/user/login"]', {
18-
name: 'QA_TEST_ACCOUNT@example.com',
19-
pass: 'QA_TEST_ACCOUNT'
22+
name: username,
23+
pass: password
2024
}, true);
2125
});
2226
}
@@ -29,6 +33,11 @@ casper.logout = function() {
2933
});
3034
}
3135

36+
// We want to start at the homepage on each test.
37+
casper.test.setUp(function() {
38+
casper.start(url);
39+
});
40+
3241
// We want to clear session after every test.
3342
casper.test.tearDown(function() {
3443
phantom.clearCookies();

tests/campaign/action.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* action.js
3+
* Test action page is rendered correctly
4+
*/
5+
6+
var x = require('casper').selectXPath;
7+
8+
casper.test.begin("Test action page is rendered correctly", 22, function suite(test) {
9+
casper.login("QA_TEST_CAMPAIGN_ACTION@example.com", "QA_TEST_CAMPAIGN_ACTION");
10+
11+
// ## Header
12+
casper.thenOpen(url + "/campaigns/test-campaign", function() {
13+
// We expect to see the title and subtitle of the campaign
14+
test.assertSelectorHasText("header[role='banner'].-hero .__title", "Test Campaign", "Title of campaign is printed in H1.");
15+
test.assertSelectorHasText("header[role='banner'].-hero .__subtitle", "This is a test unsponsored campaign.", "Subtitle of campaign is printed in H2.");
16+
});
17+
18+
// ## Know It
19+
casper.then(function() {
20+
test.assertSelectorHasText("#know .container__title", "Step 1: Know It", "\"Know It\" banner exists.");
21+
this.captureSelector("tmp/tests/step1.png", "#know");
22+
23+
test.assertNotVisible("[data-modal]", "Modals are hidden on page load.")
24+
25+
casper.click(x('//*[text()="Check out our FAQs"]'));
26+
this.waitUntilVisible("#modal-faq", function() {
27+
test.assertSelectorHasText("#modal-faq", "Why is 'fee awesome?", "FAQ modal displays on click.");
28+
});
29+
});
30+
31+
casper.then(function() {
32+
casper.click("#modal-faq .js-close-modal");
33+
this.waitWhileVisible("#modal-faq", function() {
34+
test.assert(true, "Clicking the close button hides the modal.")
35+
});
36+
});
37+
38+
casper.then(function() {
39+
casper.click(x('//*[text()="Learn more about Coffee"]'));
40+
this.waitUntilVisible("#modal-facts", function() {
41+
test.assertSelectorHasText("#modal-facts", "1 in 3 teenagers have slept through math", "Fact modal displays on click.");
42+
});
43+
});
44+
45+
// ## Plan It
46+
casper.then(function() {
47+
test.assertSelectorHasText("#plan .container__title", "Step 2: Plan It", "\"Plan It\" banner exists.");
48+
this.captureSelector("tmp/tests/step2.png", "#plan");
49+
});
50+
51+
// ## Do It
52+
casper.then(function() {
53+
test.assertSelectorHasText("#do .container__title", "Step 3: Do It", "\"Do It\" banner exists.");
54+
this.captureSelector("tmp/tests/step3.png", "#do");
55+
56+
57+
// @NOTE: Can't use assertVisible() because of "visually-hidden" mixin trickiness.
58+
test.assertExists("#tip-1.is-active", "First tip is visible on page load.");
59+
test.assertDoesntExist("#tip-2.is-active", "Second tip is hidden on page load.");
60+
61+
casper.click(x('//*[text()="Give Him \'Fee"]'));
62+
63+
test.assertDoesntExist("#tip-1.is-active", "First tip is hidden after clicking second tip link.");
64+
test.assertExists("#tip-2.is-active", "Second tip is visible after clicking second tip link.");
65+
});
66+
67+
// ## Prove It
68+
casper.then(function() {
69+
test.assertSelectorHasText("#prove .container__title", "Step 4: Prove It", "\"Prove It\" banner exists.");
70+
this.captureSelector("tmp/tests/step4.png", "#prove");
71+
72+
casper.click(".info-bar .help a");
73+
this.waitUntilVisible("#modal-contact-form", function() {
74+
test.assertSelectorHasText("#modal-contact-form", "Enter your question below.", "Zendesk modal displays on click.");
75+
});
76+
});
77+
78+
casper.then(function() {
79+
casper.click("#modal-contact-form .js-close-modal");
80+
});
81+
82+
// ## Report Back
83+
casper.then(function() {
84+
casper.click(x('//*[text()="Submit Your Pic"]'));
85+
this.waitUntilVisible("[data-modal]", function() {
86+
test.assertSelectorHasText("#modal-report-back", "Prove It", "Report Back modal displays on click.");
87+
});
88+
});
89+
90+
casper.then(function() {
91+
this.fill("form[action='/campaigns/test-campaign']", {
92+
"files[reportback_file]": "tests/fixtures/reportback-image.png",
93+
"quantity": "10",
94+
"why_participated": "Test response."
95+
}, true);
96+
});
97+
98+
99+
// Confirmation page
100+
casper.then(function() {
101+
test.assertSelectorHasText("header[role='banner'] .__title", "You did it!", "Confirmation page shown after report back.");
102+
test.assertSelectorHasText("header[role='banner'] .__subtitle", "You sure drank that 'fee. Good work!", "Campaign confirmation message is shown in subtitle.");
103+
104+
test.assertElementCount(".gallery .gallery-item", 3, "Three suggested campaigns are shown.");
105+
106+
casper.click(x('//*[text()="Back to Test Campaign"]'));
107+
});
108+
109+
// Check that reportback submitted successfully.
110+
casper.then(function() {
111+
casper.click(x('//*[text()="Update Submission"]'));
112+
this.waitUntilVisible("[data-modal]", function() {
113+
test.assertExists("#modal-report-back .submitted-image img", "Submitted report back image is shown.")
114+
test.assertField("quantity", "10", "Submitted quantity is shown for editing.")
115+
test.assertField("why_participated", "Test response.", "Submitted 'Why Participated?' is shown for editing.")
116+
});
117+
});
118+
119+
casper.run(function() {
120+
test.done();
121+
});
122+
});
123+
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ casper.test.begin("Test that an unregistered user can register & sign up for a c
2727

2828
casper.thenOpen(url + "/campaigns/test-campaign", function(){
2929
// We expect to see a sign up button, and to be able to click it to sign up.
30-
this.click("#link--campaign-signup-login");
30+
31+
this.waitUntilVisible("#link--campaign-signup-login", function() {
32+
this.click("#link--campaign-signup-login");
33+
});
3134

32-
this.waitUntilVisible(".modal-content", function() {
35+
this.waitUntilVisible("[data-modal]", function() {
3336
this.click("#link--register");
3437
});
3538
});
@@ -60,9 +63,11 @@ casper.test.begin("Test that a logged-out user can log in & sign up for a campai
6063

6164
casper.thenOpen(url + "/campaigns/test-campaign", function(){
6265
// We expect to see a sign up button, and to be able to click it to sign up.
63-
this.click("#link--campaign-signup-login");
66+
this.waitUntilVisible("#link--campaign-signup-login", function() {
67+
this.click("#link--campaign-signup-login");
68+
});
6469

65-
this.waitUntilVisible(".modal-content", function() {
70+
this.waitUntilVisible("[data-modal]", function() {
6671
this.fill("form#user-login-form", {
6772
name: 'QA_TEST_CAMPAIGN_SIGNUP_EXISTING@example.com',
6873
pass: 'QA_TEST_CAMPAIGN_SIGNUP_EXISTING'
22.4 KB
Loading

tests/user/login.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ casper.test.begin('Test that a user can authenticate correctly.', 6, function su
1616
this.click("#link--login");
1717

1818
// We should see a modal with the login form.
19-
this.waitUntilVisible(".modal-content", function() {
20-
test.assertExists(".modal-content form[action='/user/login']", "Clicking the login link shows modal login form");
19+
this.waitUntilVisible("[data-modal]", function() {
20+
test.assertExists("[data-modal] form[action='/user/login']", "Clicking the login link shows modal login form");
2121
});
2222
});
2323

@@ -36,10 +36,12 @@ casper.test.begin('Test that a user can authenticate correctly.', 6, function su
3636

3737
casper.thenOpen(url, function() {
3838
// Now let's go back home and login using the login modal.
39-
this.click("#link--login");
39+
this.waitUntilVisible("#link--login", function() {
40+
this.click("#link--login");
41+
});
4042

4143
// We should see a modal with the login form.
42-
this.waitUntilVisible(".modal-content", function() {
44+
this.waitUntilVisible("[data-modal]", function() {
4345
this.fill('form[action="/user/login"]', {
4446
name: 'QA_TEST_ACCOUNT@example.com',
4547
pass: 'QA_TEST_ACCOUNT'

tests/user/register.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Test that a user can create an account.
44
*/
55

6+
var REGISTER_SUCCESSFUL_MESSAGE = "You've created an account";
7+
68
casper.test.begin("Test that a user can create an account.", 4, function suite(test) {
79
casper.start(url);
810

@@ -13,7 +15,7 @@ casper.test.begin("Test that a user can create an account.", 4, function suite(t
1315
// Click the login link in the header navigation menu.
1416
this.click("#link--login");
1517

16-
this.waitUntilVisible(".modal-content", function() {
18+
this.waitUntilVisible("[data-modal]", function() {
1719
this.click("#link--register");
1820

1921
// Enter with some incorrect fields (email and confirmation)
@@ -44,7 +46,7 @@ casper.test.begin("Test that a user can create an account.", 4, function suite(t
4446

4547
// This should be fine, so let's look for a successful confirmation message.
4648
casper.waitForSelector(".messages", function() {
47-
test.assertSelectorHasText(".messages", "Registration successful");
49+
test.assertSelectorHasText(".messages", REGISTER_SUCCESSFUL_MESSAGE);
4850
});
4951
});
5052

0 commit comments

Comments
 (0)