-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added page to admin dashboard to view all uploads
fixes: #2051
- Loading branch information
1 parent
fe80ba4
commit 56dd61b
Showing
11 changed files
with
289 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/app/components/admin/all-uploads/all-uploads.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { assertPageInfo } from "@test/helpers/pageRoute"; | ||
import { Spectator, SpyObject, createRoutingFactory } from "@ngneat/spectator"; | ||
import { MockBawApiModule } from "@baw-api/baw-apiMock.module"; | ||
import { SharedModule } from "@shared/shared.module"; | ||
import { ToastrService } from "ngx-toastr"; | ||
import { ConfirmationComponent } from "@components/harvest/components/modal/confirmation.component"; | ||
import { LoadingComponent } from "@shared/loading/loading.component"; | ||
import { UserLinkComponent } from "@shared/user-link/user-link/user-link.component"; | ||
import { Injector } from "@angular/core"; | ||
import { SHALLOW_HARVEST } from "@baw-api/ServiceTokens"; | ||
import { Harvest } from "@models/Harvest"; | ||
import { Project } from "@models/Project"; | ||
import { generateProject } from "@test/fakes/Project"; | ||
import { of } from "rxjs"; | ||
import { User } from "@models/User"; | ||
import { generateUser } from "@test/fakes/User"; | ||
import { ShallowHarvestsService } from "@baw-api/harvest/harvest.service"; | ||
import { generateHarvest } from "@test/fakes/Harvest"; | ||
import { AllUploadsComponent } from "./all-uploads.component"; | ||
|
||
// the functionality that the project names are shown in the harvest list | ||
// and the correct api calls are made is asserted in the harvest list component | ||
// these tests assert that the harvest list component is extended correctly | ||
describe("AllUploadsComponent", () => { | ||
let spectator: Spectator<AllUploadsComponent>; | ||
let fakeHarvest: Harvest; | ||
let fakeHarvestApi: SpyObject<ShallowHarvestsService>; | ||
|
||
const createComponent = createRoutingFactory({ | ||
declarations: [LoadingComponent, ConfirmationComponent, UserLinkComponent], | ||
component: AllUploadsComponent, | ||
imports: [MockBawApiModule, SharedModule], | ||
mocks: [ToastrService], | ||
}); | ||
|
||
function setup(): void { | ||
fakeHarvest = new Harvest(generateHarvest({ status: "uploading" })); | ||
|
||
spectator = createComponent({ detectChanges: false }); | ||
|
||
const injector = spectator.inject(Injector); | ||
fakeHarvest["injector"] = injector; | ||
|
||
fakeHarvestApi = spectator.inject(SHALLOW_HARVEST.token); | ||
fakeHarvest.addMetadata({ | ||
paging: { items: 1, page: 0, total: 1, maxPage: 5 }, | ||
}); | ||
|
||
// since the harvest creator is a resolved model, we need to mock the creator property | ||
const fakeUser: User = new User(generateUser()); | ||
spyOnProperty(fakeHarvest, "creator").and.callFake(() => fakeUser); | ||
|
||
const mockHarvestProject: Project = new Project(generateProject()); | ||
spyOnProperty(fakeHarvest, "project").and.callFake( | ||
() => mockHarvestProject | ||
); | ||
|
||
// mock the harvest service filter API to populate the | ||
// list component ngx-datatable | ||
const mockResponse = of([fakeHarvest]); | ||
fakeHarvestApi.filter.and.callFake(() => mockResponse); | ||
fakeHarvestApi.transitionStatus.and.callFake(() => of(fakeHarvest)); | ||
|
||
spectator.detectChanges(); | ||
} | ||
|
||
beforeEach(() => setup()); | ||
|
||
assertPageInfo(AllUploadsComponent, ["Recording Uploads", "All Recording Uploads"]); | ||
|
||
it("should create", () => { | ||
expect(spectator.component).toBeInstanceOf(AllUploadsComponent); | ||
}); | ||
|
||
it("should return 'null' for the project", () => { | ||
expect(spectator.component.project).toBeNull(); | ||
}); | ||
|
||
it("should have the harvest list table", () => { | ||
const datatableElement: HTMLElement = | ||
spectator.query<HTMLElement>("ngx-datatable"); | ||
expect(datatableElement).toExist(); | ||
}); | ||
|
||
it("should make the correct api calls", () => { | ||
expect(fakeHarvestApi.transitionStatus).not.toHaveBeenCalled(); | ||
|
||
// test that the filter object that the filter service was called with did not contain a filter key | ||
expect(fakeHarvestApi.filter).not.toHaveBeenCalledWith( | ||
jasmine.objectContaining({ | ||
filter: jasmine.any(Object), | ||
}) | ||
); | ||
|
||
// assert that projection conditions were still applied to the request body | ||
expect(fakeHarvestApi.filter).toHaveBeenCalledWith( | ||
jasmine.objectContaining({ | ||
projection: { | ||
include: [ | ||
"id", | ||
"projectId", | ||
"name", | ||
"createdAt", | ||
"creatorId", | ||
"streaming", | ||
"status", | ||
], | ||
}, | ||
}), | ||
); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/app/components/admin/all-uploads/all-uploads.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component } from "@angular/core"; | ||
import { List } from "immutable"; | ||
import { ListComponent } from "@components/harvest/pages/list/list.component"; | ||
import { ActivatedRoute } from "@angular/router"; | ||
import { ShallowHarvestsService } from "@baw-api/harvest/harvest.service"; | ||
import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; | ||
import { adminCategory, adminUploadsMenuItem } from "../admin.menus"; | ||
import { adminMenuItemActions } from "../dashboard/dashboard.component"; | ||
|
||
@Component({ | ||
selector: "baw-all-uploads", | ||
templateUrl: "../../harvest/pages/list/list.component.html", | ||
}) | ||
class AllUploadsComponent extends ListComponent { | ||
public constructor( | ||
private modal: NgbModal, | ||
private api: ShallowHarvestsService, | ||
private activatedRoute: ActivatedRoute | ||
) { | ||
super(modal, api, activatedRoute); | ||
} | ||
|
||
public override get project() { | ||
return null; | ||
} | ||
} | ||
|
||
AllUploadsComponent.linkToRoute({ | ||
category: adminCategory, | ||
pageRoute: adminUploadsMenuItem, | ||
menus: { actions: List(adminMenuItemActions) }, | ||
}); | ||
|
||
export { AllUploadsComponent }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.