|
| 1 | +import { Page } from '@playwright/test'; |
| 2 | +import { OpenProjectBasePage } from './OpenProjectBasePage'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Page object for a project's external file storages settings page. |
| 6 | + * Supports adding Nextcloud storage via the UI. |
| 7 | + */ |
| 8 | +export class OpenProjectProjectStoragesPage extends OpenProjectBasePage { |
| 9 | + constructor(page: Page) { |
| 10 | + super(page); |
| 11 | + } |
| 12 | + |
| 13 | + /** |
| 14 | + * Navigate to a project's external file storages page. |
| 15 | + */ |
| 16 | + async navigateToProjectStorages(projectIdentifier: string): Promise<void> { |
| 17 | + await this.navigateToProjectStoragesExternal(projectIdentifier); |
| 18 | + const escaped = projectIdentifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 19 | + const pattern = new RegExp( |
| 20 | + `.*/projects/${escaped}/settings/project_storages/external_file_storages.*` |
| 21 | + ); |
| 22 | + await this.page.waitForURL(pattern, { timeout: 15000 }); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Check if Nextcloud storage row is already present on the page. |
| 27 | + * Assumes we are on the project storages external page. |
| 28 | + */ |
| 29 | + async hasNextcloudStorage(): Promise<boolean> { |
| 30 | + const nextcloudStorageRow = this.getLocator('nextcloudStorageRow'); |
| 31 | + const count = await nextcloudStorageRow.count(); |
| 32 | + return count > 0; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Add Nextcloud storage to the current project via the UI. |
| 37 | + * Assumes we are on the project storages external page and storage is not yet linked. |
| 38 | + */ |
| 39 | + async addNextcloudStorage(): Promise<void> { |
| 40 | + const newStorageLink = this.getLocator('newStorageLink'); |
| 41 | + await newStorageLink.waitFor({ state: 'visible', timeout: 10000 }); |
| 42 | + await newStorageLink.click(); |
| 43 | + await this.page.waitForURL(/\/projects\/[^/]+\/settings\/project_storages\/new/, { |
| 44 | + timeout: 15000, |
| 45 | + }); |
| 46 | + |
| 47 | + const addFileStorageHeading = this.getLocator('addFileStorageHeading').first(); |
| 48 | + await addFileStorageHeading.waitFor({ state: 'visible', timeout: 10000 }); |
| 49 | + |
| 50 | + const storageDropdown = this.getLocator('storageDropdown'); |
| 51 | + await storageDropdown.waitFor({ state: 'visible', timeout: 10000 }); |
| 52 | + |
| 53 | + const selectedOption = storageDropdown.locator('option:checked'); |
| 54 | + const selectedText = (await selectedOption.textContent())?.toLowerCase() ?? ''; |
| 55 | + if (!selectedText.includes('nextcloud')) { |
| 56 | + const nextcloudOption = storageDropdown.locator('option', { hasText: /nextcloud/i }).first(); |
| 57 | + if ((await nextcloudOption.count()) === 0) { |
| 58 | + throw new Error('Nextcloud option is not available in the storage dropdown.'); |
| 59 | + } |
| 60 | + const nextcloudValue = await nextcloudOption.getAttribute('value'); |
| 61 | + if (!nextcloudValue) { |
| 62 | + throw new Error('Nextcloud option is missing a value attribute.'); |
| 63 | + } |
| 64 | + await storageDropdown.selectOption(nextcloudValue); |
| 65 | + } |
| 66 | + |
| 67 | + const continueButton = this.getLocator('continueButton'); |
| 68 | + await continueButton.waitFor({ state: 'visible', timeout: 10000 }); |
| 69 | + await continueButton.click(); |
| 70 | + |
| 71 | + const automaticFolderModeRadio = this.getLocator('automaticFolderModeRadio'); |
| 72 | + await automaticFolderModeRadio.waitFor({ state: 'visible', timeout: 10000 }); |
| 73 | + if (!(await automaticFolderModeRadio.isChecked())) { |
| 74 | + await automaticFolderModeRadio.check(); |
| 75 | + } |
| 76 | + |
| 77 | + const addButton = this.getLocator('addButton'); |
| 78 | + await addButton.waitFor({ state: 'visible', timeout: 10000 }); |
| 79 | + await addButton.click(); |
| 80 | + |
| 81 | + const successMessage = this.getLocator('storageCreationSuccessMessage'); |
| 82 | + await successMessage.waitFor({ state: 'visible', timeout: 15000 }); |
| 83 | + } |
| 84 | +} |
0 commit comments