Skip to content
Open
28 changes: 19 additions & 9 deletions cypress/e2e/published-data/published-data.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand All @@ -192,7 +193,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand Down Expand Up @@ -221,7 +223,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand Down Expand Up @@ -298,7 +301,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand Down Expand Up @@ -349,7 +353,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand All @@ -374,7 +379,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand All @@ -398,7 +404,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand All @@ -417,7 +424,8 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]').clear().type(title);
cy.get('[data-cy="text-search"]').clear().type(title);
cy.get('[data-cy="search-button"]').click();

cy.isLoading();

Expand Down Expand Up @@ -534,10 +542,12 @@ describe("Datasets general", () => {

cy.finishedLoading();

cy.get('input[formcontrolname="globalSearch"]')
cy.get('[data-cy="text-search"]')
.clear()
.type(userPublishedDataTitle);

cy.get('[data-cy="search-button"]').click();

cy.isLoading();

cy.get("app-publisheddata-dashboard mat-table mat-row")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<shared-table
<dynamic-mat-table
[tableName]="tableName"
[columns]="columns"
[dataSource]="dataSource"
[columnsdef]="columns"
[pageSize]="5"
(rowClick)="onRowClick($event)"
(selectAll)="onSelectAll($event)"
(selectOne)="onSelectOne($event)"
(shareClick)="onShareClick()"
[select]="select"
[pagination]="pagination"
[pagingMode]="paginationMode"
[setting]="setting"
[pending]="pending"
[rowSelectionMode]="rowSelectionMode"
[showGlobalTextSearch]="true"
[globalTextSearch]="globalTextSearch"
[globalTextSearchPlaceholder]="'Title, Creator, DOI...'"
(onRowEvent)="onRowEvent($event)"
(settingChange)="onSettingChange($event)"
(paginationChange)="onPaginationChange($event)"
(globalTextSearchChange)="onGlobalTextSearchChange($event)"
(globalTextSearchApply)="onGlobalTextSearchAction()"
[emptyMessage]="'No published data available'"
[emptyIcon]="'folder'"
>
</shared-table>
</dynamic-mat-table>
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import { MockStore, createMock, mockPublishedData } from "shared/MockStubs";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { StoreModule, Store } from "@ngrx/store";
import { Router } from "@angular/router";
import { CheckboxEvent } from "shared/modules/table/table.component";
import { MatCheckboxChange } from "@angular/material/checkbox";
import { of } from "rxjs";
import { Message, MessageType } from "state-management/models";
import { showMessageAction } from "state-management/actions/user.actions";
import { FlexLayoutModule } from "@ngbracket/ngx-layout";
import { MatButtonModule } from "@angular/material/button";
import { MatIconModule } from "@angular/material/icon";
import { AppConfigService } from "app-config.service";
import { ScicatDataService } from "shared/services/scicat-data-service";
import { ExportExcelService } from "shared/services/export-excel.service";
import { PublishedData } from "@scicatproject/scicat-sdk-ts-angular";
import { RowEventType } from "shared/modules/dynamic-material-table/models/table-row.model";

const getConfig = () => ({});

Expand Down Expand Up @@ -83,118 +78,20 @@ describe("PublisheddataDashboardComponent", () => {
expect(component).toBeTruthy();
});

describe("#onShareClick()", () => {
it("should copy the selected DOI's to the users clipboard and dispatch a showMessageAction", () => {
const commandSpy = spyOn(document, "execCommand");
dispatchSpy = spyOn(store, "dispatch");

const message = new Message(
"The selected DOI's have been copied to your clipboard",
MessageType.Success,
5000,
);

component.onShareClick();

expect(commandSpy).toHaveBeenCalledTimes(1);
expect(commandSpy).toHaveBeenCalledWith("copy");
expect(dispatchSpy).toHaveBeenCalledTimes(1);
expect(dispatchSpy).toHaveBeenCalledWith(showMessageAction({ message }));
});
});

describe("#onRowClick", () => {
describe("#onRowEvent", () => {
it("should navigate to a Published Dataset", () => {
const published = mockPublishedData;
const id = encodeURIComponent(published.doi);
component.onRowClick(published);

component.onRowEvent({
event: RowEventType.RowClick,
sender: { row: published },
} as any);

expect(router.navigateByUrl).toHaveBeenCalledTimes(1);
expect(router.navigateByUrl).toHaveBeenCalledWith(
"/publishedDatasets/" + id,
);
});
});

describe("#onSelectAll()", () => {
it("should add all DOI's to selectedDOIs if checked is true", () => {
const published = createMock<PublishedData>({
doi: "test",
title: "test",
abstract: "test",
datasetPids: [],
createdAt: "",
registeredTime: "",
status: PublishedData.StatusEnum.private,
updatedAt: "",
metadata: {
creators: ["test creator"],
publisher: { name: "test" },
publicationYear: 2021,
resourceType: "test",
},
});

spyOn(component.vm$, "pipe").and.returnValue(
of({ publishedData: [published] }),
);

const event = {
event: {
checked: true,
},
selection: { selected: [published] },
};

component.onSelectAll(event as any);

expect(component.selectedDOIs.length).toEqual(1);
});

it("should remove all DOI's from selectedDOIs if checked is false", () => {
component.selectedDOIs.push(
component.doiBaseUrl + "test1",
component.doiBaseUrl + "test2",
);

const event = {
event: {
checked: false,
},
selection: [],
};

component.onSelectAll(event as any);

expect(component.selectedDOIs.length).toEqual(0);
});
});

describe("#onSelectOne()", () => {
it("should add the selected DOI to selectedDOIs if checked is true", () => {
const checkboxEvent: CheckboxEvent = {
event: { checked: true } as MatCheckboxChange,
row: { doi: "test" },
};

component.onSelectOne(checkboxEvent);

expect(component.selectedDOIs).toContain(
component.doiBaseUrl + checkboxEvent.row.doi,
);
});

it("should remove the deselected DOI from selectedDOIs if checked is false", () => {
const checkboxEvent: CheckboxEvent = {
event: { checked: false } as MatCheckboxChange,
row: { doi: "test" },
};

component.selectedDOIs.push(component.doiBaseUrl + checkboxEvent.row.doi);

component.onSelectOne(checkboxEvent);

expect(component.selectedDOIs.length).toEqual(0);
});
});
});
Loading
Loading