Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ <h5 i18n>Enter a title for the new lesson</h5>
id="title"
name="title"
formControlName="title"
(keyup)="$event.keyCode == 13 && submit()"
required
/>
@if (addLessonFormGroup.controls['title'].hasError('required')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { MockProviders } from 'ng-mocks';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { AddLessonConfigureComponent } from './add-lesson-configure.component';

describe('AddLessonConfigureComponent', () => {
let fixture: ComponentFixture<AddLessonConfigureComponent>;
let projectService: TeacherProjectService;
let titleInput: HTMLInputElement;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AddLessonConfigureComponent],
providers: [MockProviders(TeacherProjectService), provideRouter([])]
}).compileComponents();
window.history.pushState({ target: 'group1' }, '', '');
projectService = TestBed.inject(TeacherProjectService);
spyOn(projectService, 'createGroup').and.returnValue({ id: 'group2' });
spyOn(projectService, 'checkPotentialStartNodeIdChangeThenSaveProject').and.returnValue(
new Promise(() => {})
);
spyOn(HTMLElement.prototype, 'focus');
fixture = TestBed.createComponent(AddLessonConfigureComponent);
fixture.detectChanges();
titleInput = fixture.nativeElement.querySelector('#title');
});

function typeTitle(title: string): void {
titleInput.value = title;
titleInput.dispatchEvent(new Event('input'));
}

function pressEnter(): void {
const init = { key: 'Enter', keyCode: 13, bubbles: true } as KeyboardEventInit;
titleInput.dispatchEvent(new KeyboardEvent('keydown', init));
titleInput.dispatchEvent(new KeyboardEvent('keyup', init));
}

it('should add one lesson when Enter is pressed once', () => {
typeTitle('Lesson');
pressEnter();
expect(projectService.createGroup).toHaveBeenCalledTimes(1);
});

it('should not add another lesson while the first save is still in flight', () => {
typeTitle('Lesson');
pressEnter();
pressEnter();
expect(projectService.createGroup).toHaveBeenCalledTimes(1);
});

it('should not add a lesson when Enter is pressed with an empty title', () => {
pressEnter();
expect(projectService.createGroup).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class AddLessonConfigureComponent {
}

protected submit(): void {
if (this.submitting || this.addLessonFormGroup.invalid) {
return;
}
this.submitting = true;
const newLesson = this.projectService.createGroup(
this.addLessonFormGroup.controls['title'].value
Expand Down
8 changes: 4 additions & 4 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addLesson/add-lesson-configure/add-lesson-configure.component.html</context>
<context context-type="linenumber">31,34</context>
<context context-type="linenumber">30,33</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addNode/add-your-own-node/add-your-own-node.component.html</context>
Expand Down Expand Up @@ -1572,7 +1572,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addLesson/add-lesson-configure/add-lesson-configure.component.html</context>
<context context-type="linenumber">28,31</context>
<context context-type="linenumber">27,30</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addNode/add-your-own-node/add-your-own-node.component.html</context>
Expand Down Expand Up @@ -1655,7 +1655,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addLesson/add-lesson-configure/add-lesson-configure.component.html</context>
<context context-type="linenumber">42,47</context>
<context context-type="linenumber">41,46</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addNode/add-your-own-node/add-your-own-node.component.html</context>
Expand Down Expand Up @@ -10434,7 +10434,7 @@
<source> Lesson Title is required </source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/addLesson/add-lesson-configure/add-lesson-configure.component.html</context>
<context context-type="linenumber">21,25</context>
<context context-type="linenumber">20,24</context>
</context-group>
</trans-unit>
<trans-unit id="896601949204119976" datatype="html">
Expand Down
Loading