Skip to content

Commit

Permalink
Upgrade more services to Angular 8 (oppia#7145)
Browse files Browse the repository at this point in the history
* Untested work on PlaythroughIssueObjectFactory.ts

* Revert "Untested work on PlaythroughIssueObjectFactory.ts"

This reverts commit 13424bf.

* TopicRightsObjectFactory

* Lint fix

* Removed unnecessary constructor statement

* ClassifierObjectFactory

* AnswerClassificationResultObjectFactory

* PredictionResultObjectFactory

* WrittenTranslationObjectFactory

* RuleObjectFactory

* AudioTranslationObjectFactory

* ExplorationDraftObjectFactory

* Fix failing FE in TopicRightsObjectFactory

* Add force bootstrap to all pages

* function() -> () =>

* Merge proper

* Update mocking method

* More typing

* Audit and newline

* Stronger typing

* Fix FE

* Address comments

* Remove newlines, TODO for imports, modify MockOutcome

* Fix matcher case, modify TODO for imports

* Stronger typing in RuleObjectFactory

* Fix e2e

* Fix AJAX errors in Karma

* Fix FE

* Add comment in csrftoken
  • Loading branch information
YashJipkate authored and seanlip committed Jul 19, 2019
1 parent 0350f08 commit f88216a
Show file tree
Hide file tree
Showing 69 changed files with 1,061 additions and 327 deletions.
13 changes: 13 additions & 0 deletions core/templates/dev/head/AppSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@
* @fileoverview Unit tests for generic services.
*/

// TODO(YashJipkate) Remove the following block of unnnecessary imports once
// App.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.

describe('Constants Generating', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
$provide.value('RuleObjectFactory', new RuleObjectFactory());
}));

var $injector = null;
beforeEach(angular.mock.inject(function(_$injector_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
* @fileoverview Unit tests for the question player state service.
*/

// TODO(YashJipkate) Remove the following block of unnnecessary imports once
// question-player-state.service.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.

require(
'components/question-directives/question-player/services/' +
'question-player-state.service.ts');
Expand All @@ -28,7 +35,12 @@ describe('Question player state service', function() {
var question;

beforeEach(angular.mock.module('oppia'));

beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('RuleObjectFactory', new RuleObjectFactory());
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
}));
beforeEach(angular.mock.inject(function($injector) {
qpservice = $injector.get('QuestionPlayerStateService');
QuestionObjectFactory = $injector.get('QuestionObjectFactory');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
* editor page.
*/

// TODO(YashJipkate) Remove the following block of unnnecessary imports once
// state-property.service.ts is upgraded to Angular 8.
import { ExplorationDraftObjectFactory } from
'domain/exploration/ExplorationDraftObjectFactory.ts';
// ^^^ This block is to be removed.

require('pages/exploration-editor-page/services/change-list.service.ts');
require('pages/exploration-editor-page/services/exploration-title.service.ts');

describe('Change list service', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value(
'ExplorationDraftObjectFactory', new ExplorationDraftObjectFactory());
}));

describe('change list service', function() {
var cls = null;
Expand Down Expand Up @@ -205,6 +215,10 @@ describe('Change list service', function() {

describe('Exploration title service', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value(
'ExplorationDraftObjectFactory', new ExplorationDraftObjectFactory());
}));

describe('exploration title service', function() {
var ets = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
* @fileoverview Unit tests for the controller of 'State Interactions'.
*/

// TODO(YashJipkate) Remove the following block of unnnecessary imports once
// state-interaction-editor.directive.ts is upgraded to Angular 8.
import { ExplorationFeaturesService } from
'services/ExplorationFeaturesService.ts';
// ^^^ This block is to be removed.

require(
'pages/exploration-editor-page/editor-tab/' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,39 @@
* Classification Result domain objects.
*/

var oppia = require('AppInit.ts').module;
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

export class AnswerClassificationResult {
outcome: any;
answerGroupIndex: number;
ruleIndex: number;
classificationCategorization: string;

oppia.factory('AnswerClassificationResultObjectFactory', [function() {
var AnswerClassificationResult = function(
outcome, answerGroupIndex, ruleIndex, classificationCategorization) {
constructor(
outcome: any, answerGroupIndex: number, ruleIndex: number,
classificationCategorization: string) {
this.outcome = outcome;
this.answerGroupIndex = answerGroupIndex;
this.ruleIndex = ruleIndex;
this.classificationCategorization = classificationCategorization;
};
}
}

// TODO (ankita240796) Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
AnswerClassificationResult['createNew'] = function(
/* eslint-enable dot-notation */
outcome, answerGroupIndex, ruleIndex, classificationCategorization) {
@Injectable({
providedIn: 'root'
})
export class AnswerClassificationResultObjectFactory {
createNew(
outcome: any, answerGroupIndex: number, ruleIndex: number,
classificationCategorization: string) {
return new AnswerClassificationResult(
outcome, answerGroupIndex, ruleIndex, classificationCategorization);
};
return AnswerClassificationResult;
}]);
}
}

var oppia = require('AppInit.ts').module;

oppia.factory(
'AnswerClassificationResultObjectFactory',
downgradeInjectable(AnswerClassificationResultObjectFactory));
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,74 @@
* @fileoverview Unit tests for the AnswerClassificationResultObjectFactory.
*/

require('domain/classifier/AnswerClassificationResultObjectFactory.ts');
import { AnswerClassificationResultObjectFactory } from
'domain/classifier/AnswerClassificationResultObjectFactory.ts';

require('domain/exploration/OutcomeObjectFactory.ts');
require(
'pages/exploration-player-page/services/answer-classification.service.ts');

describe('Answer classification result object factory', function() {
var oof, acrof;
var DEFAULT_OUTCOME_CLASSIFICATION;
class MockSubtitledHtml {
_html: string;
_contentId: string;
constructor(html: string, contentId: string) {
this._html = html;
this._contentId = contentId;
}
}

class MockOutcome {
dest: string;
feedback: MockSubtitledHtml;
labelledAsCorrect: boolean;
paramChanges: any;
refresherExplorationId: any;
missingPrerequisiteSkillId: any;
constructor(
dest: string, feedback: MockSubtitledHtml, labelledAsCorrect: boolean,
paramChanges: any, refresherExplorationId: any,
missingPrerequisiteSkillId: any) {
this.dest = dest;
this.feedback = feedback;
this.labelledAsCorrect = labelledAsCorrect;
this.paramChanges = paramChanges;
this.refresherExplorationId = refresherExplorationId;
this.missingPrerequisiteSkillId = missingPrerequisiteSkillId;
}
}

beforeEach(angular.mock.module('oppia'));
class MockOutcomeObjectFactory {
createNew(
dest: string, feedbackTextId: string, feedbackText: string,
paramChanges: any) {
return new MockOutcome(
dest,
new MockSubtitledHtml(feedbackText, feedbackTextId),
false,
paramChanges,
null,
null);
}
}

beforeEach(angular.mock.inject(function($injector) {
acrof = $injector.get('AnswerClassificationResultObjectFactory');
oof = $injector.get('OutcomeObjectFactory');
DEFAULT_OUTCOME_CLASSIFICATION = $injector.get(
'DEFAULT_OUTCOME_CLASSIFICATION');
}));
describe('Answer classification result object factory', () => {
let acrof: AnswerClassificationResultObjectFactory;
let oof: MockOutcomeObjectFactory;
let DEFAULT_OUTCOME_CLASSIFICATION: string;

beforeEach(() => {
acrof = new AnswerClassificationResultObjectFactory();
oof = new MockOutcomeObjectFactory();
DEFAULT_OUTCOME_CLASSIFICATION = 'default_outcome';
});

it('should create a new result', function() {
it('should create a new result', () => {
var answerClassificationResult = acrof.createNew(
oof.createNew('default', '', []), 1, 0, DEFAULT_OUTCOME_CLASSIFICATION
oof.createNew('default', '', '', []), 1, 0, DEFAULT_OUTCOME_CLASSIFICATION
);

expect(answerClassificationResult.outcome).toEqual(
oof.createNew('default', '', []));
oof.createNew('default', '', '', []));
expect(answerClassificationResult.answerGroupIndex).toEqual(1);
expect(answerClassificationResult.ruleIndex).toEqual(0);
expect(answerClassificationResult.classificationCategorization).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,33 @@
* domain objects.
*/

var oppia = require('AppInit.ts').module;
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

export class Classifier {
algorithmId: string;
classifierData: any;
dataSchemaVersion: number;

oppia.factory('ClassifierObjectFactory', [function() {
var Classifier = function(algorithmId, classifierData, dataSchemaVersion) {
constructor(
algorithmId: string, classifierData: any, dataSchemaVersion: number) {
this.algorithmId = algorithmId;
this.classifierData = classifierData;
this.dataSchemaVersion = dataSchemaVersion;
};
}
}

// TODO (ankita240796) Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
Classifier['create'] = function(
/* eslint-enable dot-notation */
algorithmId, classifierData, dataSchemaVersion) {
@Injectable({
providedIn: 'root'
})
export class ClassifierObjectFactory {
create(algorithmId: string, classifierData: any, dataSchemaVersion: number) {
return new Classifier(algorithmId, classifierData, dataSchemaVersion);
};
}
}

var oppia = require('AppInit.ts').module;

return Classifier;
}]);
oppia.factory(
'ClassifierObjectFactory',
downgradeInjectable(ClassifierObjectFactory));
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
* @fileoverview Unit tests for the ClassifierObjectFactory.
*/

require('domain/classifier/ClassifierObjectFactory.ts');
import { ClassifierObjectFactory } from
'domain/classifier/ClassifierObjectFactory.ts';

describe('Classifier Object Factory', function() {
var ClassifierObjectFactory;
describe('Classifier Object Factory', () => {
let classifierObjectFactory: ClassifierObjectFactory;

beforeEach(angular.mock.module('oppia'));

beforeEach(angular.mock.inject(function($injector) {
ClassifierObjectFactory = $injector.get('ClassifierObjectFactory');
}));
beforeEach(() => {
classifierObjectFactory = new ClassifierObjectFactory();
});

it('should create a new classifier', function() {
it('should create a new classifier', () => {
var classifierObject = (
ClassifierObjectFactory.create('TestClassifier', {}, 1));
classifierObjectFactory.create('TestClassifier', {}, 1));

expect(classifierObject.algorithmId).toEqual('TestClassifier');
expect(classifierObject.classifierData).toEqual({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* result domain objects.
*/

var oppia = require('AppInit.ts').module;
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

oppia.factory('PredictionResultObjectFactory', [function() {
export class PredictionResult {
/**
* Stores the prediction result for an answer as returned by the
* various prediction services used in Oppia for Machine Learning based
Expand All @@ -31,31 +32,31 @@ oppia.factory('PredictionResultObjectFactory', [function() {
* its prediction label. The value is probability (between 0 and 1) that
* answer belongs to predicted answer group.
*/
var predictionResult = function(label, confidence) {
predictionLabel: number;
predictionConfidence: number;
constructor(label: number, confidence: number) {
this.predictionLabel = label;
this.predictionConfidence = confidence;
};

// TODO (ankita240796) Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
predictionResult['createNew'] = function(label, confidence) {
/* eslint-enable dot-notation */
return new predictionResult(label, confidence);
};
}
}

// TODO (ankita240796) Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
predictionResult['getLabel'] = function() {
/* eslint-enable dot-notation */
@Injectable({
providedIn: 'root'
})
export class PredictionResultObjectFactory extends PredictionResult {
createNew(label: number, confidence: number) {
return new PredictionResult(label, confidence);
}
getLabel() {
return this.predictionLabel;
};

// TODO (ankita240796) Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
predictionResult['getConfidence'] = function() {
/* eslint-enable dot-notation */
}
getConfidence() {
return this.predictionConfidence;
};
}
}

var oppia = require('AppInit.ts').module;

return predictionResult;
}]);
oppia.factory(
'PredictionResultObjectFactory',
downgradeInjectable(PredictionResultObjectFactory));
Loading

0 comments on commit f88216a

Please sign in to comment.