Skip to content

Commit

Permalink
Uncommented not working test
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Oct 17, 2023
1 parent a93edce commit 1dc77fb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 72 deletions.
8 changes: 8 additions & 0 deletions src/app/app.menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ export const isProjectEditorPredicate = (
*/
export const isAdminPredicate = (user: User): boolean =>
isLoggedInPredicate(user) && user.isAdmin;

/**
* Returns true only if the user is an admin and can see work in progress items
* This predicate differs from the `isAdminPredicate` for semantic reasons
*
* @param user User session data. This will be used to check if the user is an admin
*/
export const isWorkInProgressPredicate = isAdminPredicate;
5 changes: 3 additions & 2 deletions src/app/components/projects/projects.menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isAdminPredicate,
isLoggedInPredicate,
isProjectEditorPredicate,
isWorkInProgressPredicate,
} from "src/app/app.menus";
import { CommonRouteTitles } from "src/app/stringConstants";
import {
Expand Down Expand Up @@ -111,8 +112,8 @@ export const uploadAnnotationsProjectMenuItem = menuRoute({
icon: ["fas", "file-import"],
label: "Batch Upload Annotations",
parent: projectMenuItem,
// TODO Change to isProjectEditorPredicate
predicate: isAdminPredicate,
// TODO: Once functionality is implemented, this should be changed to isProjectEditorPredicate
predicate: isWorkInProgressPredicate,
route: projectMenuItem.route.add("batch-annotations"),
tooltip: () =>
"(UNDER DEVELOPMENT) Upload multiple annotations to this project",
Expand Down
131 changes: 66 additions & 65 deletions src/app/components/regions/pages/new/new.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,68 +128,69 @@ describe("RegionsNewComponent", () => {
});
});

// xdescribe("routing and resolvers", () => {
// const nestedRoutes = regionsRoute.compileRoutes(getRouteConfigForPage);
// const shallowRoutes = shallowRegionsRoute.compileRoutes(
// getRouteConfigForPage
// );

// let project: Project;
// let defaultProject: Project;

// beforeEach(() => {
// // create 2 stub projects so we can clearly assert different ones are loaded
// // on different routes
// project = new Project(generateProject());
// defaultProject = new Project(generateProject());

// // stub both api methods that the two resolvers use
// const api = createSpyObject(ProjectsService);
// api.show.and.callFake(() => of(project));
// api.filter.and.callFake(() => of([defaultProject]));

// // set up ngMocks according to https://ng-mocks.sudo.eu/guides/routing-resolver
// const builder = MockBuilder([
// NewComponent,
// RouterTestingModule.withRoutes([...nestedRoutes, ...shallowRoutes]),
// ])
// .keep(MockBawApiModule, { export: true })
// .provide({ provide: ProjectsService, useValue: api });

// // augment builder with out app level module imports
// return addStandardFormImportsToMockBuilder(builder);
// });

// function setup(path) {
// // boiler plate adapted from https://ng-mocks.sudo.eu/guides/route
// const fixture = MockRender(RouterOutlet);
// const router = fixture.point.injector.get(Router);
// const location = fixture.point.injector.get(Location);

// location.go(path);

// router.initialNavigation();
// tick();

// expect(location.path()).toBe(path);

// const component = ngMocks.find(fixture, NewComponent);
// fixture.detectChanges();

// return component;
// }

// it("should resolve with project id in the the route", fakeAsync(() => {
// const path = `/projects/${project.id}/regions/new`;
// const component = setup(path);

// expect(component.componentInstance.project).toBe(project);
// }));

// it("should resolve the default project for the shallow route", fakeAsync(() => {
// const path = "/regions/new";
// const component = setup(path);

// expect(component.componentInstance.project).toBe(defaultProject);
// }));
// });
describe("routing and resolvers", () => {
const nestedRoutes = regionsRoute.compileRoutes(getRouteConfigForPage);
const shallowRoutes = shallowRegionsRoute.compileRoutes(
getRouteConfigForPage
);

let project: Project;
let defaultProject: Project;

beforeEach(() => {
// create 2 stub projects so we can clearly assert different ones are loaded
// on different routes
project = new Project(generateProject());
defaultProject = new Project(generateProject());

// stub both api methods that the two resolvers use
const api = createSpyObject(ProjectsService);
api.show.and.callFake(() => of(project));
api.filter.and.callFake(() => of([defaultProject]));

// set up ngMocks according to https://ng-mocks.sudo.eu/guides/routing-resolver
const builder = MockBuilder([
NewComponent,
RouterTestingModule.withRoutes([...nestedRoutes, ...shallowRoutes]),
])
.keep(MockBawApiModule, { export: true })
.provide({ provide: ProjectsService, useValue: api });

// augment builder with out app level module imports
return addStandardFormImportsToMockBuilder(builder);
});

function setup(path) {
// boiler plate adapted from https://ng-mocks.sudo.eu/guides/route
const fixture = MockRender(RouterOutlet);
const router = fixture.point.injector.get(Router);
const location = fixture.point.injector.get(Location);

location.go(path);

router.initialNavigation();
tick();

expect(location.path()).toBe(path);

fixture.detectChanges();
const component = ngMocks.find(fixture, NewComponent);
fixture.detectChanges();

return component;
}

fit("should resolve with project id in the the route", fakeAsync(() => {
const path = `/projects/${project.id}/regions/new`;
const component = setup(path);

expect(component.componentInstance.project).toBe(project);
}));

it("should resolve the default project for the shallow route", fakeAsync(() => {
const path = "/regions/new";
const component = setup(path);

expect(component.componentInstance.project).toBe(defaultProject);
}));
});
6 changes: 3 additions & 3 deletions src/app/components/reports/reports.menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { projectMenuItem } from "@components/projects/projects.menus";
import { regionMenuItem } from "@components/regions/regions.menus";
import { siteMenuItem } from "@components/sites/sites.menus";
import { pointMenuItem } from "@components/sites/points.menus";
import { isAdminPredicate } from "src/app/app.menus";
import { isWorkInProgressPredicate } from "src/app/app.menus";
import {
ReportRoute,
newEventReportRoute,
Expand Down Expand Up @@ -37,7 +37,7 @@ function makeViewEventReportMenuItem(
label: "Event Summary Report",
tooltip: () => "Event summary report",
route: eventReportRoute[subRoute],
predicate: isAdminPredicate,
predicate: isWorkInProgressPredicate,
parent,
});
}
Expand All @@ -51,7 +51,7 @@ function makeNewEventReportMenuItem(
label: "New Event Summary Report",
tooltip: () => "New event summary report",
route: newEventReportRoute[subRoute],
predicate: isAdminPredicate,
predicate: isWorkInProgressPredicate,
parent,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ng-container *ngIf="resultTemplate; else defaultTemplate">
<ng-container
[ngTemplateOutletContext]="{ result: item }"
[ngTemplateOutletContext]="{ result: item, term: inputModel, formatter: templateFormatter }"
[ngTemplateOutlet]="resultTemplate"
></ng-container>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TypeaheadInputComponent {
*/
@Input() public searchCallback: TypeaheadSearchCallback;
/** Describes how to convert an object model into a human readable form for use in the pills and typeahead dropdown */
@Input() public resultTemplate: TemplateRef<any>;
@Input() public resultTemplate: TemplateRef<ResultTemplateContext>;
/** Whether the typeahead input should allow multiple inputs in pill form */
@Input() public multipleInputs = true;
/** Text to show above the input field. Usually a one 1-2 word description. */
Expand Down Expand Up @@ -65,6 +65,8 @@ export class TypeaheadInputComponent {
);
};

public templateFormatter = (item: object): string => item.toString();

public onItemSelected($event: NgbTypeaheadSelectItemEvent<object>): void {
$event.preventDefault();
const selectedItem: object = $event.item;
Expand Down

0 comments on commit 1dc77fb

Please sign in to comment.