Skip to content
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
19 changes: 9 additions & 10 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and Run DataToolkit
run: |
docker compose -f docker-compose.yml build
docker compose -f docker-compose.yml up -d
sleep 5
docker compose exec web bash -c "
# import data configs from a manifest registry
./bin/rake \"crud:import:manifest_registry[https://gist.githubusercontent.com/mark-cooper/0492cc97d53a47105dd29ca86799c8c7/raw/f376621f1c2e110f88fc1bdd10c5437f0abc99a5/meta-manifest2.json]\"
"
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/setup --skip-server
- run: |
./bin/rails server -d
curl --retry 20 --retry-delay 10 --retry-all-errors http://127.0.0.1:3000
./bin/rake crud:import:manifest_registry[https://gist.githubusercontent.com/mark-cooper/0492cc97d53a47105dd29ca86799c8c7/raw/f376621f1c2e110f88fc1bdd10c5437f0abc99a5/meta-manifest2.json]

- uses: actions/setup-node@v6
with:
Expand All @@ -59,7 +58,7 @@ jobs:
- name: Run Playwright tests
working-directory: ./test/e2e
run: |
npx playwright test --trace on # tests/cspace-tests.spec.ts
npx playwright test --trace on tests/datatoolkit-tests.spec.ts

- uses: actions/upload-artifact@v6
if: ${{ failure() }}
Expand Down
35 changes: 21 additions & 14 deletions test/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"csv-parse": "^6.1.0",
"dotenv": "^17.2.2",
"playright": "^0.0.22",
"prettier": "3.0"
Expand Down
120 changes: 107 additions & 13 deletions test/e2e/tests/cspace-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,133 @@ export class CSpaceFixture {
.waitFor({ timeout: 60000 });
}

async goto(linkToClick: string, titleToValidate: string) {
async goto(
linkToClick: string,
titleToValidate: string,
local_page = this.page
) {
// Navigate to the Link page
await this.page.getByRole("link", { name: linkToClick }).click();
await this.page.getByText(titleToValidate).waitFor({ timeout: 15000 });
await local_page.getByRole("link", { name: linkToClick }).click();
await local_page.getByText(titleToValidate).waitFor({ timeout: 15000 });

await this.page.waitForLoadState();
await local_page.waitForLoadState();
}

async selectOption(optionTextToSearch: string) {
async selectOption(optionTextToSearch: string, local_page = this.page) {
// Locate the opetion of Collection Object
const option = await this.page
const option = await local_page
.locator(`option:has-text("${optionTextToSearch}")`)
.textContent();
// Select the Option
await this.page.selectOption(this.optionFieldId, option);
await local_page.selectOption(this.optionFieldId, option);
}

async uploadFile(file: string) {
async uploadFile(file: string, local_page = this.page) {
// Upload the CSV file
await this.page.locator(this.fileFieldId).setInputFiles(file);
await local_page.locator(this.fileFieldId).setInputFiles(file);
}

async fillFormAndSubmit(optionTextToSearch: string, file: string) {
await this.page.locator("#activity_label").fill(this.taskLabel);
async fillFormAndSubmit(
optionTextToSearch: string,
file: string,
local_page = this.page
) {
await local_page.locator("#activity_label").fill(this.taskLabel);
await this.selectOption(optionTextToSearch);
await this.uploadFile(file);
// Submit the form
await this.page
await local_page
.getByRole("button", { name: /submit/i })
.click({ force: true });

await this.page.waitForURL(/activities\/\d+$/, {
await local_page.waitForURL(/activities\/\d+$/, {
waitUntil: "networkidle",
});
}

async searchItem(
itemToSearch: string,
itemType: string = "All Records",
local_page = this.page
) {
// Search for the created task
const headerDiv = local_page.locator(".cspace-ui-BannerMain--common");

await headerDiv.getByRole("textbox").first().click();
await headerDiv.getByRole("option", { name: itemType }).click();

await headerDiv.getByPlaceholder("Search").fill(itemToSearch);
await headerDiv
.getByRole("button", { name: /search/i })
.click({ force: true });

await local_page.getByRole("row", { name: `${itemToSearch}` }).click();
}

async searchByIdAndTitle(
itemId: string,
itemTitle: string,
local_page = this.page
) {
// Search for the created task

await local_page.goto(
this.baseURL + "cspace/anthro/search/collectionobject"
);
await local_page
.locator(".cspace-ui-TitleBar--common")
.getByText("Search")
.waitFor();

await local_page
.locator("header")
.filter({ hasText: "of the following conditions" })
.getByRole("textbox")
.click();
await local_page.getByRole("option", { name: "All" }).click();
await local_page.getByRole("textbox").nth(5).click();
await local_page.getByRole("option", { name: "matches" }).click();
await local_page
.locator("div:nth-child(2) > .cspace-input-LineInput--embedded")
.first()
.click();
await local_page
.locator("div:nth-child(2) > .cspace-input-LineInput--embedded")
.first()
.fill(itemId);
await local_page
.locator(
"li:nth-child(7) > .cspace-ui-FieldConditionInput--normal > .cspace-input-DropdownMenuInput--common > .cspace-input-LineInput--normal"
)
.click();
await local_page.getByRole("option", { name: "matches" }).click();
await local_page
.locator(
"li:nth-child(7) > .cspace-ui-FieldConditionInput--normal > div:nth-child(3) > .cspace-input-RepeatingInput--normal > div > div > div:nth-child(2) > .cspace-input-LineInput--embedded"
)
.click();
await local_page
.locator(
"li:nth-child(7) > .cspace-ui-FieldConditionInput--normal > div:nth-child(3) > .cspace-input-RepeatingInput--normal > div > div > div:nth-child(2) > .cspace-input-LineInput--embedded"
)
.fill(itemTitle);
await local_page
.getByRole("contentinfo")
.filter({ hasText: "SearchClear" })
.locator('button[name="search"]')
.click();

await local_page.getByRole("row", { name: `${itemTitle}` }).click();
}

async fetchRelatedObjects(itemToSearch: string, local_page = this.page) {
const relatedObjects = await local_page.getByRole("button", {
name: "Related Objects:",
});
await relatedObjects.click();
return local_page
.locator(".cspace-ui-SearchResultTable--common")
.locator(".ReactVirtualized__Grid__innerScrollContainer")
.count();
}
}
20 changes: 19 additions & 1 deletion test/e2e/tests/cspace-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,28 @@ test.afterEach(async ({ page }, testInfo) => {
test("Check Cspace", async ({ checkCspace, page }, testInfo) => {
// checkCspace
await test.step(
"Check CSpace",
"CSpace Login",
async (step) => {
await checkCspace.doLogin();
},
{ box: true }
);
await test.step(
"CSpace Search",
async (step) => {
await checkCspace.searchItem("MR2022.1.7");
await checkCspace.searchByIdAndTitle("789", "XYZ");
},
{ box: true }
);

await test.step(
"Related Objects Fetch",
async (step) => {
expect(
await checkCspace.fetchRelatedObjects("MR2022.1.7")
).toBeGreaterThan(0);
},
{ box: true }
);
});
58 changes: 46 additions & 12 deletions test/e2e/tests/datatoolkit-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
import { test, expect } from "./datatoolkit-test";
import { parse as csv } from "csv-parse";
import fs from "fs";

// CSV file parsing example
type CSVRowData = {
objectNumber: string;
title: string;
};

const filePath: string = "data/test.csv";
const CSVRows: CSVRowData[] = [];

fs.createReadStream(filePath)
.pipe(csv({ columns: true })) // `columns: true` treats the first row as headers
.on("data", (row: CSVRowData) => {
// Process each row as it is parsed
CSVRows.push(row);
// console.log(row);
})
.on("end", () => {
// This event is fired when the entire file has been processed
// console.log('CSV file successfully processed.');
// console.log(results);
})
.on("error", (error) => {
console.error(error);
});

test.afterEach(async ({ page }, testInfo) => {
// Check if the test has failed
Expand Down Expand Up @@ -62,6 +89,25 @@ test("Check Create/Update Records", async ({
{ box: true }
);

// checkCspace - Temporarily commented out as it's not implemented on Data Toolkit
// await test.step(
// "Check CSpace Items Created",
// async (step) => {
// const newContext = await browser.newContext();
// const newPage = await newContext.newPage();
// await checkCspace.doLogin(newPage);

// CSVRows.forEach(async (row) => {
// console.log(row);
// await checkCspace.searchByIdAndTitle(row.objectNumber, row.title, newPage);
// });

// await newContext.close();

// },
// { box: true }
// );

await test.step(
"Create/Update Records - Failure",
async (step) => {
Expand Down Expand Up @@ -96,18 +142,6 @@ test("Check Create/Update Records", async ({
},
{ box: true }
);

// checkCspace
await test.step(
"Check CSpace",
async (step) => {
const newContext = await browser.newContext();
const newPage = await newContext.newPage();
await checkCspace.doLogin(newPage);
await newContext.close();
},
{ box: true }
);
});

test("Check Export Records Page", async ({
Expand Down
Loading