You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2022/10/06 11:33:15 UTC

[incubator-streampipes] 03/03: [STREAMPIPES-583] Add first cypress e2e test for the data download

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-583
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 4b46c17af36130cecbeba1442a61a7ac4907d2df
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Thu Oct 6 13:33:02 2022 +0200

    [STREAMPIPES-583] Add first cypress e2e test for the data download
---
 ui/cypress/fixtures/dataDownloadDialog/test1.csv   | 11 ++++
 ui/cypress/fixtures/dataDownloadDialog/test2.csv   | 11 ++++
 ui/cypress/support/general/InitStreamPipesTest.ts  | 17 -----
 .../support/utils/DataDownloadDialogUtils.ts       | 72 ++++++++++++++++++++++
 ui/cypress/support/utils/DataLakeUtils.ts          | 21 +------
 ui/cypress/support/utils/DataSetUtils.ts           | 40 ++++++++++++
 .../dataDownloadDialogTest.smoke.spec.ts           | 61 ++++++++++++++++++
 .../tests/datalake/testSpecialCharactersInName.ts  |  4 +-
 .../select-data-missing-values.component.html      |  9 ++-
 .../select-data-range.component.html               |  7 ++-
 .../select-format/select-format.component.html     | 20 ++++--
 .../data-download-dialog.component.html            |  6 +-
 .../services/data-export.service.ts                | 28 ++-------
 ...t.service.spec.ts => file-name.service.spec.ts} | 18 +++---
 .../services/file-name.service.ts                  | 52 ++++++++++++++++
 .../data-explorer-dashboard-widget.component.html  |  3 +-
 16 files changed, 297 insertions(+), 83 deletions(-)

diff --git a/ui/cypress/fixtures/dataDownloadDialog/test1.csv b/ui/cypress/fixtures/dataDownloadDialog/test1.csv
new file mode 100644
index 000000000..76f73b9ec
--- /dev/null
+++ b/ui/cypress/fixtures/dataDownloadDialog/test1.csv
@@ -0,0 +1,11 @@
+time;randombool;randomnumber;randomtext
+1653871499055;true;62.0;c
+1653871500059;false;46.0;a
+1653871501064;true;41.0;b
+1653871502070;true;41.0;b
+1653871503078;false;22.0;b
+1653871504082;true;56.0;a
+1653871505084;false;77.0;b
+1653871506086;true;77.0;a
+1653871507091;true;85.0;b
+1653871508093;false;22.0;a
diff --git a/ui/cypress/fixtures/dataDownloadDialog/test2.csv b/ui/cypress/fixtures/dataDownloadDialog/test2.csv
new file mode 100644
index 000000000..b37d591b3
--- /dev/null
+++ b/ui/cypress/fixtures/dataDownloadDialog/test2.csv
@@ -0,0 +1,11 @@
+time,randombool,randomnumber,randomtext
+1653871499055,true,62.0,c
+1653871500059,false,46.0,a
+1653871501064,true,41.0,b
+1653871502070,true,41.0,b
+1653871503078,false,22.0,b
+1653871504082,true,56.0,a
+1653871505084,false,77.0,b
+1653871506086,true,77.0,a
+1653871507091,true,85.0,b
+1653871508093,false,22.0,a
diff --git a/ui/cypress/support/general/InitStreamPipesTest.ts b/ui/cypress/support/general/InitStreamPipesTest.ts
index 5b7ccf4e5..37fe4cc17 100644
--- a/ui/cypress/support/general/InitStreamPipesTest.ts
+++ b/ui/cypress/support/general/InitStreamPipesTest.ts
@@ -15,23 +15,6 @@
  * limitations under the License.
  *
  */
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
 
 declare global {
   namespace Cypress {
diff --git a/ui/cypress/support/utils/DataDownloadDialogUtils.ts b/ui/cypress/support/utils/DataDownloadDialogUtils.ts
new file mode 100644
index 000000000..e171121ae
--- /dev/null
+++ b/ui/cypress/support/utils/DataDownloadDialogUtils.ts
@@ -0,0 +1,72 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import { ExportConfig } from '../../../src/app/core-ui/data-download-dialog/model/export-config.model';
+import { DataLakeUtils } from './DataLakeUtils';
+import { FileNameService } from '../../../src/app/core-ui/data-download-dialog/services/file-name.service';
+import { CsvFormatExportConfig } from '../../../src/app/core-ui/data-download-dialog/model/format-export-config.model';
+
+export class DataDownloadDialogUtils {
+  public static testDownload(exportConfig: ExportConfig,
+                             resultFileLocation: string,
+                             dataViewName: string) {
+    // const exportDate: Date;
+    DataLakeUtils.goToDatalake();
+
+    // select data view in edit mode
+    DataLakeUtils.editDataView(dataViewName);
+
+    // select download button
+    const widgetName = 'download-datalake_configuration-table';
+    cy.dataCy(widgetName)
+      .click();
+
+    // download-customInterval, download-all, download-visible
+    cy.dataCy(`download-configuration-${exportConfig.dataExportConfig.dataRangeConfiguration}`)
+      .click();
+
+    // download-ignore, download-default, download-emtpy
+    // cy.dataCy(`download-configuration-${exportConfig.dataExportConfig.missingBehaviour}`)
+    //     .click();
+
+    // click next
+    cy.dataCy('download-configuration-next-btn').click();
+
+    // Format
+    // cy.dataCy('download-configuration-json').click();
+    cy.dataCy(`download-configuration-${exportConfig.formatExportConfig.exportFormat}`).click();
+    if ('delimiter' in exportConfig.formatExportConfig) {
+      // if ((exportConfig.formatExportConfig as CsvFormatExportConfig).delimiter !== undefined) {
+      cy.dataCy(`download-configuration-delimiter-${(exportConfig.formatExportConfig as CsvFormatExportConfig).delimiter}`).click();
+    }
+
+    // click next
+    cy.dataCy('download-configuration-download-btn').click();
+
+    const fileNameService: FileNameService = new FileNameService();
+    const fileName = fileNameService.generateName(exportConfig, new Date());
+    const downloadsFolder = Cypress.config('downloadsFolder');
+    cy.readFile(downloadsFolder + '/' + fileName).then((downloadFileString) => {
+      cy.readFile(`cypress/fixtures/dataDownloadDialog/${resultFileLocation}`).then((expectedResultString) => {
+        expect(downloadFileString === expectedResultString);
+      });
+    });
+  }
+}
+
+
diff --git a/ui/cypress/support/utils/DataLakeUtils.ts b/ui/cypress/support/utils/DataLakeUtils.ts
index 9596f3891..b976c81ce 100644
--- a/ui/cypress/support/utils/DataLakeUtils.ts
+++ b/ui/cypress/support/utils/DataLakeUtils.ts
@@ -16,13 +16,12 @@
  *
  */
 
-// tslint:disable-next-line:no-implicit-dependencies
-import * as CSV from 'csv-string';
 import { FileManagementUtils } from './FileManagementUtils';
 import { GenericAdapterBuilder } from '../builder/GenericAdapterBuilder';
 import { ConnectUtils } from './ConnectUtils';
 import { DataLakeFilterConfig } from '../model/DataLakeFilterConfig';
 import { DataExplorerWidget } from '../model/DataExplorerWidget';
+import { DataSetUtils } from './DataSetUtils';
 
 export class DataLakeUtils {
 
@@ -263,7 +262,7 @@ export class DataLakeUtils {
     }).should((response) => {
       const actualResultString = response.body;
       cy.readFile(fileRoute).then((expectedResultString) => {
-        DataLakeUtils.resultEqual(actualResultString, expectedResultString, ignoreTime);
+        DataSetUtils.csvEqual(actualResultString, expectedResultString, ignoreTime);
       });
     });
   }
@@ -285,20 +284,4 @@ export class DataLakeUtils {
         .type(`${value.toLocaleString()}{enter}`);
   }
 
-  private static resultEqual(actual: string, expected: string, ignoreTime: boolean) {
-    let actualResult;
-    if (ignoreTime) {
-      actualResult = DataLakeUtils.parseCsv(actual).map(row => {
-        return row.splice(1);
-      });
-    } else {
-      actualResult = DataLakeUtils.parseCsv(actual);
-    }
-    const expectedResult = DataLakeUtils.parseCsv(expected);
-    expect(actualResult).to.deep.equal(expectedResult);
-  }
-
-  private static parseCsv(csv: string) {
-    return CSV.parse(csv, ';');
-  }
 }
diff --git a/ui/cypress/support/utils/DataSetUtils.ts b/ui/cypress/support/utils/DataSetUtils.ts
new file mode 100644
index 000000000..d45711215
--- /dev/null
+++ b/ui/cypress/support/utils/DataSetUtils.ts
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import * as CSV from 'csv-string';
+
+export class DataSetUtils {
+  public static csvEqual(actualCsv: string, expectedCsv: string, ignoreTime: boolean) {
+    let actualResult;
+    if (ignoreTime) {
+      actualResult = DataSetUtils.parseCsv(actualCsv).map(row => {
+        return row.splice(1);
+      });
+    } else {
+      actualResult = DataSetUtils.parseCsv(actualCsv);
+    }
+    const expectedResult = DataSetUtils.parseCsv(expectedCsv);
+    expect(actualResult).to.deep.equal(expectedResult);
+  }
+
+
+  private static parseCsv(csv: string) {
+    return CSV.parse(csv, ';');
+  }
+
+}
diff --git a/ui/cypress/tests/dataDownloadDialog/dataDownloadDialogTest.smoke.spec.ts b/ui/cypress/tests/dataDownloadDialog/dataDownloadDialogTest.smoke.spec.ts
new file mode 100644
index 000000000..4e94c3fd4
--- /dev/null
+++ b/ui/cypress/tests/dataDownloadDialog/dataDownloadDialogTest.smoke.spec.ts
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { ExportConfig } from '../../../src/app/core-ui/data-download-dialog/model/export-config.model';
+import { DataDownloadDialogUtils } from '../../support/utils/DataDownloadDialogUtils';
+import { CsvFormatExportConfig } from '../../../src/app/core-ui/data-download-dialog/model/format-export-config.model';
+import { DataLakeUtils } from '../../support/utils/DataLakeUtils';
+
+
+describe('Test live data download dialog', () => {
+  before('Setup Test', () => {
+    cy.initStreamPipesTest();
+    DataLakeUtils.loadDataIntoDataLake('datalake/sample.csv');
+    DataLakeUtils.addDataViewAndTableWidget(dataViewName, 'Persist');
+    DataLakeUtils.saveDataExplorerWidgetConfiguration();
+  });
+
+  beforeEach('Setup Test', () => {
+    cy.login();
+  });
+
+  const dataViewName = 'TestView';
+
+  const exportConfig: ExportConfig = {
+    dataExportConfig: {
+      dataRangeConfiguration: 'all',
+      missingValueBehaviour: 'ignore',
+      measurement: 'datalake_configuration'
+    },
+    formatExportConfig: {
+      exportFormat: 'csv',
+      delimiter: 'semicolon'
+    }
+  };
+
+  it('Data Explorer CSV with Semicolon', () => {
+    const resultFile = 'test1.csv';
+    DataDownloadDialogUtils.testDownload(exportConfig, resultFile, dataViewName);
+  });
+
+  it('Data Explorer CSV with Semicolon', () => {
+    (exportConfig.formatExportConfig as CsvFormatExportConfig).delimiter = 'comma';
+    const resultFile = 'test2.csv';
+    DataDownloadDialogUtils.testDownload(exportConfig, resultFile, dataViewName);
+  });
+});
diff --git a/ui/cypress/tests/datalake/testSpecialCharactersInName.ts b/ui/cypress/tests/datalake/testSpecialCharactersInName.ts
index e3965350c..a0bf4afe1 100644
--- a/ui/cypress/tests/datalake/testSpecialCharactersInName.ts
+++ b/ui/cypress/tests/datalake/testSpecialCharactersInName.ts
@@ -60,7 +60,7 @@ describe('Test Table View in Data Explorer', () => {
 
     DataLakeUtils.goToDatalake();
 
-    DataLakeUtils.createAndEditDataView();
+    DataLakeUtils.createAndEditDataView('widgetName');
 
     DataLakeUtils.addNewWidget();
 
@@ -78,7 +78,7 @@ describe('Test Table View in Data Explorer', () => {
       new Date(2020, 10, 20, 22, 44),
       new Date(2021, 10, 20, 22, 44));
 
-    cy.dataCy('data-explorer-table-row', { timeout: 10000 }).should('have.length', 10);
+    cy.dataCy('data-explorer-table-row', {timeout: 10000}).should('have.length', 10);
 
   });
 
diff --git a/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-missing-values/select-data-missing-values.component.html b/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-missing-values/select-data-missing-values.component.html
index 0667b5a20..a4bc416f1 100644
--- a/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-missing-values/select-data-missing-values.component.html
+++ b/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-missing-values/select-data-missing-values.component.html
@@ -22,17 +22,20 @@
     [(ngModel)]="dataExportConfig.missingValueBehaviour">
   <mat-radio-button
       value="ignore"
-      class="sp-radio-button">
+      class="sp-radio-button"
+      data-cy="download-configuration-ignore">
     Ignore lines with missing value
   </mat-radio-button>
   <mat-radio-button
       value="default"
-      class="sp-radio-button">
+      class="sp-radio-button"
+      data-cy="download-configuration-default">
     Add default value
   </mat-radio-button>
   <mat-radio-button
       value="empty"
-      class="sp-radio-button">
+      class="sp-radio-button"
+      data-cy="download-configuration-empty">
     Leave entry empty
   </mat-radio-button>
 </mat-radio-group>
diff --git a/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-range/select-data-range.component.html b/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-range/select-data-range.component.html
index efcf22ea1..e32a73e67 100644
--- a/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-range/select-data-range.component.html
+++ b/ui/src/app/core-ui/data-download-dialog/components/select-data/select-data-range/select-data-range.component.html
@@ -23,6 +23,7 @@
   <mat-radio-button
       value="visible"
       class="sp-radio-button"
+      data-cy="download-configuration-visible"
       *ngIf="dataExplorerDataConfig">
     Currently configured query
   </mat-radio-button>
@@ -46,12 +47,14 @@
   <!--  </div>-->
   <mat-radio-button
       value="all"
-      class="sp-radio-button">
+      class="sp-radio-button"
+      data-cy="download-configuration-all">
     All data in database
   </mat-radio-button>
   <mat-radio-button
       value="customInterval"
-      class="sp-radio-button">
+      class="sp-radio-button"
+      data-cy="download-configuration-customInterval">
     All data in custom time interval
   </mat-radio-button>
 
diff --git a/ui/src/app/core-ui/data-download-dialog/components/select-format/select-format.component.html b/ui/src/app/core-ui/data-download-dialog/components/select-format/select-format.component.html
index dfe354587..2cadb66be 100644
--- a/ui/src/app/core-ui/data-download-dialog/components/select-format/select-format.component.html
+++ b/ui/src/app/core-ui/data-download-dialog/components/select-format/select-format.component.html
@@ -20,10 +20,16 @@
 <div>
   <h5>Download Format</h5>
   <mat-radio-group class="sp-radio-group" [(ngModel)]="formatExportConfig.exportFormat">
-    <mat-radio-button value="json" class="sp-radio-button">
+    <mat-radio-button
+        value="json"
+        class="sp-radio-button"
+        data-cy="download-configuration-json">
       JSON
     </mat-radio-button>
-    <mat-radio-button value="csv" class="sp-radio-button">
+    <mat-radio-button
+        value="csv"
+        class="sp-radio-button"
+        data-cy="download-configuration-csv">
       CSV
     </mat-radio-button>
   </mat-radio-group>
@@ -31,7 +37,13 @@
 <div *ngIf="formatExportConfig.exportFormat === 'csv'" class="mt-10">
   <h5>Delimiter</h5>
   <mat-radio-group [(ngModel)]="formatExportConfig.delimiter" class="sp-radio-group">
-    <mat-radio-button value="comma" class="sp-radio-button">&nbsp;,</mat-radio-button>
-    <mat-radio-button value="semicolon" class="sp-radio-button">&nbsp;;</mat-radio-button>
+    <mat-radio-button
+        value="comma"
+        class="sp-radio-button"
+        data-cy="download-configuration-delimiter-comma">&nbsp;,</mat-radio-button>
+    <mat-radio-button
+        value="semicolon"
+        class="sp-radio-button"
+        data-cy="download-configuration-delimiter-semicolon">&nbsp;;</mat-radio-button>
   </mat-radio-group>
 </div>
diff --git a/ui/src/app/core-ui/data-download-dialog/data-download-dialog.component.html b/ui/src/app/core-ui/data-download-dialog/data-download-dialog.component.html
index 8adb6f961..c587c1996 100644
--- a/ui/src/app/core-ui/data-download-dialog/data-download-dialog.component.html
+++ b/ui/src/app/core-ui/data-download-dialog/data-download-dialog.component.html
@@ -59,14 +59,16 @@
         mat-button
         mat-raised-button
         *ngIf="downloadDialogStepper.selectedIndex < 1" color="accent"
-        (click)="nextStep()">
+        (click)="nextStep()"
+        data-cy="download-configuration-next-btn">
       Next
     </button>
     <button
         mat-button
         mat-raised-button
         *ngIf="downloadDialogStepper.selectedIndex == 1" color="accent"
-        (click)="downloadData()">
+        (click)="downloadData()"
+        data-cy="download-configuration-download-btn">
       Download
     </button>
   </div>
diff --git a/ui/src/app/core-ui/data-download-dialog/services/data-export.service.ts b/ui/src/app/core-ui/data-download-dialog/services/data-export.service.ts
index d6ecddebe..5cc05b600 100644
--- a/ui/src/app/core-ui/data-download-dialog/services/data-export.service.ts
+++ b/ui/src/app/core-ui/data-download-dialog/services/data-export.service.ts
@@ -22,6 +22,7 @@ import { DatalakeQueryParameters, DatalakeRestService, DataViewQueryGeneratorSer
 import { HttpEventType } from '@angular/common/http';
 import { DataDownloadDialogModel } from '../model/data-download-dialog.model';
 import { DownloadProgress } from '../model/download-progress.model';
+import { FileNameService } from './file-name.service';
 
 @Injectable({
   providedIn: 'root'
@@ -31,7 +32,8 @@ export class DataExportService {
   public updateDownloadProgress: EventEmitter<DownloadProgress> = new EventEmitter();
 
   constructor(public dataLakeRestService: DatalakeRestService,
-              public dataViewQueryGeneratorService: DataViewQueryGeneratorService) {
+              public dataViewQueryGeneratorService: DataViewQueryGeneratorService,
+              public fileNameService: FileNameService) {
   }
 
   public downloadData(exportConfig: ExportConfig,
@@ -102,7 +104,7 @@ export class DataExportService {
     document.body.appendChild(a);
     a.style.display = 'display: none';
 
-    const name = this.getFileName(exportConfig, new Date());
+    const name = this.fileNameService.generateName(exportConfig, new Date());
 
     const url = window.URL.createObjectURL(new Blob([String(data)], {type: `data:text/${exportConfig.formatExportConfig.exportFormat};charset=utf-8`}));
     a.href = url;
@@ -111,27 +113,5 @@ export class DataExportService {
     window.URL.revokeObjectURL(url);
   }
 
-  public getFileName(exportConfig: ExportConfig, exportDate: Date): string {
-    const baseName = `${this.getDateString(exportDate)}_${exportConfig.dataExportConfig.measurement}_`;
-    const dataRangeOption = exportConfig.dataExportConfig.dataRangeConfiguration;
-    let dateRange = '';
-    const fileExtension = `.${exportConfig.formatExportConfig.exportFormat}`;
-
-    if (exportConfig.dataExportConfig.dateRange !== undefined && (dataRangeOption === 'customInterval' || dataRangeOption === 'visible')) {
-      if (exportConfig.dataExportConfig.dateRange.startDate) {
-        dateRange += `_${this.getDateString(exportConfig.dataExportConfig.dateRange.startDate)}`;
-      }
-
-      if (exportConfig.dataExportConfig.dateRange.endDate) {
-        dateRange += `_${this.getDateString(exportConfig.dataExportConfig.dateRange.endDate)}`;
-      }
-    }
-
-    return baseName + dataRangeOption + dateRange + fileExtension;
-  }
-
-  public getDateString(date: Date): string {
-    return date.toISOString().split('T')[0];
-  }
 
 }
diff --git a/ui/src/app/core-ui/data-download-dialog/services/data-export.service.spec.ts b/ui/src/app/core-ui/data-download-dialog/services/file-name.service.spec.ts
similarity index 83%
rename from ui/src/app/core-ui/data-download-dialog/services/data-export.service.spec.ts
rename to ui/src/app/core-ui/data-download-dialog/services/file-name.service.spec.ts
index f99c5d1c8..aa64fae7a 100644
--- a/ui/src/app/core-ui/data-download-dialog/services/data-export.service.spec.ts
+++ b/ui/src/app/core-ui/data-download-dialog/services/file-name.service.spec.ts
@@ -16,13 +16,13 @@
  *
  */
 
-import { DataExportService } from './data-export.service';
 import { ExportConfig } from '../model/export-config.model';
 import { DateRange } from '@streampipes/platform-services';
+import { FileNameService } from './file-name.service';
 
-describe('DataExportService', () => {
+describe('FileNameService', () => {
 
-  const service = new DataExportService(undefined, undefined);
+  const service = new FileNameService();
 
   // Testing data
   const defaultExportDate = new Date(2022, 11, 11, 3);
@@ -48,13 +48,13 @@ describe('DataExportService', () => {
   });
 
   it('Name for all data csv', () => {
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}all.csv`);
   });
 
   it('Name for all data json', () => {
     defaultExportConfig.formatExportConfig.exportFormat = 'json';
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}all.json`);
   });
 
@@ -62,7 +62,7 @@ describe('DataExportService', () => {
     defaultExportConfig.dataExportConfig.dataRangeConfiguration = 'customInterval';
     defaultExportConfig.dataExportConfig.dateRange = defaultDateRange;
 
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}customInterval_2022-12-02_2022-12-06.csv`);
   });
 
@@ -71,7 +71,7 @@ describe('DataExportService', () => {
     defaultExportConfig.dataExportConfig.dataRangeConfiguration = 'visible';
     defaultExportConfig.dataExportConfig.dateRange = defaultDateRange;
 
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}visible_2022-12-02_2022-12-06.json`);
   });
 
@@ -80,7 +80,7 @@ describe('DataExportService', () => {
     defaultExportConfig.dataExportConfig.dateRange = new DateRange();
     defaultExportConfig.dataExportConfig.dateRange.endDate = defaultEndDate;
 
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}visible_2022-12-06.csv`);
   });
 
@@ -89,7 +89,7 @@ describe('DataExportService', () => {
     defaultExportConfig.dataExportConfig.dateRange = new DateRange();
     defaultExportConfig.dataExportConfig.dateRange.startDate = defaultStartDate;
 
-    const result = service.getFileName(defaultExportConfig, defaultExportDate);
+    const result = service.generateName(defaultExportConfig, defaultExportDate);
     expect(result).toBe(`${expectedBaseName}visible_2022-12-02.csv`);
   });
 
diff --git a/ui/src/app/core-ui/data-download-dialog/services/file-name.service.ts b/ui/src/app/core-ui/data-download-dialog/services/file-name.service.ts
new file mode 100644
index 000000000..f8c91cb70
--- /dev/null
+++ b/ui/src/app/core-ui/data-download-dialog/services/file-name.service.ts
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import { Injectable } from '@angular/core';
+import { ExportConfig } from '../model/export-config.model';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class FileNameService {
+
+    public generateName(exportConfig: ExportConfig, exportDate: Date): string {
+    const baseName = `${this.getDateString(exportDate)}_${exportConfig.dataExportConfig.measurement}_`;
+    const dataRangeOption = exportConfig.dataExportConfig.dataRangeConfiguration;
+    let dateRange = '';
+    const fileExtension = `.${exportConfig.formatExportConfig.exportFormat}`;
+
+    if (exportConfig.dataExportConfig.dateRange !== undefined && (dataRangeOption === 'customInterval' || dataRangeOption === 'visible')) {
+      if (exportConfig.dataExportConfig.dateRange.startDate) {
+        dateRange += `_${this.getDateString(exportConfig.dataExportConfig.dateRange.startDate)}`;
+      }
+
+      if (exportConfig.dataExportConfig.dateRange.endDate) {
+        dateRange += `_${this.getDateString(exportConfig.dataExportConfig.dateRange.endDate)}`;
+      }
+    }
+
+    return baseName + dataRangeOption + dateRange + fileExtension;
+  }
+
+  public getDateString(date: Date): string {
+    return date.toISOString().split('T')[0];
+  }
+
+}
+
+
diff --git a/ui/src/app/data-explorer/components/widget/data-explorer-dashboard-widget.component.html b/ui/src/app/data-explorer/components/widget/data-explorer-dashboard-widget.component.html
index 8c4b4b548..6238ec6d2 100644
--- a/ui/src/app/data-explorer/components/widget/data-explorer-dashboard-widget.component.html
+++ b/ui/src/app/data-explorer/components/widget/data-explorer-dashboard-widget.component.html
@@ -61,7 +61,8 @@
         <button mat-button
                 mat-icon-button
                 *ngIf="editMode"
-                (click)="downloadDataAsFile()">
+                (click)="downloadDataAsFile()"
+                [attr.data-cy]="'download-' + configuredWidget.baseAppearanceConfig.widgetTitle.replaceAll(' ', '')">
           <mat-icon>get_app</mat-icon>
         </button>
         <button mat-button