Skip to content

Commit 03b8db5

Browse files
authored
Fix oppia#19545: Exploration editor category creating new categories when selecting old ones. (oppia#19549)
* Fix Exploration Editor Category Select * Change to Value Change
1 parent d9972cc commit 03b8db5

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

core/templates/pages/exploration-editor-page/settings-tab/settings-tab.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ <h3 class="e2e-test-settings-container" tabindex="0">Basic Settings</h3>
3636
<p>
3737
<mat-form-field class="e2e-test-exploration-category" appearance="fill">
3838
<mat-label for="explorationCategory" class="d-block">Add a category (Choose or type new)</mat-label>
39-
<mat-select [(value)]="explorationCategoryService.displayed" class="e2e-test-exploration-category-dropdown">
39+
<mat-select [(value)]="explorationCategoryService.displayed"
40+
(valueChange)="updateCategoryListWithUserData()"
41+
class="e2e-test-exploration-category-dropdown">
4042
<mat-option class="e2e-test-exploration-new-category-add">
4143
<ngx-mat-select-search ngModel
4244
(ngModelChange)="filterChoices($event)"
43-
(keydown.enter)="updateCategoryListWithUserData()"
4445
placeholderLabel="Type new category here...">
4546
</ngx-mat-select-search>
4647
</mat-option>
47-
<mat-option (click)="updateCategoryListWithUserData()"
48-
*ngFor="let option of filteredChoices"
48+
<mat-option *ngFor="let option of filteredChoices"
4949
class="e2e-test-exploration-category-selector-choice"
5050
[value]="option.id">
5151
{{ option.text }}

core/templates/pages/exploration-editor-page/settings-tab/settings-tab.component.spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,40 @@ describe('Settings Tab Component', () => {
297297
flush();
298298
}));
299299

300+
it('should not create new category if it is not selected',
301+
fakeAsync(() => {
302+
spyOn(explorationCategoryService, 'saveDisplayedValue').and.stub();
303+
304+
explorationCategoryService.displayed = 'old';
305+
component.newCategory = {
306+
id: 'new',
307+
text: 'new'
308+
};
309+
310+
component.updateCategoryListWithUserData();
311+
tick();
312+
313+
expect(explorationCategoryService.displayed).toBe('old');
314+
expect(explorationCategoryService.saveDisplayedValue).toHaveBeenCalled();
315+
}));
316+
317+
it('should be able to create new category if it is selected',
318+
fakeAsync(() => {
319+
spyOn(explorationCategoryService, 'saveDisplayedValue').and.stub();
320+
321+
explorationCategoryService.displayed = 'new';
322+
component.newCategory = {
323+
id: 'new',
324+
text: 'new'
325+
};
326+
327+
component.updateCategoryListWithUserData();
328+
tick();
329+
330+
expect(explorationCategoryService.displayed).toBe('new');
331+
expect(explorationCategoryService.saveDisplayedValue).toHaveBeenCalled();
332+
}));
333+
300334
it('should be able to add exploration editor tags',
301335
fakeAsync(() => {
302336
spyOn(component, 'saveExplorationTags').and.stub();

core/templates/pages/exploration-editor-page/settings-tab/settings-tab.component.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ export class SettingsTabComponent
218218
}
219219

220220
updateCategoryListWithUserData(): void {
221-
if (this.newCategory) {
221+
if (this.newCategory &&
222+
(this.explorationCategoryService.displayed === this.newCategory.id)
223+
) {
222224
this.CATEGORY_LIST_FOR_SELECT2.push(this.newCategory);
223225
this.explorationCategoryService.displayed = this.newCategory.id;
224226
}

0 commit comments

Comments
 (0)