Put the reply composer at the bottom of the conversation card so the timeline and composer form one viewport-height panel; the send button is visible on load and Ctrl/Cmd+Enter submits. Internal notes now open in a dialog instead of expanding inline, so the sidebar no longer grows. Remove the shared ticket_composer helper and the inline note expansion CSS; both dialogs share ticket_dialog_head. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
120 lines
7.1 KiB
JavaScript
120 lines
7.1 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
const root = path.resolve(__dirname, '../..');
|
|
const read = file => fs.readFileSync(path.join(root, file), 'utf8');
|
|
|
|
const center = read('src/Admin/Native/UsersMenusTicketsCenter.php');
|
|
const list = read('src/Admin/Native/UsersMenusTicketsList.php');
|
|
const detail = read('src/Admin/Native/UsersMenusTicketsDetail.php');
|
|
const create = read('src/Admin/Native/UsersMenusTicketsCreate.php');
|
|
const menus = read('src/Admin/Native/UsersMenus.php');
|
|
const js = read('assets/js/admin-tickets.js');
|
|
const css = read('assets/css/admin/tickets.css');
|
|
|
|
test('ticket native page registers no AJAX read; writes reuse REST', () => {
|
|
assert.match(menus, /use UsersMenusTicketsCenter;/);
|
|
assert.match(menus, /'users.php',[\s\S]*?'aksrt_tickets'/);
|
|
assert.doesNotMatch(menus + center, /wp_ajax_aksrt_ticket_view|ajax_ticket_view|aksrt_ticket_view/);
|
|
assert.match(center, /wp_create_nonce\('wp_rest'\)/);
|
|
assert.match(center, /rest_url\('aksrt\/v1\/admin\/tickets' \./);
|
|
assert.match(js, /'X-WP-Nonce': config.restNonce/);
|
|
assert.doesNotMatch(menus, /admin_post_aksrt_ticket_update/);
|
|
assert.doesNotMatch(center, /function (handle_ticket_update|ticket_action_\w+|ticket_redirect)/);
|
|
assert.match(menus, /count_pending_tickets\(\)/);
|
|
assert.match(menus, /TicketSettings::enabled\(\)/);
|
|
});
|
|
|
|
test('list and workspace are page views; only creation is a dialog on the list page', () => {
|
|
assert.match(center, /use UsersMenusTicketsCreate;/);
|
|
assert.doesNotMatch(center, /UsersMenusTicketsDialogs/);
|
|
assert.ok(!fs.existsSync(path.join(root, 'src/Admin/Native/UsersMenusTicketsDialogs.php')));
|
|
assert.match(center, /render_ticket_detail_page\(\$id,/);
|
|
assert.doesNotMatch(center + list + js, /view=new|'view' => 'new'|\$view === 'new'|render_ticket_create_page/);
|
|
assert.match(list, /'dialog' => self::TICKET_CREATE_DIALOG/);
|
|
assert.match(list, /\$this->render_ticket_create_dialog\(\);/);
|
|
assert.match(list, /ticket_page_url\(\['id' => \$id\] \+ \$context\)/);
|
|
assert.match(create, /<dialog id="' \. esc_attr\(self::TICKET_CREATE_DIALOG\)/);
|
|
assert.match(create, /ticket_form_open\('create', 0,/);
|
|
assert.match(js, /\.showModal\(\)/);
|
|
assert.match(js, /window\.confirm\(strings\.discard\)/);
|
|
// 处理工作区本身不是弹窗;只有内部备注的输入在弹窗内。
|
|
assert.equal((detail.match(/<dialog /g) || []).length, 1);
|
|
assert.match(detail, /<dialog id="' \. esc_attr\(self::TICKET_NOTE_DIALOG\)/);
|
|
assert.match(detail, /ticket_form_open\('note', \$id, 'aksrt-ticket-dialog__frame'\)/);
|
|
assert.doesNotMatch(js + css, /aksrt-ticket-detail-dialog|aksrt-ticket-modal-open|data-aksrt-ticket-panel/);
|
|
});
|
|
|
|
test('detail lookup is independent of the filtered list; paging clamps and preserves filters', () => {
|
|
assert.match(detail, /TicketRepository::get_instance\(\)->find\(\$id\)/);
|
|
assert.match(detail, /工单不存在/);
|
|
assert.match(list, /AdminListPagination::render\(/);
|
|
assert.match(list, /'limit' => self::TICKET_PER_PAGE/);
|
|
assert.match(center, /private const TICKET_PER_PAGE = 20;/);
|
|
assert.match(list, /if \(\$paged > \$last_page\)/);
|
|
assert.match(list, /array_merge\(\$filters, \['status' => \$key\]\)/);
|
|
assert.match(list, /'keywords' => \$filters\['s'\]/);
|
|
assert.match(list, /'status' => array_column\(\$statuses, 'status_key'\)/);
|
|
assert.match(center, /function ticket_context\(/);
|
|
});
|
|
|
|
test('conversation, private notes and final-state confirmation remain distinct', () => {
|
|
assert.match(detail, /TicketNoteService::for_ticket\(\$id\)/);
|
|
assert.match(detail, /TicketRepository::get_instance\(\)->replies\(\$id\)/);
|
|
assert.match(detail, /!empty\(\$quote\['is_deleted'\]\) \? __\('原回复已删除', 'aksrt'\)/);
|
|
// 回复框是会话面板的底部,而不是独立卡片。
|
|
assert.match(detail, /return \$html \. '<\/ol><\/div>' \. \$footer \. '<\/section>';/);
|
|
assert.ok(detail.includes("ticket_form_open('reply', $id, 'aksrt-ticket-composer')"));
|
|
assert.match(detail, /data-aksrt-ticket-send-shortcut/);
|
|
assert.match(js, /event\.ctrlKey \|\| event\.metaKey/);
|
|
assert.ok(detail.includes("ticket_form_open('status'"));
|
|
assert.doesNotMatch(detail, /function ticket_composer\(/);
|
|
assert.match(detail, /aksrt-ticket-detail__closed/);
|
|
assert.match(detail, /TicketStatusService::can_transition\(\$from, \$key\)/);
|
|
assert.match(detail, /data-aksrt-ticket-close-confirm/);
|
|
assert.match(detail, /data-aksrt-ticket-assign/);
|
|
assert.match(detail, /仅管理员可见,不会发送给用户/);
|
|
});
|
|
|
|
test('page safety: unsaved-change guard, drafts survive the post-save reload, uncertain writes lock forms', () => {
|
|
assert.match(js, /window.addEventListener\('beforeunload'/);
|
|
assert.match(js, /sessionStorage/);
|
|
assert.match(js, /aksrt_ticket_msg/);
|
|
assert.match(js, /next.length > field.maxLength/);
|
|
assert.match(js, /strings.uncertain/);
|
|
assert.match(js, /\[401, 403, 404, 409\]/);
|
|
assert.match(js, /lockForms\(\)/);
|
|
assert.match(css, /:focus-visible/);
|
|
assert.match(css, /@media \(prefers-reduced-motion: reduce\)/);
|
|
assert.match(css, /@media \(max-width: 600px\)/);
|
|
assert.doesNotMatch(css, /detail-row|row\.is-open/);
|
|
});
|
|
|
|
test('configuration remains in the SPA; native ops has no old config tabs', () => {
|
|
assert.match(list, /admin_url\('admin\.php\?page=aksrt-settings#\/users\/ticket'\)/);
|
|
assert.doesNotMatch(center + list + detail, /nav-tab-wrapper|ticket_tab|UsersMenusTicketsConfig/);
|
|
assert.ok(!fs.existsSync(path.join(root, 'src/Admin/Native/UsersMenusTicketsConfig.php')));
|
|
assert.ok(read('assets/admin/src/router/index.js').includes("{ path: '/users/tickets', title: '工单管理', nativeAdminPath: 'users.php?page=aksrt_tickets' }"));
|
|
});
|
|
|
|
test('frontend hooks remain aligned with their independent REST consumer', () => {
|
|
const renderer = read('inc/helpers/user-center-renderers/profile-tickets.php');
|
|
const frontend = read('assets/js/ticket-center.js') + '\n' + read('assets/js/ticket-center-core.js');
|
|
for (const hook of ['data-aksrt-ticket-center', 'data-aksrt-ticket-create', 'data-aksrt-ticket-stats', 'data-aksrt-ticket-stat=', 'data-aksrt-ticket-list', 'data-aksrt-ticket-pagination', 'data-aksrt-tickets-search', 'data-aksrt-ticket-filter=']) {
|
|
assert.ok(renderer.includes(hook), `renderer missing ${hook}`);
|
|
}
|
|
for (const hook of ['data-aksrt-ticket-center', 'data-aksrt-ticket-create', 'data-aksrt-ticket-list', 'data-aksrt-ticket-view=', 'data-aksrt-ticket-page=', 'data-aksrt-ticket-quote=', 'data-aksrt-ticket-images']) {
|
|
assert.ok(frontend.includes(hook), `frontend missing ${hook}`);
|
|
}
|
|
for (const endpoint of ["'/tickets'", "'/tickets/statistic'", "'/tickets/meta'", "'/tickets/' + ticketId", "'/tickets/' + ticket.id + '/reply'", "'/ticket/upload-attachment'"]) {
|
|
assert.ok(frontend.includes(endpoint));
|
|
}
|
|
assert.match(frontend, /runCaptcha\('ticket_create'\)/);
|
|
assert.match(frontend, /runCaptcha\('ticket_reply'\)/);
|
|
const routeCss = read('assets/css/routes/tickets.css');
|
|
for (const hook of ['.aksrt-tickets-page', '.aksrt-ticket-badge', '.aksrt-ticket-detail', '--aksrt-ticket-color']) assert.ok(routeCss.includes(hook));
|
|
});
|