Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci]Add tests for ocm #11693

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/e2e/cucumber/features/ocm/ocm.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ Feature: federation management
| pathToFile | content |
| example1.txt | example text |
And "Alice" logs in
And "Alice" opens the "open-cloud-mesh" app
When "Alice" generates invitation token for the federation share
And "Alice" logs out
Given using "FEDERATED" server
And "Admin" creates following user using API
| id |
| Brian |
And "Brian" logs in
And "Brian" opens the "open-cloud-mesh" app
When "Brian" accepts federated share invitation by local user "Alice"
Then "Brian" should see the following federated connections:
| user | email |
| Alice Hansen | [email protected] |
And "Brian" logs out
34 changes: 34 additions & 0 deletions tests/e2e/cucumber/steps/ui/federation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Given, When, Then, DataTable } from '@cucumber/cucumber'
import { World } from '../../environment'
import { objects } from '../../../support'
import { expect } from '@playwright/test'
Given(
'{string} generates invitation token for the federation share',
async function (this: World, stepUser: any): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.scienceMesh.Federation({ page })
const user = this.usersEnvironment.getUser({ key: stepUser })
await pageObject.generateInvitation(user.id)
}
)

When(
'{string} accepts federated share invitation by local user {string}',
async function (this: World, stepUser: string, sharer: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.scienceMesh.Federation({ page })
await pageObject.acceptInvitation(sharer)
}
)

Then(
'{string} should see the following federated connections:',
async function (this: World, stepUser: any, stepTable: DataTable): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.scienceMesh.Federation({ page })
for (const info of stepTable.hashes()) {
const isConnectionExist = await pageObject.connectionExists(info)
await expect(isConnectionExist).toBeTruthy()
}
}
)
61 changes: 61 additions & 0 deletions tests/e2e/support/objects/federation/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect, Page } from '@playwright/test'
import util from 'util'
import { federatedInvitationCode } from '../../store'

const generateInvitationButton =
'//button[contains(@aria-label,"Generate invitation link that can be shared with one or more invitees")]'
const generateInvitationActionConfirmButton = '.oc-modal-body-actions-confirm'
const invitationToken = 'span:has-text("%s")'
const InvitationInput = '//input[starts-with(@id, "oc-textinput-")]'
const invitationConnectionRow =
'//div[@id="sciencemesh-connections"]//td[text()="%s"]/parent::tr/td[text()="%s"]'
const institutionOptionDropdown = '.vs__open-indicator'
const acceptInvitationButton = 'button:has(span:has-text("Accept invitation"))'

export const generateInvitation = async (args: { page: Page; user: string }): Promise<void> => {
const { page, user } = args
await page.locator(generateInvitationButton).click()
let inviteCode = ''
await Promise.all([
page.waitForResponse(async (resp) => {
if (
resp.url().endsWith('generate-invite') &&
resp.status() === 200 &&
resp.request().method() === 'POST'
) {
const responseBody = await resp.json()
inviteCode = responseBody.token
return true
}
return false
}),
page.locator(generateInvitationActionConfirmButton).click()
])
await expect(page.locator(util.format(invitationToken, inviteCode))).toBeVisible()
federatedInvitationCode.set(user, { code: inviteCode })
}

export const acceptInvitation = async (args: { page: Page; sharer: string }): Promise<void> => {
const { page, sharer } = args
const invitation = federatedInvitationCode.get(sharer.toLowerCase())
await page.locator(InvitationInput).fill(invitation.code)
await page.locator(institutionOptionDropdown).click()
await page.getByRole('option', { name: 'first-ocis-instance ocis-server:' }).click()
await Promise.all([
page.waitForResponse(
(resp) =>
resp.url().endsWith('accept-invite') &&
resp.status() === 200 &&
resp.request().method() === 'POST'
),
page.locator(acceptInvitationButton).click()
])
}

export const connectionExists = async (args: { page: Page; info }): Promise<boolean> => {
const { page, info } = args
await expect(
page.locator(util.format(invitationConnectionRow, info.user, info.email))
).toBeVisible()
return true
}
20 changes: 20 additions & 0 deletions tests/e2e/support/objects/federation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Page } from '@playwright/test'
import * as po from './actions'

export class Federation {
#page: Page

constructor({ page }: { page: Page }) {
this.#page = page
}
async generateInvitation(user: string): Promise<void> {
await po.generateInvitation({ page: this.#page, user })
}

async acceptInvitation(sharer: string): Promise<void> {
await po.acceptInvitation({ page: this.#page, sharer })
}
async connectionExists(info): Promise<boolean> {
return await po.connectionExists({ page: this.#page, info })
}
}
1 change: 1 addition & 0 deletions tests/e2e/support/objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * as runtime from './runtime'
export * as account from './account'
export * as urlNavigation from './url-navigation'
export * as appStore from './app-store'
export * as scienceMesh from './federation'
1 change: 1 addition & 0 deletions tests/e2e/support/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { dummyUserStore, createdUserStore, federatedUserStore } from './user'
export { dummyGroupStore, createdGroupStore } from './group'
export { userRoleStore } from './role'
export { keycloakRealmRoles, keycloakCreatedUser } from './keycloak'
export { federatedInvitationCode } from './invitation'
3 changes: 3 additions & 0 deletions tests/e2e/support/store/invitation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FederatedShareInvitation } from '../types'

export const federatedInvitationCode = new Map<string, FederatedShareInvitation>()
6 changes: 6 additions & 0 deletions tests/e2e/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ export interface AppRole {
displayName: string
id: string
}

export interface FederatedShareInvitation {
code: string
description?: string
email?: string
}