Skip to content

Commit e7ba216

Browse files
refactor(GroupTabsComponent): Convert to standalone (#1913)
1 parent 0b7b271 commit e7ba216

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

src/app/student/vle/student-vle.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ import { NodeComponent } from '../../../assets/wise5/vle/node/node.component';
3939
declarations: [
4040
ChooseBranchPathDialogComponent,
4141
GenerateImageDialogComponent,
42-
GroupTabsComponent,
4342
SafeUrl,
4443
VLEComponent,
4544
VLEParentComponent
4645
],
4746
imports: [
4847
CommonModule,
4948
ComponentStudentModule,
49+
GroupTabsComponent,
5050
MatDialogModule,
5151
NavigationComponent,
5252
NodeComponent,

src/assets/wise5/directives/group-tabs/group-tabs.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
animationDuration="0ms"
55
class="app-bg-bg"
66
>
7-
<mat-tab *ngFor="let node of groupNodes" [label]="node.title" [disabled]="node.disabled">
8-
</mat-tab>
7+
@for (node of groupNodes; track node.id) {
8+
<mat-tab [label]="node.title" [disabled]="node.disabled" />
9+
}
910
</mat-tab-group>

src/assets/wise5/directives/group-tabs/group-tabs.component.spec.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { TestBed } from '@angular/core/testing';
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { of } from 'rxjs';
33
import { NodeStatusService } from '../../services/nodeStatusService';
44
import { StudentDataService } from '../../services/studentDataService';
55
import { VLEProjectService } from '../../vle/vleProjectService';
66
import { GroupTabsComponent } from './group-tabs.component';
77
import { NodeService } from '../../services/nodeService';
8+
import { HarnessLoader } from '@angular/cdk/testing';
9+
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
10+
import { MatTabGroupHarness } from '@angular/material/tabs/testing';
11+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
812

9-
const group1 = { id: 'group1' };
10-
const group2 = { id: 'group2' };
13+
const group1 = { id: 'group1', title: 'Lesson 1', startId: 'node1' };
14+
const group2 = { id: 'group2', title: 'Lesson 2', startId: 'node2' };
1115
const node1 = { id: 'node1' };
1216

1317
class MockNodeStatusService {
@@ -47,10 +51,14 @@ class MockStudentDataService {
4751
}
4852

4953
let component: GroupTabsComponent;
54+
let fixture: ComponentFixture<GroupTabsComponent>;
55+
let loader: HarnessLoader;
5056
let projectService: VLEProjectService;
57+
let tabGroup: MatTabGroupHarness;
5158
describe('GroupTabsComponent', () => {
52-
beforeEach(() => {
59+
beforeEach(async () => {
5360
TestBed.configureTestingModule({
61+
imports: [BrowserAnimationsModule],
5462
providers: [
5563
GroupTabsComponent,
5664
{ provide: NodeService, useClass: MockNodeService },
@@ -59,32 +67,32 @@ describe('GroupTabsComponent', () => {
5967
{ provide: StudentDataService, useClass: MockStudentDataService }
6068
]
6169
});
62-
component = TestBed.inject(GroupTabsComponent);
70+
fixture = TestBed.createComponent(GroupTabsComponent);
71+
component = fixture.componentInstance;
6372
projectService = TestBed.inject(VLEProjectService);
73+
fixture.detectChanges();
74+
loader = TestbedHarnessEnvironment.loader(fixture);
75+
tabGroup = await loader.getHarness(MatTabGroupHarness);
6476
});
6577
ngOnInit();
6678
goToGroupTab();
6779
});
6880

6981
function ngOnInit() {
7082
describe('ngOnInit()', () => {
71-
it('should initialize class variables', () => {
72-
component.ngOnInit();
73-
expect(component.groupNodes.length).toEqual(2);
74-
expect(component.selectedTabIndex).toEqual(0);
83+
it('should initialize class variables', async () => {
84+
expect((await tabGroup.getTabs()).length).toEqual(2);
85+
expect(await (await tabGroup.getSelectedTab()).getLabel()).toEqual('Lesson 1');
7586
});
7687
});
7788
}
7889

7990
function goToGroupTab() {
8091
describe('goToGroupTab()', () => {
81-
it("should call function to set new group's startNodeId", () => {
82-
component.groupNodes = [
83-
{ id: 'group1', disabled: false, startId: 'node1', title: 'Lesson 1' }
84-
];
92+
it("should call function to set new group's startNodeId", async () => {
8593
const spy = spyOn(TestBed.inject(NodeService), 'setCurrentNode');
86-
component.goToGroupTab(0);
87-
expect(spy).toHaveBeenCalledWith('node1');
94+
await (await tabGroup.getTabs())[1].select();
95+
expect(spy).toHaveBeenCalledWith('node2');
8896
});
8997
});
9098
}

src/assets/wise5/directives/group-tabs/group-tabs.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { NodeStatusService } from '../../services/nodeStatusService';
44
import { StudentDataService } from '../../services/studentDataService';
55
import { VLEProjectService } from '../../vle/vleProjectService';
66
import { NodeService } from '../../services/nodeService';
7+
import { CommonModule } from '@angular/common';
8+
import { MatTabsModule } from '@angular/material/tabs';
79

810
class GroupNode {
911
id: string;
@@ -13,12 +15,14 @@ class GroupNode {
1315
}
1416

1517
@Component({
18+
imports: [CommonModule, MatTabsModule],
1619
selector: 'group-tabs',
20+
standalone: true,
1721
templateUrl: './group-tabs.component.html'
1822
})
1923
export class GroupTabsComponent implements OnInit {
20-
groupNodes: GroupNode[] = [];
21-
selectedTabIndex: number;
24+
protected groupNodes: GroupNode[] = [];
25+
protected selectedTabIndex: number;
2226
private subscriptions: Subscription = new Subscription();
2327

2428
constructor(
@@ -62,7 +66,7 @@ export class GroupTabsComponent implements OnInit {
6266
);
6367
}
6468

65-
goToGroupTab(groupTabIndex: number): void {
69+
protected goToGroupTab(groupTabIndex: number): void {
6670
const groupStartNodeId = this.groupNodes[groupTabIndex].startId;
6771
this.nodeService.setCurrentNode(groupStartNodeId);
6872
}

src/assets/wise5/vle/vle.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
class="vle-content tabbed"
4242
[ngClass]="{ 'nav-view': layoutState === 'nav', 'node-view': layoutState === 'node' }"
4343
>
44-
<group-tabs></group-tabs>
44+
<group-tabs />
4545
<div class="tab-content">
4646
<run-ended-and-locked-message *ngIf="runEndedAndLocked" />
4747
@if (layoutState === 'node') {

0 commit comments

Comments
 (0)