|
| 1 | +/** |
| 2 | + * ObjectUI |
| 3 | + * Copyright (c) 2024-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * objectui#12724 — the plan card says how the build will land (the AiBuild |
| 6 | + * artboard's last 假设 item, 「首次搭建直接上线;之后的修改先存草稿,由你发布」) from |
| 7 | + * the `planCard.posture` key objectstack-ai/cloud declares (cloud#2924 ruling A; |
| 8 | + * `build-cards.schema.json`, vendored as `fixtures/build-cards.schema.ts`). A plan |
| 9 | + * card without the key says nothing about it. |
| 10 | + * |
| 11 | + * Each message goes through the real mapper (`uiMessageToChatMessage`) from a |
| 12 | + * raw tool part, so the lift is under test, not a hand-built invocation. |
| 13 | + */ |
| 14 | +import '@testing-library/jest-dom/vitest'; |
| 15 | +import { describe, expect, it, vi } from 'vitest'; |
| 16 | +import { render, screen, within } from '@testing-library/react'; |
| 17 | +import { I18nProvider } from '@object-ui/i18n'; |
| 18 | +import { ChatbotEnhanced } from '../ChatbotEnhanced'; |
| 19 | +import { uiMessageToChatMessage } from '../mapMessages'; |
| 20 | +import { planEnvelope } from './fixtures/buildCards.fixtures'; |
| 21 | + |
| 22 | +const turn = (output: unknown) => |
| 23 | + uiMessageToChatMessage({ |
| 24 | + id: 'plan', |
| 25 | + role: 'assistant', |
| 26 | + parts: [{ type: 'tool-propose_blueprint', toolCallId: 'plan-0', state: 'output-available', input: {}, output }], |
| 27 | + }); |
| 28 | + |
| 29 | +const renderPlan = (envelope: unknown, lang: 'zh' | 'en' = 'zh') => |
| 30 | + render( |
| 31 | + <I18nProvider config={{ defaultLanguage: lang, detectBrowserLanguage: false }}> |
| 32 | + <ChatbotEnhanced messages={[turn(envelope)]} onSendMessage={vi.fn()} /> |
| 33 | + </I18nProvider>, |
| 34 | + ); |
| 35 | + |
| 36 | +const assumptionItems = () => |
| 37 | + within(screen.getByTestId('proposed-plan-assumptions')) |
| 38 | + .getAllByRole('listitem') |
| 39 | + .map((li) => li.textContent); |
| 40 | + |
| 41 | +describe('objectui#12724 — the plan card draws `planCard.posture.line`', () => { |
| 42 | + it('zh: a first build`s line is the last assumption item', () => { |
| 43 | + renderPlan(planEnvelope('zh', { posture: 'firstBuild' })); |
| 44 | + expect(assumptionItems()).toEqual([ |
| 45 | + '只建这三部分,不建仪表盘、预约、罚款;补充的字段(分类)可以去掉。', |
| 46 | + '归还后状态置为已还;逾期由应还日期已过且未归还判定。', |
| 47 | + '首次搭建直接上线;之后的修改先存草稿,由你发布', |
| 48 | + ]); |
| 49 | + expect(screen.getByTestId('proposed-plan-posture')).toHaveAttribute('data-posture', 'publish'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('en: the same line in English', () => { |
| 53 | + renderPlan(planEnvelope('en', { posture: 'firstBuild' }), 'en'); |
| 54 | + expect(screen.getByTestId('proposed-plan-posture')).toHaveTextContent( |
| 55 | + /^This first build goes live at once; later changes are saved as drafts for you to publish$/, |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it('a build into a live app draws the producer`s draft line, records included', () => { |
| 60 | + renderPlan(planEnvelope('zh', { posture: 'draft' })); |
| 61 | + const line = screen.getByTestId('proposed-plan-posture'); |
| 62 | + expect(line).toHaveTextContent(/^这个应用已上线,有 36 条记录在用;这次的改动先存为草稿,由你在「变更」里核对后发布$/); |
| 63 | + expect(line).toHaveAttribute('data-posture', 'draft'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('a plan card with no assumptions still draws the section for the posture line alone', () => { |
| 67 | + const plan = planEnvelope('zh', { posture: 'firstBuild' }); |
| 68 | + renderPlan({ ...plan, planCard: { ...plan.planCard, assumptions: [] } }); |
| 69 | + expect(assumptionItems()).toEqual(['首次搭建直接上线;之后的修改先存草稿,由你发布']); |
| 70 | + }); |
| 71 | + |
| 72 | + it('CONTROL: a plan card without `posture` draws only the assumptions', () => { |
| 73 | + renderPlan(planEnvelope('zh')); |
| 74 | + expect(screen.queryByTestId('proposed-plan-posture')).not.toBeInTheDocument(); |
| 75 | + expect(assumptionItems()).toHaveLength(2); |
| 76 | + }); |
| 77 | + |
| 78 | + it('CONTROL: a posture whose mode the schema does not declare is not drawn', () => { |
| 79 | + const plan = planEnvelope('zh', { posture: 'firstBuild' }); |
| 80 | + renderPlan({ ...plan, planCard: { ...plan.planCard, posture: { ...plan.planCard.posture, mode: 'live' } } }); |
| 81 | + expect(screen.queryByTestId('proposed-plan-posture')).not.toBeInTheDocument(); |
| 82 | + }); |
| 83 | +}); |
0 commit comments