|
18 | 18 | * |
19 | 19 | */ |
20 | 20 |
|
21 | | -/*global describe, beforeAll, afterAll, awaitsFor, it, awaitsForDone, expect*/ |
| 21 | +/*global describe, beforeAll, afterAll, awaitsFor, awaits, it, awaitsForDone, expect*/ |
22 | 22 |
|
23 | 23 | define(function (require, exports, module) { |
24 | 24 |
|
@@ -447,5 +447,95 @@ define(function (require, exports, module) { |
447 | 447 | execSearchTests("edit", _enterEditMode); |
448 | 448 | execSearchTests("reader", _enterReaderMode); |
449 | 449 | }); |
| 450 | + |
| 451 | + describe("Non-markdown file preview behavior", function () { |
| 452 | + |
| 453 | + function _getMdPreviewH1() { |
| 454 | + const mdDoc = _getMdIFrameDoc(); |
| 455 | + if (!mdDoc) { return null; } |
| 456 | + const h1 = mdDoc.querySelector("#viewer-content h1"); |
| 457 | + return h1 ? h1.textContent : null; |
| 458 | + } |
| 459 | + |
| 460 | + it("should not render binary/json files in md viewer when switching from md", async function () { |
| 461 | + // Open a markdown file first |
| 462 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc1.md"]), |
| 463 | + "open doc1.md"); |
| 464 | + await _waitForMdPreviewReady(EditorManager.getActiveEditor()); |
| 465 | + |
| 466 | + // Remember what the md viewer is showing |
| 467 | + const mdH1Before = _getMdPreviewH1(); |
| 468 | + expect(mdH1Before).not.toBeNull(); |
| 469 | + |
| 470 | + // Switch to a JSON file (non-markdown, non-previewable) |
| 471 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["test-data.json"]), |
| 472 | + "open test-data.json"); |
| 473 | + // Negative assertion: wait for any async switch to settle |
| 474 | + await awaits(500); |
| 475 | + |
| 476 | + // The md viewer should still show the last md file's content, |
| 477 | + // NOT the json file's content |
| 478 | + const mdH1After = _getMdPreviewH1(); |
| 479 | + expect(mdH1After).toBe(mdH1Before); |
| 480 | + |
| 481 | + // The md viewer content should NOT contain json data |
| 482 | + const mdDoc = _getMdIFrameDoc(); |
| 483 | + const viewerText = mdDoc.getElementById("viewer-content").textContent; |
| 484 | + expect(viewerText).not.toContain('"name"'); |
| 485 | + expect(viewerText).not.toContain('"value"'); |
| 486 | + |
| 487 | + await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }), |
| 488 | + "force close test-data.json"); |
| 489 | + }, 15000); |
| 490 | + |
| 491 | + it("should resume md preview when switching back to md from non-md file", async function () { |
| 492 | + // Open doc1.md |
| 493 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc1.md"]), |
| 494 | + "open doc1.md"); |
| 495 | + await _waitForMdPreviewReady(EditorManager.getActiveEditor()); |
| 496 | + const doc1H1 = _getMdPreviewH1(); |
| 497 | + |
| 498 | + // Switch to JSON |
| 499 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["test-data.json"]), |
| 500 | + "open test-data.json"); |
| 501 | + await awaits(500); |
| 502 | + |
| 503 | + // Switch to doc2.md — should show doc2 content, not doc1 or json |
| 504 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc2.md"]), |
| 505 | + "open doc2.md"); |
| 506 | + await _waitForMdPreviewReady(EditorManager.getActiveEditor()); |
| 507 | + |
| 508 | + const doc2H1 = _getMdPreviewH1(); |
| 509 | + expect(doc2H1).not.toBeNull(); |
| 510 | + expect(doc2H1).not.toBe(doc1H1); |
| 511 | + |
| 512 | + await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }), |
| 513 | + "force close doc2.md"); |
| 514 | + }, 15000); |
| 515 | + |
| 516 | + it("should keep last md preview when switching to HTML file", async function () { |
| 517 | + // Open a markdown file |
| 518 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc1.md"]), |
| 519 | + "open doc1.md"); |
| 520 | + await _waitForMdPreviewReady(EditorManager.getActiveEditor()); |
| 521 | + const mdH1 = _getMdPreviewH1(); |
| 522 | + |
| 523 | + // Switch to HTML — live preview should switch to HTML, hiding md viewer |
| 524 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]), |
| 525 | + "open simple.html"); |
| 526 | + await awaits(500); |
| 527 | + |
| 528 | + // MD iframe should be hidden (HTML live preview takes over) |
| 529 | + const mdIFrame = _getMdPreviewIFrame(); |
| 530 | + const mdHidden = !mdIFrame || mdIFrame.style.display === "none"; |
| 531 | + // OR if md viewer stayed visible, its content should be the last md file |
| 532 | + if (!mdHidden) { |
| 533 | + expect(_getMdPreviewH1()).toBe(mdH1); |
| 534 | + } |
| 535 | + |
| 536 | + await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }), |
| 537 | + "force close simple.html"); |
| 538 | + }, 15000); |
| 539 | + }); |
450 | 540 | }); |
451 | 541 | }); |
0 commit comments