跳到正文
DEV Community· Yan Wang·· 3 小時前AI 評分39

以兩項值測試 DOCX 連結,並加入樣式文字對照

Test a DOCX Link as Two Values, With a Styled Text Control

AI 導讀

DOCX 轉換器的超連結測試應分別核對顯示文字與目的地,避免只檢查其中一項而漏掉連結消失或標籤改變。測試以超連結範例和藍色底線的無連結文字作對照,並可核對完整 Markdown 輸出。測量只涵蓋本機 Node 對合成 OOXML 套件的轉換,不包括 Word 顯示或真實文件。

正文

A converter test for a hyperlink needs at least two assertions: the reader-facing label and the destination. Checking only that the words appear can pass when the link has disappeared; checking only that a URL appears can miss a changed label.

Terra AI drafted this article; an independent AI copy editor revised or accepted it, and the Codex AI agent checked the facts and limited test evidence. The author is affiliated with LensUp. No human drafting, review or testing is being claimed. The measurements below cover local Node conversion of synthetic, text-only OOXML packages using the unchanged inspected LensUp convertDocx and installed AnyDoc WASM 0.2.4. They do not cover Word rendering, production browser conversion, real documents, network resolution, images, security, or universal fidelity.

Build a linked fixture and a styled-text control

Use one fixture with a semantic hyperlink whose displayed text is Review note and whose relationship supplies the destination. Use a second fixture with the same words styled blue and underlined, but without a hyperlink relationship. The second fixture is a negative control: visual formatting alone should not be treated as evidence of a destination. The two fixtures are not a single-variable pair: the control also differs in run styling, being blue and underlined, so the comparison is about the hyperlink relationship, not about identical appearance.

The observed linked-label output was:

[Review note](https://example.invalid/review?rev=2&lang=en)

The observed styled-unlinked output was:

Review note

The domain ending in .invalid is deliberate fixture data. It is not a working link and was never accessed.

Make the acceptance rule explicit

For this fixture, compare the extracted label with Review note and the extracted destination with the complete expected string, including ?rev=2&lang=en. Treat those as separate results so a failure says which value changed. For an exact-output regression test, also compare the whole Markdown string, including its final newline. If the converter intentionally changes Markdown serialization later, update that serialization expectation only after checking that both semantic values still meet the contract.

For the negative control, require the plain text and verify that the output does not create a Markdown link. A test that merely searches for Review note in both results cannot distinguish success from a missing link.

The Microsoft Open XML hyperlink reference is a useful starting point for the source structure. Resolving a destination, checking whether it is safe or correct, and testing whether a reader can open it are separate tasks. This experiment did none of them; retaining a string establishes no authentication or privacy property either.

來源:DEV Community · dev.to