-
Notifications
You must be signed in to change notification settings - Fork 156
/
internal-push.test.js
121 lines (103 loc) · 3.59 KB
/
internal-push.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { randomName } = require( '../support/functions' );
describe( 'Internal Push', () => {
before( () => {
cy.login();
cy.networkActivatePlugin( 'distributor' );
} );
it( 'Should push post (As a Draft post)', () => {
const postTitle = 'Post to push ' + randomName();
cy.createPost( { title: postTitle } ).then( ( post ) => {
cy.distributorPushPost( post.id, 'second', '', 'draft' );
cy.visit( 'second/wp-admin/edit.php' );
cy.get(
'.wp-list-table tbody tr:nth-child(1) .row-title'
).contains( postTitle );
cy.get(
'.wp-list-table tbody tr:nth-child(1) .post-state'
).contains( 'Draft' );
} );
} );
it( 'Should push post (As a published post)', () => {
const postTitle = 'Post to push ' + randomName();
cy.createPost( { title: postTitle } ).then( ( post ) => {
cy.distributorPushPost( post.id, 'second', '', 'publish' );
cy.visit( 'second/wp-admin/edit.php' );
cy.get( '.wp-list-table tbody tr:nth-child(1) .row-title' )
.should( 'exist' )
.contains( postTitle );
cy.get( '.wp-list-table tbody tr:nth-child(1) .post-state' ).should(
'not.exist'
);
} );
} );
it( 'Should push sync the post data', () => {
const postTitle = 'Post to push ' + randomName();
const content = 'Test content';
const categoryName = 'Category' + randomName();
const tagName = 'Tag' + randomName();
cy.createTerm( categoryName, 'category' );
cy.createTerm( tagName, 'post_tag' );
cy.createPost( { title: postTitle, content } ).then( ( post ) => {
// Set category and tag
cy.wpCli( `post term set ${ post.id } category ${ categoryName }` );
cy.wpCli( `post term set ${ post.id } post_tag ${ tagName }` );
// Set post meta.
cy.wpCli(
`wp post meta set ${ post.id } custom_meta_key custom_meta_value`
);
// Set Featured Image
// This test is temporarily disabled due to failures in GitHub actions that are not reproducible locally.
// On GitHub the success message expected within the cy.distributorPushPost command is not found as the
// distribution fails with an undefined error.
// cy.uploadMedia( 'assets/img/banner-772x250.png' ).then(
// ( media ) => {
// if ( media && media.mediaId ) {
// cy.wpCli(
// `wp post meta set ${ post.id } _thumbnail_id ${ media.mediaId }`
// );
// }
// }
// );
cy.distributorPushPost( post.id, 'second', '', 'publish' ).then(
( distributeInfo ) => {
const siteUrl = `http://localhost/second`;
cy.visit( 'second/wp-admin/edit.php' );
// Validate title
cy.get( '.wp-list-table tbody tr:nth-child(1) .row-title' )
.should( 'exist' )
.contains( postTitle );
// validate category
cy.get(
'.wp-list-table tbody tr:nth-child(1) .column-categories'
)
.should( 'exist' )
.contains( categoryName );
// validate tag
cy.get(
'.wp-list-table tbody tr:nth-child(1) .column-tags'
)
.should( 'exist' )
.contains( tagName );
// Validate post meta
cy.wpCli(
`wp post meta get ${ distributeInfo.distributedPostId } custom_meta_key --url=${ siteUrl }`
)
.its( 'stdout' )
.should( 'contain', 'custom_meta_value' );
// validate content.
cy.wpCli(
`wp post get ${ distributeInfo.distributedPostId } --field=content --url=${ siteUrl }`
)
.its( 'stdout' )
.should( 'contain', content );
// validate featured image.
// cy.wpCli(
// `wp post meta get ${ distributeInfo.distributedPostId } _thumbnail_id --url=${ siteUrl }`
// )
// .its( 'stdout' )
// .should( 'not.empty' );
}
);
} );
} );
} );