-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AddStepButton): New add step button menu option behavior (#1997)
- Loading branch information
1 parent
c303da8
commit badf97b
Showing
7 changed files
with
147 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 111 additions & 18 deletions
129
src/assets/wise5/authoringTool/add-step-button/add-step-button.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,129 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AddStepButtonComponent } from './add-step-button.component'; | ||
import { TeacherProjectService } from '../../services/teacherProjectService'; | ||
import { StudentTeacherCommonServicesModule } from '../../../../app/student-teacher-common-services.module'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { provideRouter } from '@angular/router'; | ||
|
||
let teacherProjectService: TeacherProjectService; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { MatButtonHarness } from '@angular/material/button/testing'; | ||
import { MatMenuHarness } from '@angular/material/menu/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { AddStepTarget } from '../../../../app/domain/addStepTarget'; | ||
|
||
describe('AddStepButtonComponent', () => { | ||
let component: AddStepButtonComponent; | ||
let fixture: ComponentFixture<AddStepButtonComponent>; | ||
let loader: HarnessLoader; | ||
let projectServiceSpy: jasmine.SpyObj<TeacherProjectService>; | ||
let routerSpy: jasmine.SpyObj<Router>; | ||
let route: ActivatedRoute; | ||
|
||
beforeEach(async () => { | ||
projectServiceSpy = jasmine.createSpyObj('TeacherProjectService', [ | ||
'isFirstStepInLesson', | ||
'isBranchPoint', | ||
'isNodeInAnyBranchPath', | ||
'getParentGroupId', | ||
'getNodesByToNodeId', | ||
'isFirstNodeInBranchPath' | ||
]); | ||
routerSpy = jasmine.createSpyObj('Router', ['navigate']); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [AddStepButtonComponent, MatIconModule, StudentTeacherCommonServicesModule], | ||
await TestBed.configureTestingModule({ | ||
imports: [AddStepButtonComponent, NoopAnimationsModule], | ||
providers: [ | ||
TeacherProjectService, | ||
provideHttpClient(withInterceptorsFromDi()), | ||
provideHttpClientTesting(), | ||
provideRouter([]) | ||
{ provide: TeacherProjectService, useValue: projectServiceSpy }, | ||
{ provide: Router, useValue: routerSpy }, | ||
{ provide: ActivatedRoute, useValue: {} } | ||
] | ||
}); | ||
teacherProjectService = TestBed.inject(TeacherProjectService); | ||
spyOn(teacherProjectService, 'isBranchMergePoint').and.returnValue(false); | ||
}).compileComponents(); | ||
|
||
route = TestBed.inject(ActivatedRoute); | ||
fixture = TestBed.createComponent(AddStepButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
component.nodeId = 'node1'; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should disable button when no actions are available', async () => { | ||
projectServiceSpy.isFirstStepInLesson.and.returnValue(false); | ||
projectServiceSpy.isBranchPoint.and.returnValue(true); | ||
projectServiceSpy.isNodeInAnyBranchPath.and.returnValue(true); | ||
fixture.detectChanges(); | ||
|
||
const button = await loader.getHarness(MatButtonHarness); | ||
expect(await button.isDisabled()).toBeTruthy(); | ||
}); | ||
|
||
it('should show all menu items when all actions are available', async () => { | ||
projectServiceSpy.isFirstStepInLesson.and.returnValue(true); | ||
projectServiceSpy.isBranchPoint.and.returnValue(false); | ||
projectServiceSpy.isNodeInAnyBranchPath.and.returnValue(false); | ||
fixture.detectChanges(); | ||
|
||
const button = await loader.getHarness(MatButtonHarness); | ||
await button.click(); | ||
|
||
const menu = await loader.getHarness(MatMenuHarness); | ||
const items = await menu.getItems(); | ||
expect(items.length).toBe(3); | ||
}); | ||
|
||
it('should navigate to add step before view when first in lesson', async () => { | ||
projectServiceSpy.isFirstStepInLesson.and.returnValue(true); | ||
projectServiceSpy.getParentGroupId.and.returnValue('group1'); | ||
fixture.detectChanges(); | ||
|
||
const button = await loader.getHarness(MatButtonHarness); | ||
await button.click(); | ||
const menu = await loader.getHarness(MatMenuHarness); | ||
const items = await menu.getItems(); | ||
expect(items.length).toBe(3); | ||
await items[0].click(); | ||
|
||
expect(routerSpy.navigate).toHaveBeenCalledWith(['add-node', 'choose-template'], { | ||
relativeTo: route, | ||
state: jasmine.any(AddStepTarget) | ||
}); | ||
}); | ||
|
||
it('should navigate to add step after view', async () => { | ||
projectServiceSpy.isFirstStepInLesson.and.returnValue(false); | ||
projectServiceSpy.isBranchPoint.and.returnValue(false); | ||
fixture.detectChanges(); | ||
|
||
const button = await loader.getHarness(MatButtonHarness); | ||
await button.click(); | ||
const menu = await loader.getHarness(MatMenuHarness); | ||
const items = await menu.getItems(); | ||
expect(items.length).toBe(2); | ||
await items[0].click(); | ||
|
||
expect(routerSpy.navigate).toHaveBeenCalledWith(['add-node', 'choose-template'], { | ||
relativeTo: route, | ||
state: jasmine.any(AddStepTarget) | ||
}); | ||
}); | ||
|
||
it('should navigate to create branch view', async () => { | ||
projectServiceSpy.isFirstStepInLesson.and.returnValue(false); | ||
projectServiceSpy.isBranchPoint.and.returnValue(false); | ||
projectServiceSpy.isNodeInAnyBranchPath.and.returnValue(false); | ||
fixture.detectChanges(); | ||
|
||
const button = await loader.getHarness(MatButtonHarness); | ||
await button.click(); | ||
const menu = await loader.getHarness(MatMenuHarness); | ||
const items = await menu.getItems(); | ||
expect(items.length).toBe(2); | ||
await items[1].click(); | ||
|
||
expect(routerSpy.navigate).toHaveBeenCalledWith(['create-branch'], { | ||
relativeTo: route, | ||
state: { targetId: 'node1' } | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters