File size: 4,003 Bytes
1e92f2d |
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
/**
* @group calypso-pr
*/
import {
DataHelper,
NavbarComponent,
NotificationsComponent,
RestAPIClient,
TestAccount,
NewCommentResponse,
PostResponse,
envVariables,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { skipDescribeIf } from '../../jest-helpers';
declare const browser: Browser;
/**
* Tests general interaction with the notification panel, running through
* all actions once.
*/
skipDescribeIf( envVariables.VIEWPORT_NAME === 'mobile' )(
'Notifications: General Interactions',
function () {
const comment = DataHelper.getRandomPhrase() + ' notification-actions-spec';
// TestAccount and RestAPI instances.
let commentingUser: TestAccount;
let notificationsUser: TestAccount;
let commentingUserRestAPIClient: RestAPIClient;
let notificationUserRestAPIClient: RestAPIClient;
// API responses.
let newPost: PostResponse;
let newComment: NewCommentResponse;
let notificationsComponent: NotificationsComponent;
let page: Page;
beforeAll( async function () {
// Create an instance of RestAPI as the user making the comment.
commentingUser = new TestAccount( 'commentingUser' );
commentingUserRestAPIClient = new RestAPIClient( commentingUser.credentials );
// Create an instance of RestAPI as the user receiving notification.
notificationsUser = new TestAccount( 'notificationsUser' );
notificationUserRestAPIClient = new RestAPIClient( notificationsUser.credentials );
// Create a new post and store the response.
newPost = await notificationUserRestAPIClient.createPost(
notificationsUser.credentials.testSites?.primary.id as number,
{ title: DataHelper.getRandomPhrase() }
);
// Create a new comment on the post as the commentingUser and
// store the response.
newComment = await commentingUserRestAPIClient.createComment(
notificationsUser.credentials.testSites?.primary.id as number,
newPost.ID,
comment
);
// Log in as the user receiving the notification.
page = await browser.newPage();
await notificationsUser.authenticate( page, { waitUntilStable: true } );
} );
it( 'Open Notifications panel', async function () {
const navbarComponent = new NavbarComponent( page );
await navbarComponent.openNotificationsPanel();
} );
it( 'Click notification for the comment', async function () {
notificationsComponent = new NotificationsComponent( page );
await notificationsComponent.openNotification( comment );
} );
it( 'Approve comment', async function () {
await notificationsComponent.clickNotificationAction( 'Approve' );
} );
it( 'Like comment', async function () {
await notificationsComponent.clickNotificationAction( 'Like' );
} );
it( 'Mark comment as spam', async function () {
await notificationsComponent.clickNotificationAction( 'Spam' );
await notificationsComponent.clickUndo();
} );
it( 'Trash comment', async function () {
await notificationsComponent.clickNotificationAction( 'Trash' );
} );
afterAll( async function () {
if ( ! newComment ) {
return;
}
// Clean up the comment.
try {
await notificationUserRestAPIClient.deleteComment(
notificationsUser.credentials.testSites?.primary.id as number,
newComment.ID
);
} catch ( e: unknown ) {
console.warn(
`Failed to clean up test comment in notification_action spec for site ${
notificationsUser.credentials.testSites?.primary.id as number
}, comment ${ newComment.ID }`
);
}
if ( ! newPost ) {
return;
}
// Clean up the post.
try {
await notificationUserRestAPIClient.deletePost(
notificationsUser.credentials.testSites?.primary.id as number,
newPost.ID
);
} catch ( e: unknown ) {
console.warn(
`Failed to clean up test comment in notification_action spec for site ${
notificationsUser.credentials.testSites?.primary.id as number
}, comment ${ newComment.ID }`
);
}
} );
}
);
|