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

Implement editing of questions #5614

Merged
merged 46 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d9f2824
Save.
tjiang11 Aug 30, 2018
f0cb957
Save.
tjiang11 Aug 30, 2018
9c8e702
Save. UrlInterpolationError topic null.
tjiang11 Aug 30, 2018
c93f186
Save.
tjiang11 Aug 30, 2018
f695dd6
Modify backend to return associated skills when fetching a question.
tjiang11 Aug 30, 2018
066faec
save.
tjiang11 Aug 30, 2018
07a11fb
Saving content works.
tjiang11 Aug 30, 2018
2386f69
Copy interaction.
tjiang11 Aug 30, 2018
4360648
Apply QuestionUpdateService for all changes.
tjiang11 Aug 30, 2018
a68adef
Circumvent race condition on initialization.
tjiang11 Aug 30, 2018
dd9d25f
Lint.
tjiang11 Aug 30, 2018
8a2c2bd
Clone UndoRedoService for questions.
tjiang11 Aug 30, 2018
4782099
Fetch question summaries after edit question.
tjiang11 Aug 30, 2018
a20b0ab
Create reusable function in QuestionEditorDirective.
tjiang11 Aug 30, 2018
4668f51
Lint.
tjiang11 Aug 30, 2018
fd91189
Add test.
tjiang11 Sep 1, 2018
2f4f1cc
Fix test.
tjiang11 Sep 1, 2018
3050886
Lint.
tjiang11 Sep 1, 2018
6d52d8c
Disable flag.
tjiang11 Sep 1, 2018
43807b1
Review changes.
tjiang11 Sep 3, 2018
7a4ff6f
Review changes.
tjiang11 Sep 9, 2018
41798c6
Review comments.
tjiang11 Sep 13, 2018
c496793
Lint.
tjiang11 Sep 13, 2018
fbdaa83
Review changes.
tjiang11 Sep 23, 2018
732be38
Deduplicate UndoRedoService.
tjiang11 Sep 23, 2018
7756f6d
Move updateFunction into QuestionUpdateService.
tjiang11 Sep 23, 2018
17ca89f
Fix test.
tjiang11 Oct 14, 2018
5785784
Lint.
tjiang11 Oct 14, 2018
13254ea
Update documentation.
tjiang11 Oct 15, 2018
fc4981d
Add tests for get_models_by_question_id
tjiang11 Oct 15, 2018
9ef2940
Update setQuestionStateData.
tjiang11 Oct 15, 2018
5861a5a
Fix test.
tjiang11 Oct 15, 2018
4ccea9c
Fix test.
tjiang11 Oct 15, 2018
0c589eb
Merge develop.
tjiang11 Oct 15, 2018
c0ad966
Lint.
tjiang11 Oct 15, 2018
9896d99
Add test.
tjiang11 Oct 25, 2018
4d3c329
Merge develop.
tjiang11 Oct 28, 2018
d37ab38
Lint.
tjiang11 Oct 28, 2018
f6f7e09
Edit questions in modal.
tjiang11 Oct 28, 2018
5722ca1
Add blank commit message.
tjiang11 Nov 4, 2018
3b5983f
Remove duplicate function; Fix issue with not being able to edit a qu…
tjiang11 Dec 1, 2018
c4c9b93
Merge develop.
tjiang11 Dec 1, 2018
98227d0
Lint.
tjiang11 Dec 1, 2018
5abc2c8
Lint.
tjiang11 Dec 1, 2018
387a9cb
Fix.
tjiang11 Dec 1, 2018
7a10a7b
Flip flag.
tjiang11 Dec 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test.
  • Loading branch information
tjiang11 committed Sep 1, 2018
commit fd911896cb1e612cf55b495d4dbc2c3b8b898c81
35 changes: 35 additions & 0 deletions core/domain/question_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,38 @@ def test_created_question_rights(self):
Exception, 'Entity for class QuestionRightsModel with id '
'question_id not found'):
question_services.get_question_rights('question_id')

def test_get_question_skill_links_of_question(self):
# If the question id doesnt exist at all, it returns an empty list.
question_skill_links = (
question_services.get_question_skill_links_of_question(
'non_existent_question_id'))
self.assertEqual(len(question_skill_links), 0)

question_id_2 = question_services.get_new_question_id()
self.save_new_question(
question_id_2, self.editor_id,
self._create_valid_question_data('ABC'))

question_id_3 = question_services.get_new_question_id()
self.save_new_question(
question_id_3, self.editor_id,
self._create_valid_question_data('ABC'))
question_services.create_new_question_skill_link(
self.question_id, 'skill_1')
question_services.create_new_question_skill_link(
question_id_2, 'skill_1')
question_services.create_new_question_skill_link(
question_id_2, 'skill_2')
question_services.create_new_question_skill_link(
question_id_3, 'skill_2')

question_skill_links = (
question_services.get_question_skill_links_of_question(
question_id_2))

self.assertEqual(len(question_skill_links), 2)
skill_ids = [question_skill.skill_id for question_skill
in question_skill_links]
self.assertItemsEqual(
update_skill_ids_of_questions, ['skill_1', 'skill_2'])
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe('Editable question backend API service', function() {
},
language_code: 'en',
version: 1
}
},
associated_skill_dicts: []
};
}));

Expand All @@ -95,7 +96,7 @@ describe('Editable question backend API service', function() {
$httpBackend.flush();

expect(successHandler).toHaveBeenCalledWith(
sampleDataResults.question_dict);
sampleDataResults);
expect(failHandler).not.toHaveBeenCalled();
}
);
Expand Down Expand Up @@ -126,11 +127,10 @@ describe('Editable question backend API service', function() {
sampleDataResults);

EditableQuestionBackendApiService.fetchQuestion('0').then(
function(questionDict) {
question = questionDict;
function(data) {
question = data.question_dict;
});
$httpBackend.flush();

question.question_state_data.content.html = 'New Question Content';
question.version = '2';
var questionWrapper = {
Expand Down
115 changes: 115 additions & 0 deletions core/templates/dev/head/domain/question/QuestionUpdateServiceSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2018 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 question update service.
*/

describe('Question update service', function() {
var QuestionUpdateService = null;
var QuestionObjectFactory = null;
var QuestionUndoRedoService = null;
var StateObjectFactory = null;
var sampleQuestion = null;
var sampleStateTwo = null;

beforeEach(module('oppia'));

beforeEach(inject(function($injector) {
QuestionUpdateService = $injector.get('QuestionUpdateService');
QuestionObjectFactory = $injector.get('QuestionObjectFactory');
QuestionUndoRedoService = $injector.get('QuestionUndoRedoService');
StateObjectFactory = $injector.get('StateObjectFactory');

var sampleStateDict = {
name: 'question',
classifier_model_id: 0,
content: '<p>Hello World</p>',
param_changes: [],
interaction: {
answer_groups: [{
rule_specs: [{rule_type: 'Contains', inputs: {x: 'hola'}}],
outcome: {
dest: 'Me Llamo',
feedback: {html: 'buen trabajo!'},
labelled_as_correct: true
}
}],
default_outcome: {
dest: 'Hola',
feedback: {html: 'try again!'},
labelled_as_correct: false
},
hints: [],
id: 'TextInput',
},
content_ids_to_audio_translations: {}
};

var sampleStateDictTwo = {
name: 'question',
classifier_model_id: 0,
content: '<p>Hello World!!!</p>',
param_changes: [],
interaction: {
answer_groups: [{
rule_specs: [{rule_type: 'Contains', inputs: {x: 'hola'}}],
outcome: {
dest: 'My name is...',
feedback: {html: 'good job!'},
labelled_as_correct: true
}
}],
default_outcome: {
dest: 'Hello',
feedback: {html: 'try again!'},
labelled_as_correct: false
},
hints: [],
id: 'TextInput',
},
content_ids_to_audio_translations: {}
};

sampleStateTwo = StateObjectFactory.createFromBackendDict(
'question', sampleStateDictTwo);

var sampleQuestionBackendObject = {
id: '0',
question_state_data: sampleStateDict,
language_code: 'en',
version: 1
};
sampleQuestion = QuestionObjectFactory.createFromBackendDict(
sampleQuestionBackendObject);
}));

it('should update the language code of the question', function() {
expect(sampleQuestion.getLanguageCode()).toEqual('en');
QuestionUpdateService.setQuestionLanguageCode(sampleQuestion, 'zh');
expect(sampleQuestion.getLanguageCode()).toEqual('zh');
QuestionUndoRedoService.undoChange(sampleQuestion);
expect(sampleQuestion.getLanguageCode()).toEqual('en');
});

it('should update the state data of the question', function() {
var oldStateData = angular.copy(sampleQuestion.getStateData());
var newStateData = angular.copy(sampleStateTwo);
QuestionUpdateService.setQuestionStateData(
sampleQuestion, oldStateData, newStateData);
expect(sampleQuestion.getStateData()).toEqual(newStateData);
QuestionUndoRedoService.undoChange(sampleQuestion);
expect(sampleQuestion.getStateData()).toEqual(oldStateData);
});
});