/
githubmirror
/
oppia
Обзор
Документация
Войти
/
githubmirror
/
oppia
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
extensions/interactions/InteractiveMap/directives/interactive-map-validation.service.spec.ts
196 строк
6 KB
Vaibhav Tripathi
Fix #9311 - Use TestBed.inject instead of TestBed.get (#24729)
10 фев 2026, 02:44
Не верифицирован
10 фев 2026, 02:44
015e3c8
Код
Авторство
О чём код?
// Copyright 2014 The Oppia Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS-IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * @fileoverview Unit tests for interactive map validation service. */ import {TestBed} from '@angular/core/testing'; import {AnswerGroup} from 'domain/exploration/answer-group.model'; import {InteractiveMapValidationService} from 'interactions/InteractiveMap/directives/interactive-map-validation.service'; import {Outcome} from 'domain/exploration/outcome.model'; import {Rule} from 'domain/exploration/rule.model'; import {AppConstants} from 'app.constants'; import {InteractiveMapCustomizationArgs} from 'interactions/customization-args-defs'; describe('InteractiveMapValidationService', () => { let validatorService: InteractiveMapValidationService; let WARNING_TYPES: typeof AppConstants.WARNING_TYPES; let currentState: string; let goodAnswerGroups: AnswerGroup[], goodDefaultOutcome: Outcome; let customizationArguments: InteractiveMapCustomizationArgs; beforeEach(() => { TestBed.configureTestingModule({ providers: [InteractiveMapValidationService], }); validatorService = TestBed.inject(InteractiveMapValidationService); WARNING_TYPES = AppConstants.WARNING_TYPES; currentState = 'First State'; goodDefaultOutcome = Outcome.createFromBackendDict({ dest: 'Second State', dest_if_really_stuck: null, feedback: { html: '', content_id: '', }, labelled_as_correct: false, param_changes: [], refresher_exploration_id: null, missing_prerequisite_skill_id: null, }); customizationArguments = { latitude: { value: 0, }, longitude: { value: 0, }, zoom: { value: 0, }, }; goodAnswerGroups = [ AnswerGroup.createNew( [ Rule.createFromBackendDict( { rule_type: 'Within', inputs: { d: 100, }, }, 'InteractiveMap' ), Rule.createFromBackendDict( { rule_type: 'NotWithin', inputs: { d: 50, }, }, 'InteractiveMap' ), ], goodDefaultOutcome, [], null ), ]; }); it('should be able to perform basic validation', () => { var warnings = validatorService.getAllWarnings( currentState, customizationArguments, goodAnswerGroups, goodDefaultOutcome ); expect(warnings).toEqual([]); }); it('should expect latitude and longitude customization arguments', () => { expect(() => { validatorService.getAllWarnings( currentState, // This throws "Argument of type '{}'. We need to suppress this error // because .. oppia/comment-style is not assignable to // parameter of type 'InteractiveMapCustomizationArgs'." We are // purposely assigning the wrong type of customization args in // order to test validations. // @ts-expect-error {}, goodAnswerGroups, goodDefaultOutcome ); }).toThrowError( 'Expected customization arguments to have properties: ' + 'latitude, longitude' ); }); it( 'should expect latitudes and longitudes within [-90, 90] and ' + '[-180, 180], respectively', () => { customizationArguments.latitude.value = -120; customizationArguments.longitude.value = 200; var warnings = validatorService.getAllWarnings( currentState, customizationArguments, goodAnswerGroups, goodDefaultOutcome ); expect(warnings).toEqual([ { type: WARNING_TYPES.CRITICAL, message: 'Please pick a starting latitude between -90 and 90.', }, { type: WARNING_TYPES.CRITICAL, message: 'Please pick a starting longitude between -180 and 180.', }, ]); customizationArguments.latitude.value = 120; customizationArguments.longitude.value = -200; warnings = validatorService.getAllWarnings( currentState, customizationArguments, goodAnswerGroups, goodDefaultOutcome ); expect(warnings).toEqual([ { type: WARNING_TYPES.CRITICAL, message: 'Please pick a starting latitude between -90 and 90.', }, { type: WARNING_TYPES.CRITICAL, message: 'Please pick a starting longitude between -180 and 180.', }, ]); } ); it('should expect all rule types to refer to positive distances', () => { goodAnswerGroups[0].rules[0].inputs.d = -90; goodAnswerGroups[0].rules[1].inputs.d = -180; var warnings = validatorService.getAllWarnings( currentState, customizationArguments, goodAnswerGroups, goodDefaultOutcome ); expect(warnings).toEqual([ { type: WARNING_TYPES.CRITICAL, message: 'Please ensure that learner answer 1 in Oppia response 1 refers ' + 'to a valid distance.', }, { type: WARNING_TYPES.CRITICAL, message: 'Please ensure that learner answer 2 in Oppia response 1 refers ' + 'to a valid distance.', }, ]); }); });