Skip to content

Commit 75bb2c9

Browse files
committed
testing cleanup
1 parent f0a6af9 commit 75bb2c9

2 files changed

Lines changed: 80 additions & 85 deletions

File tree

src/components/TypingIndicator/TypingIndicator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ const TypingIndicator = ({
3838
}`}
3939
>
4040
<div className="str-chat__typing-indicator__avatars">
41-
{typingInChannel.map(({ user }) => (
41+
{typingInChannel.map(({ user }, i) => (
4242
<Avatar
4343
image={user?.image}
4444
size={avatarSize}
4545
name={user?.name || user?.id}
46-
key={user?.id}
46+
key={i}
4747
/>
4848
))}
4949
</div>

src/components/TypingIndicator/__tests__/TypingIndicator.test.js

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -140,95 +140,90 @@ describe('TypingIndicator', () => {
140140
expect(tree).toMatchInlineSnapshot(`null`);
141141
});
142142

143-
it('should render TypingIndicator if user is typing in thread', async () => {
144-
const client = await getTestClientWithUser();
145-
const ch = generateChannel({ config: { typing_events: true } });
146-
useMockedApis(client, [getOrCreateChannelApi(ch)]);
147-
const channel = client.channel('messaging', ch.id);
148-
await channel.watch();
149-
150-
const { container } = await renderComponent({}, true, {
151-
client,
152-
typing: {
153-
example: { parent_id: 'sample-thread', user: 'test-user' },
154-
},
155-
channel,
156-
thread: { id: 'sample-thread' },
143+
describe('TypingIndicator in thread', () => {
144+
let client;
145+
let ch;
146+
let channel;
147+
148+
beforeEach(async () => {
149+
client = await getTestClientWithUser();
150+
ch = generateChannel({ config: { typing_events: true } });
151+
useMockedApis(client, [getOrCreateChannelApi(ch)]);
152+
channel = client.channel('messaging', ch.id);
153+
await channel.watch();
157154
});
158-
159-
expect(
160-
container.firstChild.classList.contains(
161-
'str-chat__typing-indicator--typing',
162-
),
163-
).toBe(true);
164-
});
165-
166-
it('should not render TypingIndicator in main channel if user is typing in thread', async () => {
167-
const client = await getTestClientWithUser();
168-
const ch = generateChannel({ config: { typing_events: true } });
169-
useMockedApis(client, [getOrCreateChannelApi(ch)]);
170-
const channel = client.channel('messaging', ch.id);
171-
await channel.watch();
172-
173-
const { container } = await renderComponent({}, false, {
174-
client,
175-
typing: {
176-
example: { parent_id: 'sample-thread', user: 'test-user' },
177-
},
178-
channel,
179-
thread: { id: 'sample-thread' },
155+
afterEach(cleanup);
156+
157+
it('should render TypingIndicator if user is typing in thread', async () => {
158+
const { container } = await renderComponent(
159+
{ example: { parent_id: 'sample-thread', user: 'test-user' } },
160+
true,
161+
{
162+
client,
163+
channel,
164+
thread: { id: 'sample-thread' },
165+
},
166+
);
167+
168+
expect(
169+
container.firstChild.classList.contains(
170+
'str-chat__typing-indicator--typing',
171+
),
172+
).toBe(true);
180173
});
181174

182-
expect(
183-
container.firstChild.classList.contains(
184-
'str-chat__typing-indicator--typing',
185-
),
186-
).toBe(false);
187-
});
188-
189-
it('should not render TypingIndicator in thread if user is typing in main channel', async () => {
190-
const client = await getTestClientWithUser();
191-
const ch = generateChannel({ config: { typing_events: true } });
192-
useMockedApis(client, [getOrCreateChannelApi(ch)]);
193-
const channel = client.channel('messaging', ch.id);
194-
await channel.watch();
195-
196-
const { container } = await renderComponent({}, true, {
197-
client,
198-
typing: {
199-
example: { user: 'test-user' },
200-
},
201-
channel,
202-
thread: { id: 'sample-thread' },
175+
it('should not render TypingIndicator in main channel if user is typing in thread', async () => {
176+
const { container } = await renderComponent(
177+
{ example: { parent_id: 'sample-thread', user: 'test-user' } },
178+
false,
179+
{
180+
client,
181+
channel,
182+
thread: { id: 'sample-thread' },
183+
},
184+
);
185+
186+
expect(
187+
container.firstChild.classList.contains(
188+
'str-chat__typing-indicator--typing',
189+
),
190+
).toBe(false);
203191
});
204192

205-
expect(
206-
container.firstChild.classList.contains(
207-
'str-chat__typing-indicator--typing',
208-
),
209-
).toBe(false);
210-
});
211-
212-
it('should not render TypingIndicator in thread if user is typing in another thread', async () => {
213-
const client = await getTestClientWithUser();
214-
const ch = generateChannel({ config: { typing_events: true } });
215-
useMockedApis(client, [getOrCreateChannelApi(ch)]);
216-
const channel = client.channel('messaging', ch.id);
217-
await channel.watch();
218-
219-
const { container } = await renderComponent({}, true, {
220-
client,
221-
typing: {
222-
example: { parent_id: 'sample-thread-2', user: 'test-user' },
223-
},
224-
channel,
225-
thread: { id: 'sample-thread' },
193+
it('should not render TypingIndicator in thread if user is typing in main channel', async () => {
194+
const { container } = await renderComponent(
195+
{ example: { user: 'test-user' } },
196+
true,
197+
{
198+
client,
199+
channel,
200+
thread: { id: 'sample-thread' },
201+
},
202+
);
203+
204+
expect(
205+
container.firstChild.classList.contains(
206+
'str-chat__typing-indicator--typing',
207+
),
208+
).toBe(false);
226209
});
227210

228-
expect(
229-
container.firstChild.classList.contains(
230-
'str-chat__typing-indicator--typing',
231-
),
232-
).toBe(false);
211+
it('should not render TypingIndicator in thread if user is typing in another thread', async () => {
212+
const { container } = await renderComponent(
213+
{ example: { parent_id: 'sample-thread-2', user: 'test-user' } },
214+
true,
215+
{
216+
client,
217+
channel,
218+
thread: { id: 'sample-thread' },
219+
},
220+
);
221+
222+
expect(
223+
container.firstChild.classList.contains(
224+
'str-chat__typing-indicator--typing',
225+
),
226+
).toBe(false);
227+
});
233228
});
234229
});

0 commit comments

Comments
 (0)