Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr to inquiry v2 #121

Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ export const toolbarConfig_question = {
done_btn_label: 'Done'
};

export const nativeElement = `<div><ul id="ft-id-1" class="ui-fancytree fancytree-container fancytree-plain fancytree-ext-glyph fancytree-ext-dnd5 fancytree-connectors fancytree-treefocus" tabindex="0" role="tree" aria-multiselectable="true" aria-activedescendant="ui-id-2"><li role="treeitem" aria-selected="false" class="fancytree-lastsib" id="ui-id-1" aria-expanded="true"><span class="fancytree-node fancytree-expanded fancytree-folder fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-ef" draggable="true"><span class="fancytree-expander fa fa-caret-down"></span><span role="presentation" class="fancytree-custom-icon fa fa-book"></span><span class="fancytree-title" title="Untitled QuestionSet" style="width:11em;text-overflow:ellipsis;white-space:nowrap;overflow:hidden">Testing6</span></span><ul role="group" style=""><li role="treeitem" aria-selected="false" class="fancytree-lastsib" id="ui-id-2"><span class="fancytree-node fancytree-active fancytree-focused fancytree-folder fancytree-lastsib fancytree-exp-nl fancytree-ico-cf" draggable="true"><span class="fancytree-expander fa "></span><span role="presentation" class="fancytree-custom-icon fa fa-folder-o"></span><span class="fancytree-title" title="Section" style="width:11em;text-overflow:ellipsis;white-space:nowrap;overflow:hidden">Section A</span></span></li></ul></li></ul></div>`;
export const nativeElement = `<div><ul id="ft-id-1" class="ui-fancytree fancytree-container fancytree-plain fancytree-ext-glyph fancytree-ext-dnd5 fancytree-connectors" tabindex="0" role="tree" aria-multiselectable="true"><li role="treeitem" aria-selected="false" class="fancytree-lastsib"><span class="fancytree-node fancytree-folder fancytree-lastsib fancytree-exp-nl fancytree-ico-cf" draggable="true"><span class="fancytree-expander fa "></span><span role="presentation" class="fancytree-custom-icon fa fa-book"></span><span class="fancytree-title" title="Untitled QuestionSet" style="width:15em;text-overflow:ellipsis;white-space:nowrap;overflow:hidden">Untitled QuestionSet</span><span class="ui dropdown sb-dotted-dropdown" autoclose="itemClick" suidropdown="" tabindex="0" style="display: none;">
<span id="contextMenu" class="p-0 w-auto"><i class="icon ellipsis vertical sb-color-black"></i></span>
<span id="contextMenuDropDown" class="menu transition hidden" suidropdownmenu="" style="">
<div id="addchild" class="item">Add Child</div>
</span>
</span></span></li></ul></div>`;

export const getCategoryDefinitionResponse = {
id: 'api.object.category.definition.read',
Expand Down Expand Up @@ -1688,6 +1693,7 @@ export const treeNodeData = {
board: 'CBSE',
status: 'Draft',
showEvidence: 'No',
serverMode: true
},
root: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ describe('EditorComponent', () => {
let component: EditorComponent;
let fixture: ComponentFixture<EditorComponent>;
let toasterService;
let editorService: EditorService;
let treeService: TreeService;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, FormsModule, ReactiveFormsModule, RouterTestingModule],
declarations: [EditorComponent, TelemetryInteractDirective],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [EditorTelemetryService, EditorService, ToasterService,
providers: [EditorTelemetryService, EditorService, ToasterService, TreeService,
{ provide: ConfigService, useValue: configStub }
]
})
Expand All @@ -52,6 +54,8 @@ describe('EditorComponent', () => {
fixture = TestBed.createComponent(EditorComponent);
component = fixture.componentInstance;
toasterService = TestBed.inject(ToasterService);
editorService = TestBed.inject(EditorService);
treeService = TestBed.inject(TreeService);
// tslint:disable-next-line:no-string-literal
editorConfig.context['targetFWIds'] = ['nit_k12'];
// tslint:disable-next-line:no-string-literal
Expand Down Expand Up @@ -752,18 +756,23 @@ describe('EditorComponent', () => {

it('#showQuestionLibraryComponentPage() should set #addQuestionFromLibraryButtonLoader to false and call #saveContent()',
() => {
const editorService = TestBed.inject(EditorService);
const treeService = TestBed.inject(TreeService);
editorService.templateList = ['Subjective Question'];
component.collectionId = 'do_12345';
component.organisationFramework = 'nit_k12';
component.editorConfig = editorConfig_question;
component.questionlibraryInput.searchFormConfig = categoryDefinition.result.objectCategoryDefinition.forms.searchConfig;
component.questionComponentInput.metadataFormConfig = categoryDefinition.result.objectCategoryDefinition.forms.childMetadata;
spyOn(treeService, 'getActiveNode').and.returnValue({data: {metadata: {}}});
spyOn(editorService, 'getContentChildrens').and.returnValue([{}, {}]);
component.questionlibraryInput.metadataFormConfig = categoryDefinition.result.objectCategoryDefinition.forms.childMetadata;
treeService.treeNativeElement = nativeElement;
spyOn(treeService, 'getActiveNode').and.returnValue({data: {metadata: {}}});
editorService.contentsCount = 0;
spyOn(editorService, 'getContentChildrens').and.returnValue([]);
spyOn(editorService, 'checkIfContentsCanbeAdded').and.returnValue(true);
spyOn(treeService, 'getEval').and.returnValue({mode: "server"});


const serverMode = {data: {metadata: {serverMode: true}}};
spyOn(treeService, 'getFirstChild').and.callFake(()=> serverMode);
let result = treeService.getEval();

spyOn(component, 'saveContent').and.callFake(() => {
return Promise.resolve('success');
});
Expand All @@ -773,7 +782,9 @@ describe('EditorComponent', () => {
expect(treeService.getActiveNode).toHaveBeenCalled();
expect(component.buttonLoaders.addQuestionFromLibraryButtonLoader).toBeFalsy();
expect(component.questionlibraryInput).toBeDefined();
expect(treeService.getEval).toHaveBeenCalled();
expect(editorService.getContentChildrens).toHaveBeenCalled();
expect(treeService.getFirstChild).toHaveBeenCalled();
expect(result).toBe(true)
expect(component.pageId).toEqual('question_library');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,16 @@ export class EditorComponent implements OnInit, OnDestroy, AfterViewInit {
},
targetPrimaryCategories: questionCategory,
collectionId: this.collectionId,
existingcontentCounts: this.editorService.getContentChildrens().length,
collection: activeNode?.data?.metadata,
framework: this.organisationFramework,
editorConfig: this.editorConfig,
searchFormConfig: this.questionlibraryInput.searchFormConfig,
metadataFormConfig: this.questionlibraryInput.metadataFormConfig
};
this.questionlibraryInput.collection.eval = this.treeService.getEval();
if(this.treeService.getEval()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of taking this value from tree object can you set the evalMode in editorConfig take it from editorConfig ?
I have doubt here calling treeService will give error for Question Editor flow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is only for sending evalMode property to the resource library for composite search. Here, we are not making use of this inside editor just we are passing the configuration to library this will not break anything in editor flow.
@rajnishdargan

this.questionlibraryInput.collection.evalMode = "server"
}
this.questionlibraryInput.existingcontentCounts = this.editorService.getContentChildrens().length
this.pageId = 'question_library';
console.log(this.questionlibraryInput);
}).catch(((error: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export const mockData = {
code: 'showTimer',
},
{
code: 'mode'
code: 'serverMode'
}
]
}
Expand Down Expand Up @@ -418,9 +418,7 @@ export const mockData = {
createdBy: '5a587cc1-e018-4859-a0a8-e842650b9d64',
compatibilityLevel: 5,
navigationMode: 'non-linear',
eval: {
mode: 'server'
},
serverMode: true,
timeLimits: {
questionSet: {
min: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ export class MetaFormComponent implements OnChanges, OnDestroy {
if (field.code === 'allowECM') {
field.default = _.get(metaDataFields, 'recordedBy') !== 'Self' ? 'Yes' : 'No' ;
}
if (field.code === 'mode') {
field.default = _.get(metaDataFields, 'eval.mode')
if (field.code === 'serverMode') {
field.default = _.get(metaDataFields, 'evalMode') == this.configService.editorConfig.evalMode || _.get(metaDataFields, 'serverMode') === true;

}
if (field.code === 'instances') {
field.default = !_.isEmpty(metaDataFields, 'instances') ? _.get(metaDataFields, 'instances.label') : '' ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,9 @@ export const mockTreeService = {
return {
data: {
id: "do_11330103476396851218",
metadata: {
evalMode: 'server'
}
},
getParent: () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,11 @@ export class QuestionComponent implements OnInit, AfterViewInit, OnDestroy {
this.editorService.data = {};
this.editorService.selectedSection = selectedUnitId;
let metaData = this.getQuestionMetadata();
metaData.eval = activeNode?.data.metadata?.eval || data?.data?.eval;

const evalMode = data?.data?.evalMode || data?.data?.metadata?.evalMode || activeNode?.data.metadata?.evalMode;
if(evalMode){
metaData.evalMode = evalMode;
}
this.setQuestionTypeValues(metaData);
return {
nodesModified: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
"readQuestionFields": "body,primaryCategory,mimeType,qType,answer,templateId,responseDeclaration,interactionTypes,interactions,name,solutions,editorState,media,remarks,evidence,hints,instructions,outcomeDeclaration,",
"omitFalseyProperties":["topic", "topicsIds", "targetTopicIds", "keywords"],
"evaluableQuestionSet": "PIAA Question Set",
"server":{"mode":"server"},
"client":{"mode":"client"},
"editorModeCheck":"server",
"serverSearch": "{\"mode\":\"server\"}",
"clientSearch": "{\"mode\":\"client\"}",
"evalMode": "server",
"questionSet": {
"maxQuestionsLimit": 500
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,36 @@ describe('EditorService', () => {

it('#getCollectionHierarchy should call when no section id and parent', () => {
treeService.treeCache.nodesModified = treeData.treeNode;
treeService.treeNativeElement = nativeElement;
// treeService.treeNativeElement = nativeElement;
// treeService.setTreeElement(nativeElement);
spyOn(treeService, 'setTreeElement').and.returnValue(nativeElement)
spyOn(editorService, 'getCollectionHierarchy').and.callThrough();
spyOn(editorService.treeService, 'getFirstChild').and.callFake(() => treeData.treeNode.data);
spyOn(editorService, 'getUpdatedNodeMetaData').and.callFake(() => { return treeService.treeCache.nodesModified });
spyOn(treeService, 'getFirstChild').and.callFake(() => {
return { data: { metadata: { identifier: '0123' } } };
});
hierarchyRootNodeData.folder = false;
editorService.getHierarchyObj(hierarchyRootNodeData);
editorService.getCollectionHierarchy();
// expect(treeService.treeNativeElement).toEqual(nativeElement);
expect(editorService.getCollectionHierarchy).toHaveBeenCalled();
});

it('#getUpdatedNodeMetaData should return root nodesModified data', () => {
treeService.treeCache.nodesModified = treeData.treeNode;
treeService.treeCache.nodesModified = {"da0ac2f0-1ea3-464a-bc03-f62b71415837": {root: false, metadata: {}}};
treeService.treeNativeElement = nativeElement;
spyOn(treeService, 'getFirstChild').and.callFake(()=> treeData.treeNode.data);
spyOn(treeService, 'getFirstChild').and.callFake(() => {
return { data: { metadata: { identifier: '0123', evalMode: 'server' } } };
});
spyOn(editorService, 'getUpdatedNodeMetaData').and.callThrough();
editorService.getUpdatedNodeMetaData();
expect(editorService.getUpdatedNodeMetaData).toHaveBeenCalled();
});

it('#getUpdatedNodeMetaData should delete serverMode property', () => {
treeService.treeCache.nodesModified = {"da0ac2f0-1ea3-464a-bc03-f62b71415837": {root: true, metadata: {serverMode: true}}};
treeService.treeNativeElement = nativeElement;
spyOn(treeService, 'getFirstChild').and.callFake(() => {
return { data: { metadata: { identifier: '0123', evalMode: 'server' } } };
});
spyOn(editorService, 'getUpdatedNodeMetaData').and.callThrough();
editorService.getUpdatedNodeMetaData();
expect(editorService.getUpdatedNodeMetaData).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,14 @@ export class EditorService {
return node.root;
});
const parentNode = this.treeService.getFirstChild().data;

_.forEach(this.treeService.treeCache.nodesModified, (node, nodeId)=>{
if(!node.root && parentNode?.eval || parentNode?.metadata?.eval){
this.treeService.treeCache.nodesModified[nodeId].metadata.eval = parentNode.eval || parentNode?.metadata?.eval;
if(!node.root && parentNode?.evalMode || parentNode?.metadata?.evalMode){
this.treeService.treeCache.nodesModified[nodeId].metadata.evalMode = parentNode?.evalMode || parentNode?.metadata?.evalMode;
}

})
if(this.treeService.treeCache.nodesModified[parentNodeId]?.metadata.hasOwnProperty('mode')) {
delete this.treeService.treeCache.nodesModified[parentNodeId]?.metadata?.mode
if(this.treeService.treeCache.nodesModified[parentNodeId]?.metadata.hasOwnProperty('serverMode')) {
delete this.treeService.treeCache.nodesModified[parentNodeId]?.metadata?.serverMode
}
return this.treeService.treeCache.nodesModified;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const treeNode = {
"keywords": [
"test"
],
"serverMode": true,
"subject": [
"History"
],
Expand Down Expand Up @@ -63,7 +64,7 @@ export const treeNode = {
"medium": [
"English"
],
"mode": "server",
"evalMode": "server",
"createdOn": "2021-04-22T14:23:40.169+0000",
"contentDisposition": "inline",
"additionalCategories": [
Expand Down Expand Up @@ -124,9 +125,6 @@ export const treeCache = {
"min": 0
}
},
"eval": {
"mode": "server"
},
"description": "desc",
"board": "General Nursing Midwifery",
"medium": [
Expand Down Expand Up @@ -161,9 +159,6 @@ export const treeCache = {
"max": 0,
"min": 0
}
},
"eval": {
"mode": "client"
}
},
"isNew": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ describe('TreeService', () => {
spyOn(treeService, 'getActiveNode').and.callFake(()=> treeNode);
treeService.updateTreeNodeMetadata(treeNode,undefined,'Observation', 'QuestionSet');
})


it('should call updateEvaluable for root element', ()=> {
treeService.treeCache = treeCache;
treeService.treeNativeElement = nativeElement;
spyOn(treeService, 'getFirstChild').and.callFake(()=> treeNode);
const serverMode = {data: {metadata: {serverMode: true}}};
spyOn(treeService, 'updateFirstChild').and.callFake(() => {});
spyOn(treeService,'getFirstChild').and.callFake(() => serverMode);

treeService.updateEvaluable('do_113263678834016256111');
expect(treeService.getFirstChild).toHaveBeenCalled();
Expand All @@ -89,10 +89,23 @@ describe('TreeService', () => {
treeService.updateEvaluable('da0ac2f0-1ea3-464a-bc03-f62b71415837');
expect(treeService.getFirstChild).toHaveBeenCalled();
});


it('should call getEval method', () => {
spyOn(treeService, 'getFirstChild').and.callFake(()=> treeNode);
treeService.getEval();
const serverMode = {data: {metadata: {serverMode: true}}};
spyOn(treeService, 'getFirstChild').and.callFake(()=> serverMode);
let result = treeService.getEval();
expect(treeService.getFirstChild).toHaveBeenCalled();
expect(result).toBe(true)
});

it('should call overrideEvaluable method', () => {
// const serverMode = {data: {metadata: {serverMode: true}}};
treeService.treeCache = treeCache;
const serverMode = {data: {metadata: {serverMode: true}}};
spyOn(treeService, 'getFirstChild').and.callFake(()=> serverMode);
treeService.overrideEvaluable('da0ac2f0-1ea3-464a-bc03-f62b71415837')
spyOn(treeService, 'overrideEvaluable');
expect(treeService.getFirstChild).toHaveBeenCalled();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,35 +253,41 @@ export class TreeService {
}

updateEvaluable(nodeId){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method call of updateEvaluable in this service can you call it based on some condition check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the method we have condition based update for evalMode. If I keep outside this will requires more changes and testing now.
@rajnishdargan

this.treeCache.nodesModified[nodeId].metadata.eval = this.treeCache.nodesModified[nodeId].metadata.primaryCategory === this.configService.editorConfig.evaluableQuestionSet ?
this.configService.editorConfig.server:this.configService.editorConfig.client;
if(this.treeCache.nodesModified[nodeId].metadata.primaryCategory === this.configService.editorConfig.evaluableQuestionSet) {
this.treeCache.nodesModified[nodeId].metadata.evalMode = this.configService.editorConfig.evalMode
}
if(!this.treeCache.nodesModified[nodeId].root){
this.treeCache.nodesModified[nodeId].metadata.eval = this.getFirstChild().data.primaryCategory === this.configService.editorConfig.evaluableQuestionSet?
this.configService.editorConfig.server:this.configService.editorConfig.client;
if(this.getFirstChild().data.primaryCategory === this.configService.editorConfig.evaluableQuestionSet) {
this.treeCache.nodesModified[nodeId].metadata.evalMode = this.configService.editorConfig.evalMode;
}
this.overrideEvaluable(nodeId);
} else {
if(this.getFirstChild().data?.metadata.mode) {
this.treeCache.nodesModified[nodeId].metadata.eval = this.getFirstChild().data.metadata.mode === this.configService.editorConfig.editorModeCheck ?
this.configService.editorConfig.server:this.configService.editorConfig.client;
const firstChild = this.getFirstChild().data?.metadata;
if(firstChild?.serverMode) {
this.treeCache.nodesModified[nodeId].metadata.evalMode = this.configService.editorConfig.evalMode;
this.updateFirstChild(this.treeCache.nodesModified[nodeId].metadata.evalMode)
} else if(!firstChild?.serverMode) {
delete this.treeCache.nodesModified[nodeId].metadata.evalMode;
delete $(this.treeNativeElement).fancytree('getRootNode').getFirstChild()?.data?.evalMode
}
this.updateFirstChild(this.treeCache.nodesModified[nodeId].metadata.eval)
}
}

updateFirstChild(evalMode:any) {
$(this.treeNativeElement).fancytree('getRootNode').getFirstChild().data.eval = evalMode;
$(this.treeNativeElement).fancytree('getRootNode').getFirstChild().data.evalMode = evalMode;
}

getEval() {
return this.getFirstChild().data?.eval?.mode === this.configService.editorConfig.server.mode ||
this.getFirstChild().data.metadata?.eval?.mode === this.configService.editorConfig.server.mode ? this.configService.editorConfig.serverSearch : this.configService.editorConfig.clientSearch
if(this.getFirstChild().data?.serverMode || this.getFirstChild().data?.metadata?.serverMode) {
return true
}
return false
}

overrideEvaluable(nodeId){
const firstNode = this.getFirstChild()
if(this.getFirstChild().data.metadata.mode) {
this.treeCache.nodesModified[nodeId].metadata.eval = firstNode.data.metadata.mode === this.configService.editorConfig.editorModeCheck ?
this.configService.editorConfig.server:this.configService.editorConfig.client;
if(this.getFirstChild().data?.metadata?.serverMode && firstNode.data?.metadata?.serverMode) {
this.treeCache.nodesModified[nodeId].metadata.evalMode = this.configService.editorConfig.evalMode
}
}

Expand Down