Skip to content

Commit

Permalink
Merge pull request #8533 from owncloud/ocis-notifications-e2e
Browse files Browse the repository at this point in the history
[tests-only] Add notification e2e tests
  • Loading branch information
JammingBen committed Mar 10, 2023
2 parents 62100dc + 5005753 commit 399aa4c
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .drone.env
@@ -1,3 +1,3 @@
# The version of OCIS to use in pipelines that test against OCIS
OCIS_COMMITID=964263489149108b3953828dccf2e91264ce5f25
OCIS_COMMITID=0f77acab45991f77ec24a863186026636b1b2818
OCIS_BRANCH=master
29 changes: 29 additions & 0 deletions tests/e2e/cucumber/features/smoke/notifications.oc10.feature
@@ -0,0 +1,29 @@
Feature: Notifications
As a user
I want to be notified
About new things that concern me

Background:
Given "Admin" creates following users
| id |
| Alice |
| Brian |
And "Admin" sets the default folder for received shares to "Shares"
And "Admin" disables share auto accepting

Scenario: User should be able to read and dismiss notifications
Given "Alice" creates the following folder in personal space using API
| name |
| folder_to_shared |
And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |
When "Brian" logs in
Then "Brian" should see the following notifications
| message |
| "Alice Hansen" invited you to view "folder_to_shared" |
And "Brian" marks all notifications as read
Then "Brian" should see no notifications
And "Alice" logs out
68 changes: 68 additions & 0 deletions tests/e2e/cucumber/features/smoke/notifications.ocis.feature
@@ -0,0 +1,68 @@
Feature: Notifications
As a user
I want to be notified
About new things that concern me

Background:
Given "Admin" creates following users
| id |
| Alice |
| Brian |
And "Admin" assigns following roles to the users using API
| id | role |
| Alice | Space Admin |

Scenario: User should be able to read and dismiss notifications
Given "Alice" creates the following folder in personal space using API
| name |
| folder_to_shared |
And "Alice" creates the following project space using API
| name | id |
| team | team.1 |
And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |
And "Alice" navigates to the projects space page
And "Alice" navigates to the project space "team.1"
And "Alice" adds following users to the project space
| user | role | kind |
| Brian | editor | user |
When "Brian" logs in
Then "Brian" should see the following notifications
| message |
| Alice Hansen shared folder_to_shared with you |
| Alice Hansen added you to Space team |
And "Brian" marks all notifications as read
Then "Brian" should see no notifications
When "Alice" opens the "files" app
And "Alice" removes following sharee
| resource | recipient |
| folder_to_shared | Brian |
And "Alice" navigates to the projects space page
And "Alice" navigates to the project space "team.1"
And "Alice" removes access to following users from the project space
| user | role | kind |
| Brian | editor | user |
When "Brian" reloads the page
Then "Brian" should see the following notifications
| message |
| Alice Hansen unshared folder_to_shared with you |
| Alice Hansen removed you from Space team |
And "Brian" marks all notifications as read
Then "Brian" should see no notifications
And "Brian" logs out
When "Alice" opens the "admin-settings" app
And "Alice" navigates to the project spaces management page
And "Alice" disables the space "team.1" using the context-menu
And "Alice" reloads the page
Then "Alice" should see the following notifications
| message |
| Alice Hansen disabled Space team |
And "Alice" deletes the space "team.1" using the context-menu
And "Alice" reloads the page
Then "Alice" should see the following notifications
| message |
| Alice Hansen deleted Space team |
And "Alice" logs out
35 changes: 35 additions & 0 deletions tests/e2e/cucumber/steps/ui/notifications.ts
@@ -0,0 +1,35 @@
import { DataTable, Then, When } from '@cucumber/cucumber'
import { World } from '../../environment'
import { objects } from '../../../support'
import { expect } from '@playwright/test'

Then(
'{string} should see the following notification(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const application = new objects.runtime.Application({ page })
const messages = await application.getNotificationMessages()
for (const { message } of stepTable.hashes()) {
expect(messages).toContain(message)
}
}
)

Then(
'{string} should see no notification(s)',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const application = new objects.runtime.Application({ page })
const messages = await application.getNotificationMessages()
expect(messages.length).toBe(0)
}
)

When(
'{string} marks all notifications as read',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const application = new objects.runtime.Application({ page })
await application.markNotificationsAsRead()
}
)
30 changes: 30 additions & 0 deletions tests/e2e/support/objects/runtime/application.ts
Expand Up @@ -3,6 +3,12 @@ import util from 'util'

const appSwitcherButton = '#_appSwitcherButton'
const appSelector = `//ul[contains(@class, "applications-list")]//a[@href="#/%s" or @href="/%s"]`
const notificationsBell = `#oc-notifications-bell`
const notificationsDrop = `#oc-notifications-drop`
const notificationsLoading = `#oc-notifications-drop .oc-notifications-loading`
const markNotificationsAsReadButton = `#oc-notifications-drop .oc-notifications-mark-all`
const notificationItemsMessages = `#oc-notifications-drop .oc-notifications-item .oc-notifications-message`

export class Application {
#page: Page

Expand All @@ -18,4 +24,28 @@ export class Application {
await this.#page.locator(appSwitcherButton).click()
await this.#page.locator(util.format(appSelector, name, name)).click()
}

async getNotificationMessages(): Promise<string[]> {
const dropIsOpen = await this.#page.locator(notificationsDrop).isVisible()
if (!dropIsOpen) {
await this.#page.locator(notificationsBell).click()
}
await this.#page.waitForSelector(notificationsLoading, { state: 'detached' })
const result = this.#page.locator(notificationItemsMessages)
const messages = []
const count = await result.count()
for (let i = 0; i < count; i++) {
messages.push(await result.nth(i).innerText())
}
return messages
}

async markNotificationsAsRead(): Promise<void> {
const dropIsOpen = await this.#page.locator(notificationsDrop).isVisible()
if (!dropIsOpen) {
await this.#page.locator(notificationsBell).click()
}
await this.#page.waitForSelector(notificationsLoading, { state: 'detached' })
await this.#page.locator(markNotificationsAsReadButton).click()
}
}

0 comments on commit 399aa4c

Please sign in to comment.