-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permafail E2E: fix Notifications spec. (#78616)
* packages/calypso-e2e/src/secrets/encrypted.enc - migrate commentingUser to the new schema. * packages/calypso-e2e/src/lib/components/notifications-component.ts - refactor the component POM to use modern meethods. packages/calypso-e2e/src/lib/test-account.ts - add new flag for `authenticate` call to allow waiting for the full load. test/e2e/specs/infrastructure/notification__actions.ts - refactor the spec to only perform one action, not to perform and undo the action. * test/e2e/specs/infrastructure/notification__actions.ts - explain the purpose of the spec with JSDoc. - rename the file. packages/calypso-e2e/src/lib/test-account.ts - change optional parameter for `authenticate` to "waitUntiLStable".
- Loading branch information
1 parent
223926c
commit 0e0c171
Showing
5 changed files
with
152 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
130 changes: 130 additions & 0 deletions
130
test/e2e/specs/infrastructure/notifications__general-interaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* @group calypso-pr | ||
*/ | ||
|
||
import { | ||
DataHelper, | ||
NavbarComponent, | ||
NotificationsComponent, | ||
RestAPIClient, | ||
TestAccount, | ||
NewCommentResponse, | ||
PostResponse, | ||
} from '@automattic/calypso-e2e'; | ||
import { Page, Browser } from 'playwright'; | ||
|
||
declare const browser: Browser; | ||
|
||
/** | ||
* Tests general interaction with the notification panel, running through | ||
* all actions once. | ||
*/ | ||
describe( '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 }` | ||
); | ||
} | ||
} ); | ||
} ); |