Skip to content

Commit

Permalink
refactor(StudentDataService): Move getNotebookItemsByNodeId() (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Oct 30, 2023
1 parent 082555c commit f675f81
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 360 deletions.
27 changes: 0 additions & 27 deletions src/app/services/studentDataService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('StudentDataService', () => {
shouldEvaluateHasWorkCreatedAfterTimestampFalse();
shouldEvaluateHasWorkCreatedAfterTimestampTrue();
shouldGetBranchPathTakenEventsByNodeId();
shouldGetNotebookItemsByNodeId();
shouldHandleSaveStudentWorkToServerSuccess();
shouldHandleSaveEventsToServerSuccess();
shouldHandleSaveAnnotationsToServerSuccess();
Expand Down Expand Up @@ -94,32 +93,6 @@ function shouldGetBranchPathTakenEventsByNodeId() {
});
}

function shouldGetNotebookItemsByNodeId() {
it('should get notebook items by node id', () => {
const notebook = {
allItems: [
{ nodeId: 'node1' },
{ nodeId: 'node1' },
{ nodeId: 'node1' },
{ nodeId: 'node1' },
{ nodeId: 'node1' },
{ nodeId: 'node2' },
{ nodeId: 'node2' },
{ nodeId: 'node2' },
{ nodeId: 'node2' },
{ nodeId: 'node2' }
]
};
const notebookItems = service.getNotebookItemsByNodeId(notebook, 'node1');
expect(notebookItems.length).toEqual(5);
expect(notebookItems[0].nodeId).toEqual('node1');
expect(notebookItems[1].nodeId).toEqual('node1');
expect(notebookItems[2].nodeId).toEqual('node1');
expect(notebookItems[3].nodeId).toEqual('node1');
expect(notebookItems[4].nodeId).toEqual('node1');
});
}

function shouldHandleSaveStudentWorkToServerSuccess() {
xit('should handle save student work to server success', () => {
service.studentData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { AbstractConstraintStrategy } from './AbstractConstraintStrategy';
export class AddXNumberOfNotesOnThisStepConstraintStrategy extends AbstractConstraintStrategy {
evaluate(criteria: any): boolean {
try {
const notebookItemsByNodeId = this.dataService.getNotebookItemsByNodeId(
const notebookItemsByNodeId = this.getNotebookItemsByNodeId(
this.notebookService.getNotebookByWorkgroup(),
criteria.params.nodeId
);
return notebookItemsByNodeId.length >= criteria.params.requiredNumberOfNotes;
} catch (e) {}
return false;
}

private getNotebookItemsByNodeId(notebook: any, nodeId: string): any[] {
return notebook.allItems.filter((item) => item.nodeId === nodeId);
}
}
10 changes: 0 additions & 10 deletions src/assets/wise5/services/studentDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,6 @@ export class StudentDataService extends DataService {
);
}

getNotebookItemsByNodeId(notebook, nodeId) {
const notebookItemsByNodeId = [];
for (const notebookItem of notebook.allItems) {
if (notebookItem.nodeId === nodeId) {
notebookItemsByNodeId.push(notebookItem);
}
}
return notebookItemsByNodeId;
}

populateHistories(events) {
this.stackHistory = [];
for (const event of events) {
Expand Down
Loading

0 comments on commit f675f81

Please sign in to comment.