Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Chat filtering breaks when "From" and "To" have the same date #35616

Merged
merged 4 commits into from
Mar 27, 2025
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
5 changes: 5 additions & 0 deletions .changeset/tidy-cups-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes Omnichannel Contact Center's chats filter not working when "From" and "To" fields have the same date
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { usePermission, useUserId } from '@rocket.chat/ui-contexts';
import moment from 'moment';
import { parse, endOfDay, startOfDay } from 'date-fns';
import { useCallback } from 'react';

import type { ChatsFiltersQuery } from '../../contexts/ChatsContext';
Expand Down Expand Up @@ -47,10 +47,10 @@ export const useChatsQuery = () => {
if (from || to) {
query.createdAt = JSON.stringify({
...(from && {
start: moment(new Date(from)).set({ hour: 0, minutes: 0, seconds: 0 }).toISOString(),
start: startOfDay(parse(from, 'yyyy-MM-dd', new Date())).toISOString(),
}),
...(to && {
end: moment(new Date(to)).set({ hour: 23, minutes: 59, seconds: 59 }).toISOString(),
end: endOfDay(parse(to, 'yyyy-MM-dd', new Date())).toISOString(),
}),
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { faker } from '@faker-js/faker/locale/af_ZA';

import { Users } from '../fixtures/userStates';
import { OmnichannelChats } from '../page-objects/omnichannel-contact-center-chats';
import { setSettingValueById } from '../utils';
import { createAgent, makeAgentAvailable } from '../utils/omnichannel/agents';
import { createConversation } from '../utils/omnichannel/rooms';
import { test, expect } from '../utils/test';

test.use({ storageState: Users.user1.state });

test.describe('OC - Contact Center - Chats', () => {
let conversations: Awaited<ReturnType<typeof createConversation>>[];
let agent: Awaited<ReturnType<typeof createAgent>>;

let poOmniChats: OmnichannelChats;

const uuid = faker.string.uuid();
const visitorA = `visitorA_${uuid}`;
const visitorB = `visitorB_${uuid}`;

test.beforeAll(async ({ api }) => {
expect((await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).status()).toBe(200);
});

test.beforeAll(async ({ api }) => {
agent = await createAgent(api, 'user1');

expect((await makeAgentAvailable(api, agent.data._id)).status()).toBe(200);
});

test.beforeAll(async ({ api }) => {
conversations = await Promise.all([
createConversation(api, { agentId: `user1`, visitorName: visitorA }),
createConversation(api, { agentId: `user1`, visitorName: visitorB }),
]);
});

test.beforeEach(async ({ page }) => {
poOmniChats = new OmnichannelChats(page);

await page.goto('/omnichannel-directory/chats');
});

test.afterEach(async ({ page }) => {
await page.close();
});

test.afterAll(async ({ api }) => {
await Promise.all([...conversations.map((conversation) => conversation.delete()), agent.delete()]);
expect((await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).status()).toBe(200);
});

test(`OC - Contact Center - Chats - Filter from and to same date`, async ({ page }) => {
await test.step('expect conversations to be visible', async () => {
await poOmniChats.inputSearch.fill(uuid);
await expect(poOmniChats.findRowByName(visitorA)).toBeVisible();
await expect(poOmniChats.findRowByName(visitorB)).toBeVisible();
});

await test.step('expect to filter [from] and [to] today', async () => {
const [chatA] = conversations.map((c) => c.data);
const [todayString] = new Date(chatA.room.ts).toISOString().split('T');
await poOmniChats.btnFilters.click();
await expect(page).toHaveURL('/omnichannel-directory/chats/filters');
await poOmniChats.filters.inputFrom.fill(todayString);
await poOmniChats.filters.inputTo.fill(todayString);
await poOmniChats.filters.btnApply.click();
await page.waitForResponse('**/api/v1/livechat/rooms*');
});

await test.step('expect conversations to be visible', async () => {
await expect(poOmniChats.findRowByName(visitorA)).toBeVisible();
await expect(poOmniChats.findRowByName(visitorB)).toBeVisible();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Locator, Page } from '@playwright/test';

export class OmnichannelChatsFilters {
protected readonly page: Page;

constructor(page: Page) {
this.page = page;
}

get inputFrom(): Locator {
return this.page.locator('input[name="from"]');
}

get inputTo(): Locator {
return this.page.locator('input[name="to"]');
}

get btnApply(): Locator {
return this.page.locator('role=button[name="Apply"]');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Locator, Page } from '@playwright/test';

import { OmnichannelChatsFilters } from './omnichannel-contact-center-chats-filters';

export class OmnichannelChats {
private readonly page: Page;

filters: OmnichannelChatsFilters;

constructor(page: Page) {
this.page = page;
this.filters = new OmnichannelChatsFilters(page);
}

get btnFilters(): Locator {
return this.page.locator('role=button[name="Filters"]');
}

get inputSearch(): Locator {
return this.page.locator('role=textbox[name="Search"]');
}

findRowByName(contactName: string) {
return this.page.locator(`td >> text="${contactName}"`);
}
}
Loading