- Added `bot_username` to settings for dynamic retrieval of the bot's username. - Implemented `_resolve_bot_username` function to fetch the bot's username if not set, improving user experience in group chats. - Updated `DutyWithUser` schema to include optional `phone` and `username` fields for enhanced duty information. - Enhanced API responses to include contact details for users, ensuring better communication. - Introduced a new current duty view in the web app, displaying active duty information along with contact options. - Updated CSS styles for better presentation of contact information in duty cards. - Added unit tests to verify the inclusion of contact details in API responses and the functionality of the current duty view.
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
/**
|
|
* Unit tests for buildDayDetailContent.
|
|
* Verifies dutyList is sorted by start_at before display.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll } from "vitest";
|
|
import { buildDayDetailContent } from "./dayDetail.js";
|
|
|
|
describe("buildDayDetailContent", () => {
|
|
beforeAll(() => {
|
|
document.body.innerHTML =
|
|
'<div id="calendar"></div><div id="monthTitle"></div>' +
|
|
'<div id="dutyList"></div><div id="loading"></div><div id="error"></div>' +
|
|
'<div id="accessDenied"></div><div class="header"></div><div class="weekdays"></div>' +
|
|
'<button id="prevMonth"></button><button id="nextMonth"></button>';
|
|
});
|
|
|
|
it("sorts duty list by start_at when input order is wrong", () => {
|
|
const dateKey = "2025-02-25";
|
|
const duties = [
|
|
{
|
|
event_type: "duty",
|
|
full_name: "Петров",
|
|
start_at: "2025-02-25T14:00:00",
|
|
end_at: "2025-02-25T18:00:00",
|
|
},
|
|
{
|
|
event_type: "duty",
|
|
full_name: "Иванов",
|
|
start_at: "2025-02-25T09:00:00",
|
|
end_at: "2025-02-25T14:00:00",
|
|
},
|
|
];
|
|
const html = buildDayDetailContent(dateKey, duties, []);
|
|
expect(html).toContain("Иванов");
|
|
expect(html).toContain("Петров");
|
|
const ivanovPos = html.indexOf("Иванов");
|
|
const petrovPos = html.indexOf("Петров");
|
|
expect(ivanovPos).toBeLessThan(petrovPos);
|
|
});
|
|
|
|
it("includes contact info (phone, username) for duty entries when present", () => {
|
|
const dateKey = "2025-03-01";
|
|
const duties = [
|
|
{
|
|
event_type: "duty",
|
|
full_name: "Alice",
|
|
start_at: "2025-03-01T09:00:00",
|
|
end_at: "2025-03-01T17:00:00",
|
|
phone: "+79991234567",
|
|
username: "alice_dev",
|
|
},
|
|
];
|
|
const html = buildDayDetailContent(dateKey, duties, []);
|
|
expect(html).toContain("Alice");
|
|
expect(html).toContain("day-detail-contact-row");
|
|
expect(html).toContain('href="tel:');
|
|
expect(html).toContain("+79991234567");
|
|
expect(html).toContain("https://t.me/");
|
|
expect(html).toContain("alice_dev");
|
|
});
|
|
});
|