Skip to content

Commit

Permalink
Merge pull request #1013 from SciCatProject/SWAP-2931-fixing-issues-a…
Browse files Browse the repository at this point in the history
…fter-production-import

Improvements that will make e2e tests pass even if we have a lot of data in the database and use PATCH instead of PUT for datasets
  • Loading branch information
nitrosx authored Jan 2, 2023
2 parents bf34f22 + 2176999 commit dc465d6
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 43 deletions.
20 changes: 15 additions & 5 deletions cypress/integration/datasets-attachment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ describe("Datasets", () => {
it("should go to dataset details and add an attachment using the dropzone", () => {
cy.visit("/datasets");

cy.wait(1000);
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.get(".mat-row").contains("Cypress Dataset").click();
cy.finishedLoading();

cy.wait(1000);
cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.get(".mat-tab-link").contains("Attachments").click();
cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").first().click();

cy.wait(1000);
cy.isLoading();

cy.finishedLoading();

cy.get(".mat-tab-link").contains("Attachments").click();

cy.fixture("attachment-image").then((file) => {
cy.get(".dropzone").attachFile(
Expand Down
44 changes: 39 additions & 5 deletions cypress/integration/datasets-keyword.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("Datasets", () => {
beforeEach(() => {
cy.login(Cypress.config("username"), Cypress.config("password"));

cy.intercept("PUT", "/api/v3/Datasets/**/*").as("keyword");
cy.intercept("PATCH", "/api/v3/Datasets/**/*").as("keyword");
cy.intercept("GET", "*").as("fetch");
});

Expand All @@ -24,6 +24,18 @@ describe("Datasets", () => {

cy.visit("/datasets");

cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").click();

cy.wait("@fetch");
Expand All @@ -38,7 +50,7 @@ describe("Datasets", () => {
cy.get('[data-cy="save-general-information"]').click();

cy.wait("@keyword").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);
});

Expand All @@ -54,7 +66,17 @@ describe("Datasets", () => {

cy.visit("/datasets");

cy.wait(1000);
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").click();

Expand All @@ -67,7 +89,7 @@ describe("Datasets", () => {
cy.get('[data-cy="save-general-information"]').click();

cy.wait("@keyword").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);
});

Expand All @@ -77,6 +99,18 @@ describe("Datasets", () => {
it("should go to dataset details and remove the added keyword", () => {
cy.visit("/datasets");

cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").click();

cy.get('[data-cy="edit-general-information"]').click();
Expand All @@ -86,7 +120,7 @@ describe("Datasets", () => {
cy.get('[data-cy="save-general-information"]').click();

cy.wait("@keyword").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);
});

Expand Down
38 changes: 29 additions & 9 deletions cypress/integration/datasets-metadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Datasets", () => {
beforeEach(() => {
cy.login(Cypress.config("username"), Cypress.config("password"));

cy.intercept("PUT", "/api/v3/Datasets/**/*").as("metadata");
cy.intercept("PATCH", "/api/v3/Datasets/**/*").as("metadata");
cy.intercept("GET", "*").as("fetch");
});

Expand All @@ -25,11 +25,17 @@ describe("Datasets", () => {

cy.visit("/datasets");

cy.wait("@fetch");
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.wait(1000);
cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").first().click();

Expand All @@ -44,7 +50,7 @@ describe("Datasets", () => {
cy.get('[data-cy="add-new-row"]').click();

// simulate click event on the drop down
cy.get("mat-select[data-cy=field-type-input]").first().click(); // opens the drop down
cy.get("mat-select[data-cy=field-type-input]").last().click(); // opens the drop down

// simulate click event on the drop down item (mat-option)
cy.get(".mat-option-text")
Expand All @@ -53,13 +59,17 @@ describe("Datasets", () => {
option[0].click();
});

cy.get("[data-cy=metadata-name-input]").type(`${metadataName}{enter}`);
cy.get("[data-cy=metadata-value-input]").type(`${metadataValue}{enter}`);
cy.get("[data-cy=metadata-name-input]")
.last()
.type(`${metadataName}{enter}`);
cy.get("[data-cy=metadata-value-input]")
.last()
.type(`${metadataValue}{enter}`);

cy.get("button[data-cy=save-changes-button]").click();

cy.wait("@metadata").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);

cy.finishedLoading();
Expand All @@ -81,18 +91,28 @@ describe("Datasets", () => {
it("should go to dataset details and remove a metadata entry", () => {
cy.visit("/datasets");

cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").click();

cy.finishedLoading();
cy.get('[role="tab"]').contains("Edit").click();

cy.get("button.deleteButton").first().click();
cy.get("button.deleteButton").last().click();

cy.get("button[data-cy=save-changes-button]").click();
cy.wait("@metadata").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);

cy.finishedLoading();
Expand Down
18 changes: 13 additions & 5 deletions cypress/integration/datasets-public.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("Datasets", () => {

cy.createDataset("raw");

cy.intercept("PUT", "/api/v3/Datasets/**/*").as("change");
cy.intercept("PATCH", "/api/v3/Datasets/**/*").as("change");
cy.intercept("GET", "*").as("fetch");
});

Expand All @@ -22,11 +22,19 @@ describe("Datasets", () => {
it("should go to dataset details and toggle public", () => {
cy.visit("/datasets");

cy.wait("@fetch");
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.wait(1000);
cy.finishedLoading();

cy.contains(".mat-row", "Cypress Dataset").click();
cy.contains(".mat-row", "Cypress Dataset").first().click();

cy.wait("@fetch");

Expand All @@ -37,7 +45,7 @@ describe("Datasets", () => {
cy.get("@publicToggle").click();

cy.wait("@change").then(({ request, response }) => {
expect(request.method).to.eq("PUT");
expect(request.method).to.eq("PATCH");
expect(response.statusCode).to.eq(200);
});

Expand Down
12 changes: 11 additions & 1 deletion cypress/integration/datasets-publish.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ describe("Datasets", () => {

cy.visit("/datasets");

cy.wait(1000);
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get("[data-cy=checkboxInput]").first().click();

Expand Down
14 changes: 12 additions & 2 deletions cypress/integration/datasets-reduce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("Datasets", () => {
beforeEach(() => {
cy.login(Cypress.config("username"), Cypress.config("password"));

cy.intercept("PUT", "/api/v3/Datasets/**/*").as("metadata");
cy.intercept("PATCH", "/api/v3/Datasets/**/*").as("metadata");
cy.intercept("GET", "*").as("fetch");
});

Expand All @@ -22,7 +22,17 @@ describe("Datasets", () => {

cy.visit("/datasets");

cy.wait(1000);
cy.get(".dataset-table mat-table mat-header-row").should("exist");

cy.finishedLoading();

cy.get('input[type="search"][data-placeholder="Text Search"]')
.clear()
.type("Cypress");

cy.isLoading();

cy.finishedLoading();

cy.get(".mat-row").contains("Cypress Dataset").click();

Expand Down
22 changes: 12 additions & 10 deletions cypress/integration/samples-create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ describe("Samples", function () {

cy.wait("@fetch");

cy.get("mat-card")
.contains("Create Sample")
.click();
cy.get("mat-card").contains("Create Sample").click();

cy.get("mat-dialog-container").should("contain.text", "Sample Entry");

cy.get("#descriptionInput").type("Cypress Sample");
cy.get("#groupInput").type("ess");

cy.get("button")
.contains("Save")
.click();
cy.get("body").then((body) => {
if (body.find('[data-cy="groupSelect"]').length > 0) {
cy.get('[data-cy="groupSelect"]').click();
cy.get('[role="listbox"] mat-option').first().click();
} else {
cy.get("#groupInput").type("ess");
}
});

cy.get("button").contains("Save").click();

cy.wait("@create").then(({ request, response }) => {
expect(request.method).to.eq("POST");
expect(response.statusCode).to.eq(200);
});

cy.get(".mat-table")
.children()
.should("contain.text", "Cypress Sample");
cy.get(".mat-table").children().should("contain.text", "Cypress Sample");
});
});
});
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Cypress.Commands.add("finishedLoading", (type) => {
.should("not.exist");
});

Cypress.Commands.add("isLoading", (type) => {
cy.get('[data-cy="spinner"]').should("exist");
});

Cypress.Commands.add("createDataset", (type) => {
cy.getCookie("$LoopBackSDK$user").then((userCookie) => {
const user = JSON.parse(decodeURIComponent(userCookie.value));
Expand Down
2 changes: 1 addition & 1 deletion src/app/samples/sample-dialog/sample-dialog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 mat-dialog-title>Sample Entry</h1>
</mat-form-field>
<mat-form-field *ngIf="userGroups">
<mat-label>Owner Group</mat-label>
<mat-select formControlName="ownerGroup">
<mat-select formControlName="ownerGroup" data-cy="groupSelect">
<mat-option *ngFor="let group of userGroups" [value]="group">
{{ group }}
</mat-option>
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/sdk/services/custom/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ export class DatasetApi extends BaseLoopBackApi {
* </em>
*/
public patchAttributes(id: any, data: any = {}, customHeaders?: Function): Observable<any> {
let _method: string = "PUT";
let _method: string = "PATCH";
let _url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Datasets/:id";
let _routeParams: any = {
Expand Down
6 changes: 3 additions & 3 deletions src/app/state-management/effects/datasets.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("DatasetEffects", () => {
"metadataKeys",
"find",
"findOne",
"updateAttributes",
"patchAttributes",
"createAttachments",
"updateByIdAttachments",
"destroyByIdAttachments",
Expand Down Expand Up @@ -419,7 +419,7 @@ describe("DatasetEffects", () => {

actions = hot("-a", { a: action });
const response = cold("-a|", { a: dataset });
datasetApi.updateAttributes.and.returnValue(response);
datasetApi.patchAttributes.and.returnValue(response);

const expected = cold("--(bc)", { b: outcome1, c: outcome2 });
expect(effects.updateProperty$).toBeObservable(expected);
Expand All @@ -434,7 +434,7 @@ describe("DatasetEffects", () => {

actions = hot("-a", { a: action });
const response = cold("-#", {});
datasetApi.updateAttributes.and.returnValue(response);
datasetApi.patchAttributes.and.returnValue(response);

const expected = cold("--b", { b: outcome });
expect(effects.updateProperty$).toBeObservable(expected);
Expand Down
Loading

0 comments on commit dc465d6

Please sign in to comment.