Skip to content

Commit a864fe6

Browse files
authored
Merge branch 'master' into SWAP-4587-scicat-fe-add-testing-for-datafiles-actions
2 parents 70b890d + a995ede commit a864fe6

37 files changed

+1051
-1253
lines changed

cypress/e2e/datasets/datasets-datafiles.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("Dataset datafiles", () => {
4444

4545
cy.isLoading();
4646

47-
cy.contains("mat-row", "Cypress Dataset").first().click();
47+
cy.get("mat-row").contains("Cypress Dataset").first().click();
4848

4949
cy.wait("@fetch");
5050

@@ -101,7 +101,7 @@ describe("Dataset datafiles", () => {
101101

102102
cy.isLoading();
103103

104-
cy.contains("mat-row", "Cypress Dataset").first().click();
104+
cy.get("mat-row").contains("Cypress Dataset").first().click();
105105

106106
cy.wait("@fetch");
107107

cypress/e2e/datasets/datasets-publish.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("Datasets", () => {
2323

2424
cy.isLoading();
2525

26-
cy.get("[data-cy=checkboxInput]").first().click();
26+
cy.get(".dataset-table input[type='checkbox']").first().click();
2727

2828
cy.get("#addToBatchButton").click();
2929

cypress/e2e/datasets/datasets-share.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("Datasets", () => {
2323

2424
cy.isLoading();
2525

26-
cy.get("[data-cy=checkboxInput]").first().click();
26+
cy.get(".dataset-table input[type='checkbox']").first().click();
2727

2828
cy.get("#addToBatchButton").click();
2929

package-lock.json

Lines changed: 153 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/datasets/dashboard/dashboard.component.html

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<breadcrumb></breadcrumb>
2-
<full-text-search-bar
3-
#searchBar
4-
data-cy="text-search"
5-
[placeholder]="'Text Search'"
6-
>
7-
</full-text-search-bar>
2+
<full-text-search-bar
3+
#searchBar
4+
data-cy="text-search"
5+
[placeholder]="'Text Search'"
6+
>
7+
</full-text-search-bar>
88
<mat-sidenav-container [hasBackdrop]="false">
99
<mat-sidenav-content>
1010
<div fxLayout="row" fxLayout.xs="column">
@@ -36,22 +36,11 @@
3636
</ng-template>
3737

3838
<dataset-table
39-
[tableColumns]="tableColumns$ | async"
4039
[selectedSets]="selectedSets$ | async"
41-
(settingsClick)="onSettingsClick()"
4240
(rowClick)="onRowClick($event)"
4341
(pageChange)="onPageChange($event)"
4442
></dataset-table>
4543
</div>
4644
</div>
4745
</mat-sidenav-content>
48-
49-
<mat-sidenav #settings position="end" mode="push">
50-
<dataset-table-settings
51-
[selectableColumns]="selectableColumns$ | async"
52-
[clearSearchBar]="clearColumnSearch"
53-
(closeClick)="onCloseClick()"
54-
(selectColumn)="onSelectColumn($event)"
55-
></dataset-table-settings>
56-
</mat-sidenav>
5746
</mat-sidenav-container>

src/app/datasets/dashboard/dashboard.component.spec.ts

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@ import {
2020
addDatasetAction,
2121
changePageAction,
2222
} from "state-management/actions/datasets.actions";
23-
import {
24-
selectColumnAction,
25-
deselectColumnAction,
26-
} from "state-management/actions/user.actions";
2723
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
28-
import { SelectColumnEvent } from "datasets/dataset-table-settings/dataset-table-settings.component";
2924
import { provideMockStore } from "@ngrx/store/testing";
3025
import { selectSelectedDatasets } from "state-management/selectors/datasets.selectors";
31-
import { TableColumn } from "state-management/models";
3226
import {
3327
selectColumns,
3428
selectIsLoggedIn,
3529
} from "state-management/selectors/user.selectors";
3630
import { MatDialog, MatDialogModule } from "@angular/material/dialog";
37-
import { MatSidenav, MatSidenavModule } from "@angular/material/sidenav";
38-
import { MatCheckboxChange } from "@angular/material/checkbox";
31+
import { MatSidenavModule } from "@angular/material/sidenav";
3932
import { MatCardModule } from "@angular/material/card";
4033
import { MatIconModule } from "@angular/material/icon";
4134
import { AppConfigService } from "app-config.service";
@@ -129,91 +122,6 @@ describe("DashboardComponent", () => {
129122
expect(component).toBeTruthy();
130123
});
131124

132-
describe("#onSettingsClick()", () => {
133-
it("should toggle the sideNav", () => {
134-
const toggleSpy = spyOn(component.sideNav, "toggle");
135-
136-
component.onSettingsClick();
137-
138-
expect(toggleSpy).toHaveBeenCalled();
139-
});
140-
141-
it("should not clear the search column if sidenav is open", () => {
142-
component.sideNav.opened = false;
143-
// The opened status is toggled when onSettingsClick is called
144-
component.onSettingsClick();
145-
146-
expect(component.clearColumnSearch).toEqual(false);
147-
});
148-
149-
it("should clear the search column if sidenav is closed", () => {
150-
component.sideNav.opened = true;
151-
// The opened status is toggled when onSettingsClick is called
152-
component.onSettingsClick();
153-
154-
expect(component.clearColumnSearch).toEqual(true);
155-
});
156-
});
157-
158-
describe("#onCloseClick()", () => {
159-
it("should close the sideNav", () => {
160-
const closeSpy = spyOn(component.sideNav, "close");
161-
162-
component.onCloseClick();
163-
164-
expect(closeSpy).toHaveBeenCalled();
165-
});
166-
});
167-
168-
describe("#onSelectColumn()", () => {
169-
const column: TableColumn = {
170-
name: "test",
171-
order: 0,
172-
type: "standard",
173-
enabled: false,
174-
};
175-
176-
it("should dispatch a selectColumnAction if checkBoxChange.checked is true", () => {
177-
dispatchSpy = spyOn(store, "dispatch");
178-
179-
const checkBoxChange = {
180-
checked: true,
181-
} as MatCheckboxChange;
182-
183-
const event: SelectColumnEvent = {
184-
checkBoxChange,
185-
column,
186-
};
187-
188-
component.onSelectColumn(event);
189-
190-
expect(dispatchSpy).toHaveBeenCalledTimes(1);
191-
expect(dispatchSpy).toHaveBeenCalledWith(
192-
selectColumnAction({ name: column.name, columnType: column.type }),
193-
);
194-
});
195-
196-
it("should dispatch a deselectColumnAction if checkBoxChange.checked is false", () => {
197-
dispatchSpy = spyOn(store, "dispatch");
198-
199-
const checkBoxChange = {
200-
checked: false,
201-
} as MatCheckboxChange;
202-
203-
const event: SelectColumnEvent = {
204-
checkBoxChange,
205-
column,
206-
};
207-
208-
component.onSelectColumn(event);
209-
210-
expect(dispatchSpy).toHaveBeenCalledTimes(1);
211-
expect(dispatchSpy).toHaveBeenCalledWith(
212-
deselectColumnAction({ name: column.name, columnType: column.type }),
213-
);
214-
});
215-
});
216-
217125
describe("#onRowClick()", () => {
218126
it("should navigate to a dataset", () => {
219127
component.onRowClick(dataset);
@@ -296,32 +204,4 @@ describe("DashboardComponent", () => {
296204
);
297205
});
298206
});
299-
300-
describe("#tableColumn$ observable", () => {
301-
it("should show 'select' column when user is logged in", () => {
302-
const testColumn: TableColumn = {
303-
name: "test",
304-
order: 0,
305-
type: "standard",
306-
enabled: false,
307-
};
308-
const selectColumn: TableColumn = {
309-
name: "select",
310-
order: 1,
311-
type: "standard",
312-
enabled: true,
313-
};
314-
selectColumns.setResult([testColumn, selectColumn]);
315-
selectIsLoggedIn.setResult(true);
316-
317-
component.tableColumns$.subscribe((result) => {
318-
expect(result.length).toEqual(2);
319-
});
320-
321-
selectIsLoggedIn.setResult(false);
322-
component.tableColumns$.subscribe((result) =>
323-
expect(result).toEqual([testColumn]),
324-
);
325-
});
326-
});
327207
});

src/app/datasets/dashboard/dashboard.component.ts

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,19 @@ import { distinctUntilChanged, filter, map, take } from "rxjs/operators";
2828
import { MatDialog } from "@angular/material/dialog";
2929
import { MatSidenav } from "@angular/material/sidenav";
3030
import { AddDatasetDialogComponent } from "datasets/add-dataset-dialog/add-dataset-dialog.component";
31-
import { combineLatest, Subscription } from "rxjs";
31+
import { combineLatest, Subscription, lastValueFrom } from "rxjs";
3232
import {
3333
selectProfile,
3434
selectCurrentUser,
3535
selectColumns,
3636
selectIsLoggedIn,
37+
selectHasFetchedSettings,
3738
} from "state-management/selectors/user.selectors";
3839
import {
3940
OutputDatasetObsoleteDto,
4041
ReturnedUserDto,
4142
} from "@scicatproject/scicat-sdk-ts-angular";
42-
import {
43-
selectColumnAction,
44-
deselectColumnAction,
45-
loadDefaultSettings,
46-
} from "state-management/actions/user.actions";
47-
import { SelectColumnEvent } from "datasets/dataset-table-settings/dataset-table-settings.component";
43+
import { loadDefaultSettings } from "state-management/actions/user.actions";
4844
import { AppConfigService } from "app-config.service";
4945

5046
@Component({
@@ -61,15 +57,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
6157
loggedIn$ = this.store.select(selectIsLoggedIn);
6258
selectedSets$ = this.store.select(selectSelectedDatasets);
6359
selectColumns$ = this.store.select(selectColumns);
60+
selectHasFetchedSettings$ = this.store.select(selectHasFetchedSettings);
6461

65-
tableColumns$ = combineLatest([this.selectColumns$, this.loggedIn$]).pipe(
66-
map(([columns, loggedIn]) =>
67-
columns.filter((column) => loggedIn || column.name !== "select"),
68-
),
69-
);
70-
selectableColumns$ = this.selectColumns$.pipe(
71-
map((columns) => columns.filter((column) => column.name !== "select")),
72-
);
7362
public nonEmpty$ = this.store.select(selectIsBatchNonEmpty);
7463

7564
subscriptions: Subscription[] = [];
@@ -97,33 +86,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
9786
);
9887
}
9988

100-
onSettingsClick(): void {
101-
this.sideNav.toggle();
102-
if (this.sideNav.opened) {
103-
this.clearColumnSearch = false;
104-
} else {
105-
this.clearColumnSearch = true;
106-
}
107-
}
108-
109-
onCloseClick(): void {
110-
this.clearColumnSearch = true;
111-
this.sideNav.close();
112-
}
113-
114-
onSelectColumn(event: SelectColumnEvent): void {
115-
const { checkBoxChange, column } = event;
116-
if (checkBoxChange.checked) {
117-
this.store.dispatch(
118-
selectColumnAction({ name: column.name, columnType: column.type }),
119-
);
120-
} else if (!checkBoxChange.checked) {
121-
this.store.dispatch(
122-
deselectColumnAction({ name: column.name, columnType: column.type }),
123-
);
124-
}
125-
}
126-
12789
onRowClick(dataset: OutputDatasetObsoleteDto): void {
12890
const pid = encodeURIComponent(dataset.pid);
12991
this.router.navigateByUrl("/datasets/" + pid);
@@ -178,12 +140,29 @@ export class DashboardComponent implements OnInit, OnDestroy {
178140
this.store.dispatch(fetchMetadataKeysAction());
179141

180142
this.subscriptions.push(
181-
combineLatest([this.pagination$, this.readyToFetch$, this.loggedIn$])
143+
combineLatest([
144+
this.pagination$,
145+
this.readyToFetch$,
146+
this.loggedIn$,
147+
this.selectHasFetchedSettings$,
148+
])
182149
.pipe(
183-
map(([pagination, , loggedIn]) => [pagination, loggedIn]),
150+
map(([pagination, , loggedIn, hasFetchedSettings]) => [
151+
pagination,
152+
loggedIn,
153+
hasFetchedSettings,
154+
]),
184155
distinctUntilChanged(deepEqual),
185156
)
186-
.subscribe(([pagination, loggedIn]) => {
157+
.subscribe(async ([pagination, loggedIn]) => {
158+
const hasFetchedSettings = await lastValueFrom(
159+
this.selectHasFetchedSettings$.pipe(take(1)),
160+
);
161+
162+
if (!hasFetchedSettings) {
163+
return;
164+
}
165+
187166
this.store.dispatch(fetchDatasetsAction());
188167
this.store.dispatch(fetchFacetCountsAction());
189168
this.router.navigate(["/datasets"], {

src/app/datasets/dataset-table-settings/_dataset-table-settings-theme.scss

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/app/datasets/dataset-table-settings/dataset-table-settings.component.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/app/datasets/dataset-table-settings/dataset-table-settings.component.scss

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)