Skip to content

Commit d329f89

Browse files
committed
in progress - all tests run
1 parent 85c5b43 commit d329f89

File tree

34 files changed

+263
-59
lines changed

34 files changed

+263
-59
lines changed

projects/customizations-example/src/app/icon/icon.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ChangeDetectionStrategy } from '@angular/core';
23

34
import { IconComponent } from './icon.component';
45

@@ -9,7 +10,11 @@ describe('IconComponent', () => {
910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
1112
declarations: [IconComponent],
12-
}).compileComponents();
13+
})
14+
.overrideComponent(IconComponent, {
15+
set: { changeDetection: ChangeDetectionStrategy.Default },
16+
})
17+
.compileComponents();
1318
});
1419

1520
beforeEach(() => {

projects/customizations-example/src/app/message-action/message-action.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ChangeDetectionStrategy } from '@angular/core';
23

34
import { MessageActionComponent } from './message-action.component';
45

@@ -9,7 +10,11 @@ describe('MessageActionComponent', () => {
910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
1112
declarations: [MessageActionComponent],
12-
}).compileComponents();
13+
})
14+
.overrideComponent(MessageActionComponent, {
15+
set: { changeDetection: ChangeDetectionStrategy.Default },
16+
})
17+
.compileComponents();
1318
});
1419

1520
beforeEach(() => {

projects/customizations-example/src/app/thread-header/thread-header.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ChangeDetectionStrategy } from '@angular/core';
23

34
import { ThreadHeaderComponent } from './thread-header.component';
45

@@ -9,7 +10,11 @@ describe('ThreadHeaderComponent', () => {
910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
1112
declarations: [ThreadHeaderComponent],
12-
}).compileComponents();
13+
})
14+
.overrideComponent(ThreadHeaderComponent, {
15+
set: { changeDetection: ChangeDetectionStrategy.Default },
16+
})
17+
.compileComponents();
1318
});
1419

1520
beforeEach(() => {

projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AttachmentUpload, CustomAttachmentPreviewListContext } from '../types';
55
import { AttachmentPreviewListComponent } from './attachment-preview-list.component';
66
import {
77
AfterViewInit,
8+
ChangeDetectionStrategy,
89
Component,
910
TemplateRef,
1011
ViewChild,
@@ -25,7 +26,11 @@ describe('AttachmentPreviewListComponent', () => {
2526
attachmentUploads$ = new BehaviorSubject<AttachmentUpload[]>([]);
2627
await TestBed.configureTestingModule({
2728
declarations: [AttachmentPreviewListComponent],
28-
}).compileComponents();
29+
})
30+
.overrideComponent(AttachmentPreviewListComponent, {
31+
set: { changeDetection: ChangeDetectionStrategy.Default },
32+
})
33+
.compileComponents();
2934
});
3035

3136
beforeEach(() => {

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Channel } from 'stream-chat';
44
import { AvatarComponent } from '../avatar/avatar.component';
55

66
import { AvatarPlaceholderComponent } from './avatar-placeholder.component';
7+
import { ChangeDetectionStrategy } from '@angular/core';
78

89
describe('AvatarPlaceholderComponent', () => {
910
let component: AvatarPlaceholderComponent;
@@ -12,7 +13,11 @@ describe('AvatarPlaceholderComponent', () => {
1213
beforeEach(async () => {
1314
await TestBed.configureTestingModule({
1415
declarations: [AvatarPlaceholderComponent, AvatarComponent],
15-
}).compileComponents();
16+
})
17+
.overrideComponent(AvatarPlaceholderComponent, {
18+
set: { changeDetection: ChangeDetectionStrategy.Default },
19+
})
20+
.compileComponents();
1621
});
1722

1823
beforeEach(() => {

projects/stream-chat-angular/src/lib/avatar/avatar.component.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SimpleChange } from '@angular/core';
1+
import { ChangeDetectionStrategy, SimpleChange } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { Observable, Subject, of } from 'rxjs';
44
import { ChatClientService, ClientEvent } from '../chat-client.service';
@@ -33,6 +33,10 @@ describe('AvatarComponent', () => {
3333
providers: [
3434
{ provide: ChatClientService, useValue: chatClientServiceMock },
3535
],
36+
}).overrideComponent(AvatarComponent, {
37+
set: {
38+
changeDetection: ChangeDetectionStrategy.Default,
39+
},
3640
});
3741
fixture = TestBed.createComponent(AvatarComponent);
3842
component = fixture.componentInstance;
@@ -206,7 +210,7 @@ describe('AvatarComponent', () => {
206210
expect(component.initials).toBe('#');
207211
});
208212

209-
it(`should display other user's image in 1:1 chats`, () => {
213+
it(`should display other user's image in 1:1 chats`, async () => {
210214
const channel = generateMockChannels()[0];
211215
channel.state.members = {
212216
otheruser: {
@@ -230,6 +234,9 @@ describe('AvatarComponent', () => {
230234
expect(queryImg()?.src).toContain('url/to/img');
231235

232236
component.imageUrl = 'channel/img';
237+
component.ngOnChanges({
238+
imageUrl: {} as SimpleChange,
239+
});
233240
fixture.detectChanges();
234241

235242
expect(queryImg()?.src).toContain('channel/img');

projects/stream-chat-angular/src/lib/avatar/avatar.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export class AvatarComponent
7979
if (changes['channel']) {
8080
this.updateIsOnlineSubscription();
8181
}
82+
83+
if (changes['imageUrl'] || changes['channel']) {
84+
this.isError = false;
85+
}
86+
8287
if (changes.type || changes.name || changes.channel) {
8388
this.setInitials();
8489
}

projects/stream-chat-angular/src/lib/channel-header/channel-header.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ChannelService } from '../channel.service';
88
import { ChatClientService } from '../chat-client.service';
99
import { StreamI18nService } from '../stream-i18n.service';
1010
import { ChannelHeaderComponent } from './channel-header.component';
11+
import { ChangeDetectionStrategy } from '@angular/core';
1112

1213
describe('ChannelHeaderComponent', () => {
1314
let fixture: ComponentFixture<ChannelHeaderComponent>;
@@ -36,6 +37,8 @@ describe('ChannelHeaderComponent', () => {
3637
{ provide: ChannelService, useValue: channelServiceMock },
3738
{ provide: ChatClientService, useValue: chatClientServiceMock },
3839
],
40+
}).overrideComponent(ChannelHeaderComponent, {
41+
set: { changeDetection: ChangeDetectionStrategy.Default },
3942
});
4043
TestBed.inject(StreamI18nService).setTranslation();
4144
fixture = TestBed.createComponent(ChannelHeaderComponent);

projects/stream-chat-angular/src/lib/channel-list/channel-list.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ChannelListComponent } from './channel-list.component';
1414
import { Subject, of } from 'rxjs';
1515
import { PaginatedListComponent } from '../paginated-list/paginated-list.component';
1616
import { Channel } from 'stream-chat';
17+
import { ChangeDetectionStrategy } from '@angular/core';
1718

1819
describe('ChannelListComponent', () => {
1920
let channelServiceMock: MockChannelService;
@@ -46,6 +47,8 @@ describe('ChannelListComponent', () => {
4647
},
4748
ThemeService,
4849
],
50+
}).overrideComponent(ChannelListComponent, {
51+
set: { changeDetection: ChangeDetectionStrategy.Default },
4952
});
5053
fixture = TestBed.createComponent(ChannelListComponent);
5154
nativeElement = fixture.nativeElement as HTMLElement;

projects/stream-chat-angular/src/lib/channel-preview/channel-preview.component.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Observable, Subject, of } from 'rxjs';
1717
import { DateParserService } from '../date-parser.service';
1818
import { IconModule } from '../icon/icon.module';
1919
import { IconPlaceholderComponent } from '../icon/icon-placeholder/icon-placeholder.component';
20+
import { ChangeDetectionStrategy } from '@angular/core';
2021

2122
describe('ChannelPreviewComponent', () => {
2223
let fixture: ComponentFixture<ChannelPreviewComponent>;
@@ -52,6 +53,8 @@ describe('ChannelPreviewComponent', () => {
5253
{ provide: ChannelService, useValue: channelServiceMock },
5354
{ provide: ChatClientService, useValue: chatClientServiceMock },
5455
],
56+
}).overrideComponent(ChannelPreviewComponent, {
57+
set: { changeDetection: ChangeDetectionStrategy.Default },
5558
});
5659
fixture = TestBed.createComponent(ChannelPreviewComponent);
5760
component = fixture.componentInstance;
@@ -218,6 +221,46 @@ describe('ChannelPreviewComponent', () => {
218221
expect(avatar.location).toBe('channel-preview');
219222
});
220223

224+
it('should update title, avatarImage, and avatarName when channel is updated', () => {
225+
// Setup initial channel
226+
const channel = generateMockChannels()[0];
227+
component.channel = channel;
228+
fixture.detectChanges();
229+
230+
// Verify initial values
231+
expect(component.title).toBe(channel.data?.name);
232+
expect(component.avatarImage).toBe(channel.data?.image);
233+
expect(component.avatarName).toBe(channel.data?.name);
234+
235+
// Update channel data
236+
const updatedName = 'Updated Channel Name';
237+
const updatedImage = 'https://example.com/updated-image.jpg';
238+
239+
// Simulate channel update event
240+
channel.data = {
241+
...channel.data,
242+
name: updatedName,
243+
image: updatedImage,
244+
};
245+
246+
channel.handleEvent('channel.updated', {
247+
channel: channel,
248+
});
249+
250+
fixture.detectChanges();
251+
252+
// Verify updated values
253+
expect(component.title).toBe(updatedName);
254+
expect(component.avatarImage).toBe(updatedImage);
255+
expect(component.avatarName).toBe(updatedName);
256+
257+
// Verify UI is updated
258+
expect(queryTitle()?.textContent).toContain(updatedName);
259+
const avatar = queryAvatar();
260+
expect(avatar.imageUrl).toBe(updatedImage);
261+
expect(avatar.name).toBe(updatedName);
262+
});
263+
221264
it('should display channel display text', () => {
222265
const channel = generateMockChannels()[0];
223266
channel.data!.name = undefined;

0 commit comments

Comments
 (0)