针对(未知网址)的Http错误响应:0未知在没有后端的情况下运行茉莉花单元测试时出错

时间:2019-01-23 11:05:50

标签: javascript angular typescript jasmine karma-jasmine

Http Failure response error is coming when I run test cases without the web api. When the web api is running, the tests are running fine

以下是我的代码段:

beforeEach(async(() => {
    TestBed.configureTestingModule({
        declarations: [PlanDirectiveReadOnlyComponent, TitleCasePipe, PlanDirectivePhaseComponent, StructureComponent,
            EditPhaseComponent, TotalPhaseComponent,
            GoalIntellisenseComponent],
        imports: [HttpClientModule, FormsModule, ReactiveFormsModule, DialogModule, TableModule, RouterTestingModule],
        providers: [PlanOrderService, {
            provide: ActivatedRoute,
            useValue: {
                params: Observable.of({ orderId: 'Order_2' })
            }
        }, AppService, PlanDirectiveTemplateDetailsService,
            ConfirmationService
        ]
    })
        .compileComponents();
}));

beforeEach(() => {
    fixture = TestBed.createComponent(PlanDirectiveReadOnlyComponent);
    planDirectiveTemplateDetails = TestBed.get(PlanDirectiveTemplateDetailsService);
    appService = TestBed.get(AppService);
    component = fixture.componentInstance;
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;
});

afterEach(function () {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('should create', () => {
    spyOn(component, 'getPatient').and.returnValue(true);
    expect(component).toBeTruthy();
});

it('should fetch patient details using order id', async(() => {
    planDirectiveTemplateDetails = TestBed.get(PlanDirectiveTemplateDetailsService);

    const patient = {
        ID: 'pat_1', AnonymizedID: 'abnhuio rtret', Name: 'ABENE SENATOR SNOW'
    };

    spyOn(planDirectiveTemplateDetails, 'getPatientByOrderId').and.callFake(() => {
        return Observable.of<Patient>(patient);
    });
    component.getPatient();

    fixture.whenStable().then(() => {
        expect(component.appService.objPlanDirectiveDetails.isBackButtonPressed).toBeFalsy();
        expect(component.patientLastNameCharacter).toEqual('A');
        expect(component.patientFirstNameCharacter).toEqual('S');
    });
}));

it('should extract data from url', async(() => {
    spyOn(planDirectiveTemplateDetails, 'getStructureSetIdByorderId').and.returnValue(Observable.of('CT_1'));
    component.routeParameters();

    fixture.whenStable().then(() => {
        expect(component.orderId).toBe('Order_2');
        expect(component.structuresetId).toBe('CT_1');
    });
}));

it('should fetch treatment instruction data from DB', async(() => {

    treatmentInst = `{"Identifier":"6a10990d-6696-480d-b9f2-3024add297c1","DisplayName":"Test Template",
    "AnatomicalRegion":"Pelvis","AnatomicalSite":"Prostate","OARs":{"Structure":[{"Id":"OAR1","Code":"15900","Schema":"FMA",
    "SchemaVersion":"3.2","Meaning":"Controlateral Breast","Color":null,"Name":"Controlateral Breast"},{"Id":"OAR2","Code":"14544",
    "Schema":"FMA","SchemaVersion":"3.2","Meaning":"Ipsilateral lung","Color":null,"Name":"Ipsilateral lung"},
    {"Id":"OAR3","Code":"14544","Schema":"FMA","SchemaVersion":"3.2","Meaning":"Controlateral lung","Color":null,
    "Name":"Controlateral lung"},{"Id":"OAR4","Code":"14544","Schema":"FMA","SchemaVersion":"3.2","Meaning":"Heart","Color":null,
    "Name":"Heart"}]},"Targets":{"Structure":[{"Id":"Target1","Code":"PTV","Schema":"99VMS_STRUCTCODE","SchemaVersion":"1",
    "Meaning":"Planning Target Volume","Color":null,"Name":"PTV High"},{"Id":"Target2","Code":"CTV","Schema":"99VMS_STRUCTCODE",
    "SchemaVersion":"1","Meaning":"Clinical Target Volume","Color":null,"Name":"CTV Low"}]},"OARObjectives":{
        "Objective":[{"StructureId":"OAR1","Phase":"1","ClinicalGoal":{"DVHObjective":"Max[Gy]","Evaluator":"<=2"},
        "AcceptableVariation":{"DVHObjective":"Max[Gy]","Evaluator":"<=4"},"Priority":"1"},{"StructureId":"OAR1","Phase":"2",
        "ClinicalGoal":{"DVHObjective":"D5%[Gy]","Evaluator":"<=1.44"},"AcceptableVariation":{"DVHObjective":"D5%[Gy]",
        "Evaluator":"<=1.42"},"Priority":"2"},{"StructureId":"OAR2","Phase":"1","ClinicalGoal":{"DVHObjective":"V16cc[%]",
        "Evaluator":"<=15"},"AcceptableVariation":{"DVHObjective":"V16cc[%]","Evaluator":"<=11"},"Priority":"3"},
        {"StructureId":"OAR2","Phase":"2","ClinicalGoal":{"DVHObjective":"V16cc[%]","Evaluator":"<=15"},"AcceptableVariation":
        {"DVHObjective":"V16cc[%]","Evaluator":"<=11"},"Priority":"3"},{"StructureId":"OAR3","Phase":"2","ClinicalGoal":
        {"DVHObjective":"Max[cc]","Evaluator":"<=2"},"AcceptableVariation":{"DVHObjective":"Max[cc]","Evaluator":"<=5"},
        "Priority":"4"},{"StructureId":"OAR4","Phase":"2","ClinicalGoal":{"DVHObjective":"Mean[%]","Evaluator":"<=2"},
        "AcceptableVariation":{"DVHObjective":"Mean[%]","Evaluator":"<=3"},"Priority":"5"}]},"PrescribedSessions":
        {"Session":[{"Id":"1","ReferencedPhase":"1","Imaging":"None"},{"Id":"2","ReferencedPhase":"1","Imaging":"None"},
        {"Id":"3","ReferencedPhase":"1","Imaging":"None"},{"Id":"4","ReferencedPhase":"1","Imaging":"None"},{"Id":"5",
        "ReferencedPhase":"1","Imaging":"None"},{"Id":"6","ReferencedPhase":"1","Imaging":"None"},{"Id":"7","ReferencedPhase":"1",
        "Imaging":"None"},{"Id":"8","ReferencedPhase":"1","Imaging":"None"},{"Id":"9","ReferencedPhase":"1","Imaging":"None"},
        {"Id":"10","ReferencedPhase":"1","Imaging":"None"},{"Id":"11","ReferencedPhase":"1","Imaging":"None"},{"Id":"12",
        "ReferencedPhase":"1","Imaging":"None"},{"Id":"13","ReferencedPhase":"1","Imaging":"None"},{"Id":"14","ReferencedPhase":"1",
        "Imaging":"None"},{"Id":"15","ReferencedPhase":"1","Imaging":"None"},{"Id":"16","ReferencedPhase":"2","Imaging":"None"},
        {"Id":"17","ReferencedPhase":"2","Imaging":"None"},{"Id":"18","ReferencedPhase":"2","Imaging":"None"},{"Id":"19",
        "ReferencedPhase":"2","Imaging":"None"},{"Id":"20","ReferencedPhase":"2","Imaging":"None"}]},"Phases":{"Phase":[{"Id":"1",
        "PrescriptionTargets":{"PrescriptionTarget":[{"StructureId":"Target1","FractionDoseGy":"4","FractionCount":15,
        "TotalDose":60.0,"Objectives":{"Objective":[{"StructureId":null,"Phase":null,"ClinicalGoal":{"DVHObjective":"D5%[Gy]",
        "Evaluator":"<=52"},"AcceptableVariation":{"DVHObjective":"D5%[Gy]","Evaluator":"<=53"},"Priority":"1"},{"StructureId":null,
        "Phase":null,"ClinicalGoal":{"DVHObjective":"Max[%]","Evaluator":"<=105"},"AcceptableVariation":{"DVHObjective":"Max[%]",
        "Evaluator":"<=115"},"Priority":"2"}]}},{"StructureId":"Target2","FractionDoseGy":"2","FractionCount":15,"TotalDose":30.0,
        "Objectives":{"Objective":[{"StructureId":null,"Phase":null,"ClinicalGoal":{"DVHObjective":"V43%[cc]","Evaluator":"<=50"},
        "AcceptableVariation":{"DVHObjective":"V43%[cc]","Evaluator":"<=45"},"Priority":"1"},{"StructureId":null,"Phase":null,
        "ClinicalGoal":{"DVHObjective":"Mean[cc]","Evaluator":"<=7"},"AcceptableVariation":{"DVHObjective":"Mean[cc]","Evaluator":
        "<=10"},"Priority":"2"}]}}]}},{"Id":"2","PrescriptionTargets":{"PrescriptionTarget":[{"StructureId":"Target1",
        "FractionDoseGy":"8","FractionCount":5,"TotalDose":40.0,"Objectives":{"Objective":[{"StructureId":null,"Phase":null,
        "ClinicalGoal":{"DVHObjective":"D3cc[Gy]","Evaluator":"<=54"},"AcceptableVariation":{"DVHObjective":"D3cc[Gy]","Evaluator":
        "<=52"},"Priority":"1"},{"StructureId":null,"Phase":null,"ClinicalGoal":{"DVHObjective":"Mean[Gy]","Evaluator":"<=19"},
        "AcceptableVariation":{"DVHObjective":"Mean[Gy]","Evaluator":"<=10"},"Priority":"2"}]}},{"StructureId":"Target2",
        "FractionDoseGy":"4","FractionCount":5,"TotalDose":20.0,"Objectives":{"Objective":[{"StructureId":null,"Phase":null,
        "ClinicalGoal":{"DVHObjective":"V43Gy[cc]","Evaluator":"<=50"},"AcceptableVariation":{"DVHObjective":"V43Gy[cc]",
        "Evaluator":"<=52"},"Priority":"1"},{"StructureId":null,"Phase":null,"ClinicalGoal":{"DVHObjective":"V48Gy[%]","Evaluator":
        "<=30"},"AcceptableVariation":{"DVHObjective":"V48Gy[%]","Evaluator":"<=28"},"Priority":"2"}]}}]}}]},"Notes":{"Note":
        [{"TimeStamp":"30 Jul 2018, 1:31 PM","UpdatedBy":"RO","Comment":"Comment Added by Remote Oncologist"},{"TimeStamp":
        "30 Jul 2018, 1:31 PM","UpdatedBy":"RO","Comment":"Comment Added by Remote Oncologist"}]}}`;

    spyOn(planDirectiveTemplateDetails, 'getTemplateByTemplateId').and.returnValue(Observable.of(treatmentInst));
    spyOn(component, 'updateTemplateInUI').and.returnValue(true);
    spyOn(appService, 'changeTreatment').and.returnValue(true);

    component.getTemplate();

    fixture.whenStable().then(() => {
        expect(component.TemplateSiteName.siteName).toBe('Prostate');
        expect(component.TemplateSiteName.templateName).toBe('Test Template');
        expect(appService.changeTreatment).toHaveBeenCalled();
    });
}));

it('should update treatment instruction data in UI', async(() => {

    treatmentInst = {
        Identifier: '6a10990d-6696-480d-b9f2-3024add297c1', DisplayName: 'Test Template', AnatomicalRegion: 'Pelvis',
        AnatomicalSite: 'Prostate', OARs: {
            Structure: [{
                Id: 'OAR1', Code: 15900, Schema: 'FMA', SchemaVersion: 3.2,
                Meaning: 'Controlateral Breast', Color: null, Name: 'Controlateral Breast'
            }, {
                Id: 'OAR2', Code: 14544, Schema: 'FMA',
                SchemaVersion: 3.2, Meaning: 'Ipsilateral lung', Color: null, Name: 'Ipsilateral lung'
            }, {
                Id: 'OAR3', Code: 14544, Schema: 'FMA',
                SchemaVersion: 3.2, Meaning: 'Controlateral lung', Color: null, Name: 'Controlateral lung'
            }, {
                Id: 'OAR4', Code: 14544, Schema: 'FMA',
                SchemaVersion: 3.2, Meaning: 'Heart', Color: null, Name: 'Heart'
            }]
        }, Targets: {
            Structure: [{
                Id: 'Target1', Code: 'PTV',
                Schema: '99VMS_STRUCTCODE', SchemaVersion: 1, Meaning: 'Planning Target Volume', Color: null, Name: 'PTV High'
            },
            {
                Id: 'Target2', Code: 'CTV', Schema: '99VMS_STRUCTCODE', SchemaVersion: 1, Meaning: 'Clinical Target Volume',
                Color: null, Name: 'CTV Low'
            }]
        },
        OARObjectives: {
            Objective: [{
                StructureId: 'OAR1', Phase: 1, ClinicalGoal: { DVHObjective: 'Max[Gy]', Evaluator: '<=2' },
                AcceptableVariation: { DVHObjective: 'Max[Gy]', Evaluator: '<=4' }, Priority: 1
            }, {
                StructureId: 'OAR1', Phase: 2,
                ClinicalGoal: { DVHObjective: 'D5%[Gy]', Evaluator: '<=1.44' },
                AcceptableVariation: { DVHObjective: 'D5%[Gy]', Evaluator: '<=1.42' }, Priority: 2
            }, {
                StructureId: 'OAR2', Phase: 1, ClinicalGoal: { DVHObjective: 'V16cc[%]', Evaluator: '<=15' },
                AcceptableVariation: { DVHObjective: 'V16cc[%]', Evaluator: '<=11' }, Priority: 3
            }, {
                StructureId: 'OAR2', Phase: 2,
                ClinicalGoal: { DVHObjective: 'V16cc[%]', Evaluator: '<=15' },
                AcceptableVariation: { DVHObjective: 'V16cc[%]', Evaluator: '<=11' }, Priority: 3
            },
            {
                StructureId: 'OAR3', Phase: 2, ClinicalGoal: { DVHObjective: 'Max[cc]', Evaluator: '<=2' }, AcceptableVariation: {
                    DVHObjective: 'Max[cc]', Evaluator: '<=5'
                }, Priority: 4
            }, {
                StructureId: 'OAR4', Phase: 2, ClinicalGoal: { DVHObjective: 'Mean[%]', Evaluator: '<=2' },
                AcceptableVariation: { DVHObjective: 'Mean[%]', Evaluator: '<=3' }, Priority: 5
            }]
        }, PrescribedSessions: {
            Session: [{
                Id: 1, ReferencedPhase: 1, Imaging: 'None'
            }, { Id: 2, ReferencedPhase: 1, Imaging: 'None' }, { Id: 3, ReferencedPhase: 1, Imaging: 'None' }, {
                Id: 4, ReferencedPhase: 1, Imaging: 'None'
            }, { Id: 5, ReferencedPhase: 1, Imaging: 'None' }, { Id: 6, ReferencedPhase: 1, Imaging: 'None' }, {
                Id: 7, ReferencedPhase: 1, Imaging: 'None'
            }, { Id: 8, ReferencedPhase: 1, Imaging: 'None' }, { Id: 9, ReferencedPhase: 1, Imaging: 'None' },
            { Id: 10, ReferencedPhase: 1, Imaging: 'None' }, { Id: 11, ReferencedPhase: 1, Imaging: 'None' }, {
                Id: 12, ReferencedPhase: 1, Imaging: 'None'
            }, { Id: 13, ReferencedPhase: 1, Imaging: 'None' }, { Id: 14, ReferencedPhase: 1, Imaging: 'None' },
            { Id: 15, ReferencedPhase: 1, Imaging: 'None' }, { Id: 16, ReferencedPhase: 2, Imaging: 'None' },
            { Id: 17, ReferencedPhase: 2, Imaging: 'None' }, { Id: 18, ReferencedPhase: 2, Imaging: 'None' },
            { Id: 19, ReferencedPhase: 2, Imaging: 'None' }, { Id: 20, ReferencedPhase: 2, Imaging: 'None' }]
        }, Phases: {
            Phase: [{
                Id: 1, PrescriptionTargets: {
                    PrescriptionTarget: [{
                        StructureId: 'Target1', FractionDoseGy: 4,
                        FractionCount: 15, TotalDose: 60, Objectives: {
                            Objective: [{
                                StructureId: null, Phase: null, ClinicalGoal: {
                                    DVHObjective: 'D5%[Gy]', Evaluator: '<=52'
                                }, AcceptableVariation: { DVHObjective: 'D5%[Gy]', Evaluator: '<=53' }, Priority: 1
                            },
                            {
                                StructureId: null, Phase: null, ClinicalGoal: { DVHObjective: 'Max[%]', Evaluator: '<=105' },
                                AcceptableVariation: { DVHObjective: 'Max[%]', Evaluator: '<=115' }, Priority: 2
                            }]
                        }
                    }, {
                        StructureId: 'Target2', FractionDoseGy: 2,
                        FractionCount: 15, TotalDose: 30, Objectives: {
                            Objective: [{
                                StructureId: null, Phase: null, ClinicalGoal:
                                    { DVHObjective: 'V43%[cc]', Evaluator: '<=50' },
                                AcceptableVariation: { DVHObjective: 'V43%[cc]', Evaluator: '<=45' }, Priority: 1
                            }, {
                                StructureId: null, Phase: null, ClinicalGoal: { DVHObjective: 'Mean[cc]', Evaluator: '<=7' },
                                AcceptableVariation: { DVHObjective: 'Mean[cc]', Evaluator: '<=10' }, Priority: 2
                            }]
                        }
                    }]
                }
            },
            {
                Id: 2, PrescriptionTargets: {
                    PrescriptionTarget: [{
                        StructureId: 'Target1', FractionDoseGy: 8, FractionCount: 5,
                        TotalDose: 40, Objectives: {
                            Objective: [{
                                StructureId: null, Phase: null, ClinicalGoal: {
                                    DVHObjective: 'D3cc[Gy]', Evaluator: '<=54'
                                }, AcceptableVariation: { DVHObjective: 'D3cc[Gy]', Evaluator: '<=52' }, Priority: 1
                            },
                            {
                                StructureId: null, Phase: null, ClinicalGoal: { DVHObjective: 'Mean[Gy]', Evaluator: '<=19' },
                                AcceptableVariation: { DVHObjective: 'Mean[Gy]', Evaluator: '<=10' }, Priority: 2
                            }]
                        }
                    }, {
                        StructureId: 'Target2', FractionDoseGy: 4,
                        FractionCount: 5, TotalDose: 20, Objectives: {
                            Objective: [{
                                StructureId: null, Phase: null, ClinicalGoal:
                                    { DVHObjective: 'V43Gy[cc]', Evaluator: '<=50' }, AcceptableVariation: {
                                        DVHObjective: 'V43Gy[cc]', Evaluator: '<=52'
                                    }, Priority: 1
                            }, {
                                StructureId: null, Phase: null, ClinicalGoal: {
                                    DVHObjective: 'V48Gy[%]', Evaluator: '<=30'
                                }, AcceptableVariation: { DVHObjective: 'V48Gy[%]', Evaluator: '<=28' }, Priority: 2
                            }]
                        }
                    }]
                }
            }]
        },
        Notes: {
            Note: [{ TimeStamp: '30 Jul 2018, 1:31 PM', UpdatedBy: 'RO', Comment: 'Comment Added by Remote Oncologist' },
            { TimeStamp: '30 Jul 2018, 1:31 PM', UpdatedBy: 'RO', Comment: 'Comment Added by Remote Oncologist' }]
        }
    };
    appService.treatmentInstruction.next(treatmentInst);
    // spyOnProperty(appService.treatmentInstruction, 'next').and.returnValue(treatmentInst);

    component.updateTemplateInUI();

    fixture.whenStable().then(() => {
        expect(component.structuresInfo.length).toBe(2);
        expect(component.oarStructureLength).toBe(4);
        expect(component.notesArray.length).toBe(2);
    });
}));

0 个答案:

没有答案