Skip to content
Open
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
115 changes: 84 additions & 31 deletions cypress/e2e/datasets/datasets-general.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,27 +495,21 @@ describe("Datasets general", () => {
});

cy.readFile("CI/e2e/frontend.config.e2e.json").then((baseConfig) => {
const relationsToTest = [
{ relation: "GREATER_THAN", rhs: 1 },
{ relation: "LESS_THAN", rhs: 3 },
{ relation: "EQUAL_TO_NUMERIC", rhs: 2 },
{ relation: "GREATER_THAN_OR_EQUAL", rhs: 2 },
{ relation: "LESS_THAN_OR_EQUAL", rhs: 2 },
{ relation: "RANGE", rhs: [1, 3] },
];
const testConfig = {
...baseConfig,
defaultDatasetsListSettings: {
...baseConfig.defaultDatasetsListSettings,
conditions: relationsToTest.map(({ relation, rhs }) => ({
condition: {
lhs: "extra_entry_end_time",
relation,
rhs,
unit: "",
conditions: [
{
condition: {
lhs: "extra_entry_end_time",
relation: "GREATER_THAN",
rhs: 1,
unit: "",
},
enabled: true,
},
enabled: true,
})),
],
},
};

Expand All @@ -536,20 +530,16 @@ describe("Datasets general", () => {
cy.get(".dataset-table mat-row").first().click();
cy.get(".metadataTable", { timeout: 10000 }).scrollIntoView();

cy.get(".metadataTable mat-row").within(() => {
cy.get(".mat-column-human_name label")
.invoke("text")
.then((fieldName) => {
if (fieldName && fieldName.trim() === "Extra Entry End Time") {
cy.get(".mat-column-value label")
.invoke("text")
.then((valueText) => {
const value = parseFloat(valueText.trim());
expect(value).to.be.greaterThan(1);
});
}
});
});
cy.get(".metadataTable mat-row .mat-column-value label")
.invoke("text")
.then((valueText) => {
const value = parseFloat(valueText.trim());
expect(value).to.be.greaterThan(1);
});

cy.visit("/datasets");
cy.get(".condition-panel").first().click();
cy.get('[data-cy="remove-condition-button"]').click();
});
});

Expand Down Expand Up @@ -651,7 +641,7 @@ describe("Datasets general", () => {

cy.visit("/datasets");

cy.wait("@getConfig", { timeout: 10000 });
cy.wait("@getConfig", { timeout: 20000 });

cy.finishedLoading();
});
Expand All @@ -670,4 +660,67 @@ describe("Datasets general", () => {
.should("be.visible");
});
});

describe("Conditions in multiple pages", () => {
beforeEach(() => {
cy.login(Cypress.env("username"), Cypress.env("password"));
});

it("should preverse dataset conditions when clearing sample conditions", () => {

cy.createDataset({
type: "raw",
scientificMetadata: {
extra_entry_end_time: { type: "number", value: 5, unit: "" },
},
});
const sampleId = Math.floor(100000 + Math.random() * 900000).toString();
cy.createSample({...testData.sample, sampleId});

cy.visit("/datasets");
cy.finishedLoading();

cy.get('[data-cy="add-condition-button"]').click();
cy.get('input[name="lhs"]').type("extra_entry_end_time");
cy.get("mat-dialog-container").find('button[type="submit"]').click();

cy.get(".condition-panel").should("have.length", 1);

cy.visit("/samples");
cy.finishedLoading();

cy.get('[data-cy="add-condition-button"]').click();
cy.get('input[name="lhs"]').type("test_characteristic");
cy.get("mat-dialog-container").find('button[type="submit"]').click();

cy.get(".condition-panel").should("have.length", 1);

cy.get(".condition-panel").first().click();
cy.get(".condition-panel")
.first()
.within(() => {
cy.get("input[matInput]").eq(0).clear().type("10");
});
cy.get('[data-cy="samples-filters-search-button"]').click();

// Clear conditions on samples page
cy.get('[data-cy="samples-filters-clear-button"]').click();

cy.get(".condition-panel").should("have.length", 0);

// Navigate back to datasets and verify condition is still there
cy.visit("/datasets");
cy.finishedLoading();

cy.get(".condition-panel").should("have.length", 1);
cy.get(".condition-panel").should("contain.text", "extra_entry_end_time");

cy.get(".condition-panel").first().click();
cy.get('[data-cy="remove-condition-button"]').click();
});
afterEach(() => {
cy.removeSamples();
})
});

});
15 changes: 15 additions & 0 deletions cypress/fixtures/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ export const testData = {
main_user: "ESS",
},
},
sample: {
ownerGroup: "ess",
accessGroups: ["string"],
instrumentGroup: "string",
sampleId: "string",
owner: "string",
description: "Cypress Sample",
type: "string",
proposalId: "cypress",
parentSampleId: "string",
sampleCharacteristics: {
test_characteristic: { type: "number", value: 10, unit: "" },
},
isPublished: false,
},
rawDataset: {
principalInvestigator: "string",
endTime: "2019-10-31T14:44:46.143Z",
Expand Down
22 changes: 22 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ Cypress.Commands.add("createInstrument", (instrument) => {
});
});

Cypress.Commands.add("createSample", (sample) => {
return cy.getCookie("user").then((userCookie) => {
const user = JSON.parse(decodeURIComponent(userCookie.value));

cy.getToken().then((token) => {
cy.log("Sample: " + JSON.stringify(sample, null, 2));
cy.log("User: " + JSON.stringify(user, null, 2));

cy.request({
method: "POST",
url: lbBaseUrl + "/Samples",
headers: {
Authorization: token,
Accept: "application/json",
"Content-Type": "application/json",
},
body: sample,
});
});
});
});

Cypress.Commands.add("updateProposal", (proposalId, updateProposalDto) => {
return cy.getCookie("user").then((userCookie) => {
const user = JSON.parse(decodeURIComponent(userCookie.value));
Expand Down
Loading
Loading