@@ -17,20 +17,29 @@ describe('Unsubscribe form', () => {
1717
1818 cy . selectList ( '10up' ) ; // Ensure list is selected, refreshes Mailchimp data with WP
1919
20+ // Single Opt-in
21+ cy . setDoubleOptInOption ( false ) ;
22+
2023 // Check unsubscription link
21- cy . visit ( '/wp-admin/admin.php?page=mailchimp_sf_options' ) ;
22- cy . get ( '#mc_use_unsub_link' ) . check ( ) ;
23- cy . get ( 'input[value="Update Subscribe Form Settings"]' ) . first ( ) . click ( ) ;
24+ cy . setSettingsOption ( '#mc_use_unsub_link' , true ) ;
2425 } ) ;
2526
2627 after ( ( ) => {
2728 // I don't know why we have to login again, but we do
2829 cy . login ( ) ; // WP
2930
3031 // Uncheck unsubscription link
31- cy . visit ( '/wp-admin/admin.php?page=mailchimp_sf_options' ) ;
32- cy . get ( '#mc_use_unsub_link' ) . uncheck ( ) ;
33- cy . get ( 'input[value="Update Subscribe Form Settings"]' ) . first ( ) . click ( ) ;
32+ cy . setSettingsOption ( '#mc_use_unsub_link' , false ) ;
33+ } ) ;
34+
35+ it ( 'unsubscribe link appears on both shortcode and block pages' , ( ) => {
36+ [ shortcodePostURL , blockPostPostURL ] . forEach ( ( url ) => {
37+ // Visit the mailchimp block page
38+ cy . visit ( url ) ;
39+
40+ // Assert unsubscribe link exists
41+ cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'exist' ) ;
42+ } ) ;
3443 } )
3544
3645 it ( 'unsubscribes valid emails that were previously subscribed to a list' , ( ) => {
@@ -41,81 +50,90 @@ describe('Unsubscribe form', () => {
4150 cy . subscribeToList ( listId , email ) ;
4251 } ) ;
4352
44- [ shortcodePostURL , blockPostPostURL ] . forEach ( ( url ) => {
45- let baseUrl ;
53+ let baseUrl ;
4654
47- // Visit the mailchimp block page
48- cy . visit ( url ) ;
55+ // Visit the mailchimp block page
56+ cy . visit ( blockPostPostURL ) ;
4957
50- // Get baseUrl to use for later assertion
51- cy . url ( ) . then ( ( url ) => {
52- // Extract the base URL
53- const urlObject = new URL ( url ) ;
54- baseUrl = `${ urlObject . protocol } //${ urlObject . host } ` ;
55- } ) ;
56-
58+ // Get baseUrl to use for later assertion
59+ cy . url ( ) . then ( ( url ) => {
60+ // Extract the base URL
61+ const urlObject = new URL ( url ) ;
62+ baseUrl = `${ urlObject . protocol } //${ urlObject . host } ` ;
63+ } ) ;
5764
58- // Assert unsubscribe link exists
59- cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'exist' ) ;
6065
61- // Visit unsubscribe link
62- cy . get ( 'a[href*="/unsubscribe"]' )
63- . invoke ( 'removeAttr' , 'target' ) // Prevent opening in new window so that Cypress can test
64- . click ( ) ;
66+ // Assert unsubscribe link exists
67+ cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'exist' ) ;
6568
66- // Unsubscribe
67- cy . get ( '#email-address' ) . type ( email ) ;
68- cy . get ( 'input[type="submit"]' ) . click ( ) ;
69- cy . get ( 'body' ) . should ( 'contain' , 'Unsubscribe Successful' ) ;
69+ // Visit unsubscribe link
70+ cy . get ( 'a[href*="/unsubscribe"]' )
71+ . invoke ( 'removeAttr' , 'target' ) // Prevent opening in new window so that Cypress can test
72+ . click ( ) ;
7073
71- // Navigate back to the website button exists
72- cy . contains ( 'a' , 'return to our website' )
73- . should ( 'exist' ) ;
74+ // Unsubscribe
75+ cy . get ( '#email-address' ) . type ( email ) ;
76+ cy . get ( 'input[type="submit"]' ) . click ( ) ;
77+ cy . get ( 'body' ) . should ( 'contain' , 'Unsubscribe Successful' ) ;
78+
79+ // Navigate back to the website button exists
80+ cy . contains ( 'a' , 'return to our website' )
81+ . should ( 'exist' ) ;
82+
83+ // Verify contact exists in Mailchimp with status 'unsubscribed'
84+ cy . verifyContactInMailchimp ( email , '10up' , 'unsubscribed' ) . then ( ( contact ) => {
85+ cy . verifyContactStatus ( contact , 'unsubscribed' ) ;
7486
7587 // Delete contact to clean up
7688 cy . deleteContactFromList ( email ) ;
77-
78- // Navigate to website
79- // NOTE: The website URL is site in Mailchimp and it won't accept localhost or our test URL
80- // TODO: Assert that we're back on our website (we currently have no way to set this)
81- // cy.contains('a', 'return to our website').click();
82- // cy.url().should('include', baseUrl); // TODO: Do we want to assert a specific landing page?
83-
8489 } ) ;
90+
91+ // Navigate to back website
92+ // NOTE: The website URL is site in Mailchimp and it won't accept localhost or our test URL
93+ // TODO: Assert that we're back on our website (we currently have no way to set this)
94+ // cy.contains('a', 'return to our website').click();
95+ // cy.url().should('include', baseUrl); // TODO: Do we want to assert a specific landing page?
8596 } ) ;
86-
97+
8798 it ( 'throws an error when unsubscribing an email that was never subscribed to a list' , ( ) => {
8899 const email = generateRandomEmail ( 'never-subscribed-user' ) ;
89100
90- [ shortcodePostURL , blockPostPostURL ] . forEach ( ( url ) => {
91- // Visit the mailchimp block page
92- cy . visit ( url ) ;
101+ // Visit the mailchimp block page
102+ cy . visit ( blockPostPostURL ) ;
93103
94- // Assert unsubscribe link exists
95- cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'exist' ) ;
104+ // Assert unsubscribe link exists
105+ cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'exist' ) ;
96106
97- // Visit unsubscribe link
98- cy . get ( 'a[href*="/unsubscribe"]' )
99- . invoke ( 'removeAttr' , 'target' ) // Prevent opening in new window so that Cypress can test
100- . click ( ) ;
107+ // Visit unsubscribe link
108+ cy . get ( 'a[href*="/unsubscribe"]' )
109+ . invoke ( 'removeAttr' , 'target' ) // Prevent opening in new window so that Cypress can test
110+ . click ( ) ;
101111
102- // Unsubscribe
103- cy . get ( '#email-address' ) . type ( email ) ;
104- cy . get ( 'input[type="submit"]' ) . click ( ) ;
112+ // Unsubscribe
113+ cy . get ( '#email-address' ) . type ( email ) ;
114+ cy . get ( 'input[type="submit"]' ) . click ( ) ;
105115
106- // Assert that the unsubscribe didn't work because the email isn't subscribed
107- cy . get ( '.errorText' ) . should ( 'contain' , 'this email is not subscribed' ) ;
108-
109- } ) ;
116+ // Assert that the unsubscribe didn't work because the email isn't subscribed
117+ cy . get ( '.errorText' ) . should ( 'contain' , 'this email is not subscribed' ) ;
110118 } ) ;
111119
112- // TODO: Test not written yet
113- it . skip ( 'does not display an unsubscribe link when the unsubscribe option is disabled' , ( ) => {
114- // Test here...
115- } ) ;
120+ it ( 'does not display an unsubscribe link when the unsubscribe option is disabled' , ( ) => {
121+ // Not sure why we have to login for this test, but we do
122+ cy . login ( ) ; // WP
116123
117- // TODO: Test not written yet
118- it . skip ( 'redirects the user back to the website when the user is finished unsubscribing and clicks the back link' , ( ) => {
119- // Test here...
124+ // Uncheck unsubscription link
125+ cy . setSettingsOption ( '#mc_use_unsub_link' , false ) ;
126+
127+ [ shortcodePostURL , blockPostPostURL ] . forEach ( ( url ) => {
128+ // Visit the mailchimp block page
129+ cy . visit ( url ) ;
130+
131+ // Assert unsubscribe link exists
132+ cy . get ( 'a[href*="/unsubscribe"]' ) . should ( 'not.exist' ) ;
133+ } ) ;
120134 } ) ;
135+
136+ // NOTE: We can not set the "return to website" URL from the Mailchimp plugin or through the API.
137+ // Alternative proposals on issue #91 and #92 to add a user tutorial
138+ // it.skip('redirects the user back to the website when the user is finished unsubscribing and clicks the back link', () => {});
121139} ) ;
0 commit comments