Skip to content

Commit

Permalink
feat(pages): add goToWorkspaces and getWorkspaceToDownload
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Dec 26, 2019
1 parent d7a5f6b commit a9e90ab
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pages/workspaces.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const { By, until } = require('selenium-webdriver');
const { getDownloadedWorkspaces } = require('../util');

const WORKSPACES_URL = `https://c9.io/${process.env.USERNAME}`;
const MIGRATE_URL_REGEX = new RegExp(`/${process.env.USERNAME}/(.+)/migrate$`);

const PREPARE_TO_DOWNLOAD_BUTTON_LOCATOR = By.xpath(
'//span[contains(text(), "Prepare to Download / Migrate")]',
);
const ARCHIVE_BUTTON_LOCATOR = By.xpath('//button[text()="Archive"]');
const DOWNLOAD_LINK_LOCATOR = By.xpath('//a[text()="Download / Migrate"]');

const MODAL_LOCATOR = By.css('.modal');
const ARCHIVE_BUTTON_LOCATOR = By.xpath('//button[text()="Archive"]');

class WorkspacesPage {
/**
Expand All @@ -14,14 +20,18 @@ class WorkspacesPage {
this.driver = driver;
}

async goToWorkspaces() {
await this.driver.get(WORKSPACES_URL);
}

async prepareToDownload() {
const { driver } = this;

const prepareToDownloadButtons = await driver.findElements(
PREPARE_TO_DOWNLOAD_BUTTON_LOCATOR,
);

for (let prepareToDownloadButton of prepareToDownloadButtons) {
for (const prepareToDownloadButton of prepareToDownloadButtons) {
await prepareToDownloadButton.click();
await driver.wait(until.elementLocated(MODAL_LOCATOR));
const archiveButton = await driver.wait(
Expand All @@ -34,6 +44,29 @@ class WorkspacesPage {
});
}
}

/**
* @return {string}
*/
async getWorkspaceToDownload() {
const { driver } = this;

const downloadLinks = await driver.findElements(DOWNLOAD_LINK_LOCATOR);

for (let downloadLink of downloadLinks) {
const href = await downloadLink.getAttribute('href');
const match = href.match(MIGRATE_URL_REGEX);

if (Array.isArray(match)) {
const downloadedWorkspaces = await getDownloadedWorkspaces();
const workspaceName = match[1];

if (!downloadedWorkspaces.includes(workspaceName)) {
return workspaceName;
}
}
}
}
}

module.exports = WorkspacesPage;

0 comments on commit a9e90ab

Please sign in to comment.