Skip to content

Commit

Permalink
Frontend Unit Tests(6): Cover multiple component files (oppia#13476)
Browse files Browse the repository at this point in the history
* drag-and-drop-sort & item-selection

* number-with-units

* other tests

* other tests

* minor fixes

* minor fixes

* backend test fix

* addressed comments

* addressed comments
  • Loading branch information
gp201 authored Jul 29, 2021
1 parent 9991fab commit 35bdbe6
Show file tree
Hide file tree
Showing 55 changed files with 3,838 additions and 647 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<!--This CSS class is essential for auto-scrolling in Drag and drop interaction to work
correctly. More details about the class can be found in extensions/interactions/
DragAndDropSortInput/directives/drag-and-drop-sort-input-interaction.directive.html-->
DragAndDropSortInput/directives/drag-and-drop-sort-input-interaction.component.html-->
<div class="conversation-skin-interaction-container">
<angular-html-bind class="protractor-test-conversation-input"
html-data="displayedCard.getInteractionHtml()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ require(
'drag-and-drop-sort-input-validation.service.ts');
require(
'interactions/DragAndDropSortInput/directives/' +
'oppia-interactive-drag-and-drop-sort-input.directive.ts');
'oppia-interactive-drag-and-drop-sort-input.component.ts');
require(
'interactions/DragAndDropSortInput/directives/' +
'oppia-response-drag-and-drop-sort-input.directive.ts');
'oppia-response-drag-and-drop-sort-input.component.ts');
require(
'interactions/DragAndDropSortInput/directives/' +
'oppia-short-response-drag-and-drop-sort-input.directive.ts');
'oppia-short-response-drag-and-drop-sort-input.component.ts');
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li ng-repeat="responses in $ctrl.answer">
<ul ng-model="responses">
<li ng-repeat="response in responses track by $index">
<div ng-if="$ctrl.chooseItemType($index)" ng-class="itemtype">
<div ng-class="$ctrl.chooseItemType($index)">
<angular-html-bind html-data="response"></angular-html-bind>
</div>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li ng-repeat="responses in $ctrl.answer">
<ul ng-model="responses">
<li ng-repeat="response in responses track by $index">
<div ng-if="$ctrl.chooseItemType($index)" ng-class="itemtype">
<div ng-class="$ctrl.chooseItemType($index)">
<angular-html-bind html-data="response"></angular-html-bind>
</div>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
// Copyright 2021 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 the DragAndDropSortInput interaction.
*/

require(
'interactions/DragAndDropSortInput/directives/' +
'oppia-interactive-drag-and-drop-sort-input.component.ts');

describe('oppiaInteractiveDragAndDropSortInput', () => {
let ctrl = null;

let mockCurrentInteractionService = {
onSubmit: function(answer, rulesService) {},
registerCurrentInteraction: function(submitAnswerFn, isAnswerValid) {
submitAnswerFn();
}
};
let mockDragAndDropSortInputRulesService = {};
let mockInteractionAttributesExtractorService = {
getValuesFromAttributes: function(interactionId, attrs) {
return attrs;
}
};

beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value(
'CurrentInteractionService', mockCurrentInteractionService);
$provide.value(
'DragAndDropSortInputRulesService',
mockDragAndDropSortInputRulesService);
$provide.value(
'InteractionAttributesExtractorService',
mockInteractionAttributesExtractorService);
}));

describe('when multiple items in the same position are allowed', () => {
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('$attrs', {
choices: [
{
html: '<p>choice 1</p>',
contentId: 'ca_choices_1'
},
{
html: '<p>choice 2</p>',
contentId: 'ca_choices_2'
},
{
html: '<p>choice 3</p>',
contentId: 'ca_choices_3'
},
{
html: '<p>choice 4</p>',
contentId: 'ca_choices_4'
}
],
allowMultipleItemsInSamePosition: true
});
}));

beforeEach(angular.mock.inject(function($injector, $componentController) {
ctrl = $componentController('oppiaInteractiveDragAndDropSortInput');

ctrl.savedSolution = [
[
'ca_choices_1'
],
[
'ca_choices_2',
'ca_choices_3'
],
[
'ca_choices_4'
]
];
}));

it('should initialise component when user adds interaction', () => {
ctrl.$onInit();

expect(ctrl.dataMaxDepth).toBe(2);
expect(ctrl.allowMultipleItemsInSamePosition).toBe(true);
expect(ctrl.list).toEqual([{
title: '<p>choice 1</p>',
items: []
},
{
title: '<p>choice 2</p>',
items: [
{title: '<p>choice 3</p>', items: []}
]
},
{
title: '<p>choice 4</p>',
items: []
}]);
expect(ctrl.choices).toEqual([
'<p>choice 1</p>',
'<p>choice 2</p>',
'<p>choice 3</p>',
'<p>choice 4</p>'
]);
});

it('should make a default list of dicts when user did not save a solution',
() => {
ctrl.savedSolution = undefined;
ctrl.$onInit();

expect(ctrl.dataMaxDepth).toBe(2);
expect(ctrl.allowMultipleItemsInSamePosition).toBe(true);
expect(ctrl.list).toEqual([{
title: '<p>choice 1</p>',
items: []
},
{
title: '<p>choice 2</p>',
items: []
},
{
title: '<p>choice 3</p>',
items: []},
{
title: '<p>choice 4</p>',
items: []
}]);
expect(ctrl.choices).toEqual([
'<p>choice 1</p>',
'<p>choice 2</p>',
'<p>choice 3</p>',
'<p>choice 4</p>'
]);
});

it('should show black dashed box when user drags item', () => {
let e = {
dest: {
nodesScope: {
$childNodesScope: undefined
}
},
elements: {
placeholder: [
{
style: {
borderColor: null
}
}
]
}
};
ctrl.$onInit();

ctrl.treeOptions.dragMove(e);

expect(e.elements.placeholder[0].style.borderColor).toBe('#000000');
});

it('should show blue dashed box when user selects item', () => {
let e = {
dest: {
nodesScope: {
$childNodesScope: {}
}
},
elements: {
placeholder: [
{
style: {
borderColor: null
}
}
]
}
};
ctrl.$onInit();

ctrl.treeOptions.dragMove(e);

expect(e.elements.placeholder[0].style.borderColor).toBe('#add8e6');
});
});

describe('when multiple items in the same position are not allowed', () => {
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('$attrs', {
choices: [
{
html: '<p>choice 1</p>',
contentId: 'ca_choices_1'
},
{
html: '<p>choice 2</p>',
contentId: 'ca_choices_2'
},
{
html: '<p>choice 3</p>',
contentId: 'ca_choices_3'
}
],
allowMultipleItemsInSamePosition: false
});
}));

beforeEach(angular.mock.inject(function($injector, $componentController) {
ctrl = $componentController('oppiaInteractiveDragAndDropSortInput');

ctrl.savedSolution = [
[
'ca_choices_1'
],
[
'ca_choices_2'
],
[
'ca_choices_3'
]
];
}));

it('should initialise component when user adds interaction', () => {
ctrl.$onInit();

expect(ctrl.dataMaxDepth).toBe(1);
expect(ctrl.allowMultipleItemsInSamePosition).toBe(false);
expect(ctrl.list).toEqual([{
title: '<p>choice 1</p>',
items: []
},
{
title: '<p>choice 2</p>',
items: []
},
{
title: '<p>choice 3</p>',
items: []
}]);
expect(ctrl.choices).toEqual([
'<p>choice 1</p>',
'<p>choice 2</p>',
'<p>choice 3</p>'
]);
});
});
});
Loading

0 comments on commit 35bdbe6

Please sign in to comment.