|
| 1 | +import { testConfig } from "../../fixtures/testData"; |
| 2 | +import { mergeConfig } from "../../support/utils"; |
| 3 | + |
| 4 | +describe("Datasets Detail View Dynamic", () => { |
| 5 | + const dynamicComponentConfig = testConfig.dynamicDetialViewComponent; |
| 6 | + const customizedLabelSets = |
| 7 | + dynamicComponentConfig.labelsLocalization.datasetCustom; |
| 8 | + const customizedComponents = |
| 9 | + dynamicComponentConfig.datasetDetailComponent.customization; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + cy.readFile("CI/e2e/frontend.config.e2e.json").then((baseConfig) => { |
| 13 | + const mergedConfig = mergeConfig(baseConfig, dynamicComponentConfig); |
| 14 | + cy.intercept("GET", "**/admin/config", mergedConfig).as( |
| 15 | + "getFrontendConfig", |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + cy.login(Cypress.env("username"), Cypress.env("password")); |
| 20 | + cy.createDataset("raw"); |
| 21 | + cy.visit("/datasets"); |
| 22 | + cy.wait("@getFrontendConfig"); |
| 23 | + }); |
| 24 | + |
| 25 | + after(() => { |
| 26 | + cy.removeDatasets(); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should load datasets with customized labels", () => { |
| 30 | + cy.get(".dataset-table mat-table mat-header-row").should("exist"); |
| 31 | + |
| 32 | + cy.finishedLoading(); |
| 33 | + |
| 34 | + cy.get('[data-cy="text-search"] input[type="search"]') |
| 35 | + .clear() |
| 36 | + .type("Cypress"); |
| 37 | + |
| 38 | + cy.isLoading(); |
| 39 | + |
| 40 | + cy.get("mat-row").contains("Cypress Dataset").click(); |
| 41 | + |
| 42 | + cy.isLoading(); |
| 43 | + cy.wrap(Object.values(customizedLabelSets)).each((value) => { |
| 44 | + cy.get("body") |
| 45 | + .find('[data-cy="section-label"], [data-cy="field-label"]') |
| 46 | + .should("contain", value); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should order sections based on customized settings", () => { |
| 51 | + cy.get(".dataset-table mat-table mat-header-row").should("exist"); |
| 52 | + |
| 53 | + cy.finishedLoading(); |
| 54 | + |
| 55 | + cy.get('[data-cy="text-search"] input[type="search"]') |
| 56 | + .clear() |
| 57 | + .type("Cypress"); |
| 58 | + |
| 59 | + cy.isLoading(); |
| 60 | + |
| 61 | + cy.get("mat-row").contains("Cypress Dataset").click(); |
| 62 | + |
| 63 | + cy.isLoading(); |
| 64 | + const sortedLabels = customizedComponents |
| 65 | + .sort((a, b) => a.order - b.order) |
| 66 | + .map((section) => section.label); |
| 67 | + |
| 68 | + cy.wrap(sortedLabels).each((label, index) => { |
| 69 | + cy.get('[data-cy="section-label"]') |
| 70 | + .eq(index) |
| 71 | + .should("contain", customizedLabelSets[label]); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + it("should order fields based on customized settings", () => { |
| 76 | + cy.get(".dataset-table mat-table mat-header-row").should("exist"); |
| 77 | + |
| 78 | + cy.finishedLoading(); |
| 79 | + |
| 80 | + cy.get('[data-cy="text-search"] input[type="search"]') |
| 81 | + .clear() |
| 82 | + .type("Cypress"); |
| 83 | + |
| 84 | + cy.isLoading(); |
| 85 | + |
| 86 | + cy.get("mat-row").contains("Cypress Dataset").click(); |
| 87 | + |
| 88 | + cy.isLoading(); |
| 89 | + const componentLabel = "Section Label Regular"; |
| 90 | + const sectionToTest = customizedComponents.find( |
| 91 | + (section) => section.label === componentLabel, |
| 92 | + ); |
| 93 | + cy.wrap(sectionToTest).should("not.be.undefined"); |
| 94 | + |
| 95 | + cy.wrap(sectionToTest.fields) |
| 96 | + .then((fields) => fields.sort((a, b) => a.order - b.order)) |
| 97 | + .each((field, index) => { |
| 98 | + cy.get('[data-cy="field-label"]') |
| 99 | + .eq(index) |
| 100 | + .should("contain", customizedLabelSets[field.source]); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + it("should render attachments section with customized settings", () => { |
| 105 | + cy.get(".dataset-table mat-table mat-header-row").should("exist"); |
| 106 | + |
| 107 | + cy.finishedLoading(); |
| 108 | + |
| 109 | + cy.get('[data-cy="text-search"] input[type="search"]') |
| 110 | + .clear() |
| 111 | + .type("Cypress"); |
| 112 | + |
| 113 | + cy.isLoading(); |
| 114 | + |
| 115 | + cy.get("mat-row").contains("Cypress Dataset").click(); |
| 116 | + |
| 117 | + cy.isLoading(); |
| 118 | + const componentLabel = "Section Label Attachments"; |
| 119 | + const sectionToTest = customizedComponents.find( |
| 120 | + (section) => section.label === componentLabel, |
| 121 | + ); |
| 122 | + const actualImageCount = 5; |
| 123 | + const expectedImageCount = sectionToTest.options.limit; |
| 124 | + const expectedSize = sectionToTest.options.size; |
| 125 | + |
| 126 | + cy.get(".mat-mdc-tab-link").contains("Attachments").click(); |
| 127 | + |
| 128 | + cy.uploadDatasetAttachments(actualImageCount); |
| 129 | + |
| 130 | + cy.isLoading(); |
| 131 | + |
| 132 | + cy.get(".mat-mdc-tab-link").contains("Details").click(); |
| 133 | + |
| 134 | + cy.get('[data-cy="section-label"]') |
| 135 | + .contains(customizedLabelSets["Section Label Attachments"]) |
| 136 | + .parent() |
| 137 | + .find("img") |
| 138 | + .should("have.length", expectedImageCount) |
| 139 | + .each(($img) => { |
| 140 | + cy.wrap($img).should("have.attr", "class").and("contain", expectedSize); |
| 141 | + }); |
| 142 | + }); |
| 143 | +}); |
0 commit comments