Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { AdvancedProjectAuthoringComponent } from './advanced-project-authoring.component';

const USER_ID = 7;

function initialize(metadata: any): AdvancedProjectAuthoringComponent {
const configService = jasmine.createSpyObj('ConfigService', ['getContextPath', 'getProjectId']);
configService.getContextPath.and.returnValue('');
configService.getProjectId.and.returnValue(1);
const projectService = jasmine.createSpyObj('TeacherProjectService', ['getProjectMetadata']);
projectService.getProjectMetadata.and.returnValue(metadata);
projectService.project = { metadata: metadata };
const userService = jasmine.createSpyObj('UserService', ['getUserId']);
userService.getUserId.and.returnValue(USER_ID);
const component = new AdvancedProjectAuthoringComponent(
configService,
null,
projectService,
userService
);
component.ngOnInit();
return component;
}

describe('AdvancedProjectAuthoringComponent', () => {
describe('ngOnInit()', () => {
it('should not treat a unit that has never been saved as the user unit', () => {
expect(initialize({ title: 'New Unit' })['isMyUnit']).toBeFalse();
});

it('should treat a unit the user authored as the user unit', () => {
expect(initialize({ authors: [{ id: USER_ID }] })['isMyUnit']).toBeTrue();
});

it('should not treat a unit someone else authored as the user unit', () => {
expect(initialize({ authors: [{ id: USER_ID + 1 }] })['isMyUnit']).toBeFalse();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export class AdvancedProjectAuthoringComponent {
this.navigationType = this.projectService.project.theme ?? 'default';
this.projectJSONString = JSON.stringify(this.projectService.project, null, 4);
this.publishUnitUrl = `${this.configService.getContextPath()}/contact?projectId=${this.configService.getProjectId()}&publish=true`;
this.isMyUnit = this.metadata.authors.some(
(author) => author.id === this.userService.getUserId()
);
this.isMyUnit =
this.metadata.authors?.some((author) => author.id === this.userService.getUserId()) ?? false;
}

protected tabChanged(event: MatTabChangeEvent): void {
Expand Down
Loading