* Create a PageRenderer instance for testing * This mirrors the PageRenderer from app.js
()
| 39 | * This mirrors the PageRenderer from app.js |
| 40 | */ |
| 41 | function createPageRenderer() { |
| 42 | return { |
| 43 | /** |
| 44 | * Render chapter content to specified container |
| 45 | * @param {Object} chapterData - Chapter data object |
| 46 | * @param {HTMLElement} containerElement - Target container element |
| 47 | */ |
| 48 | render: function(chapterData, containerElement) { |
| 49 | if (!chapterData || !containerElement) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Clear container |
| 54 | containerElement.innerHTML = ''; |
| 55 | |
| 56 | // Create chapter container |
| 57 | const chapterContainer = document.createElement('div'); |
| 58 | chapterContainer.className = 'chapter-container'; |
| 59 | |
| 60 | // Render chapter header (title, subtitle) |
| 61 | const header = this.renderChapterHeader(chapterData); |
| 62 | chapterContainer.appendChild(header); |
| 63 | |
| 64 | // Render chapter body |
| 65 | const body = this.renderChapterBody(chapterData); |
| 66 | chapterContainer.appendChild(body); |
| 67 | |
| 68 | containerElement.appendChild(chapterContainer); |
| 69 | }, |
| 70 | |
| 71 | /** |
| 72 | * Render chapter header (title, subtitle) |
| 73 | * @param {Object} chapterData - Chapter data |
| 74 | * @returns {HTMLElement} Header element |
| 75 | */ |
| 76 | renderChapterHeader: function(chapterData) { |
| 77 | const header = document.createElement('header'); |
| 78 | header.className = 'chapter-header'; |
| 79 | |
| 80 | // Chapter number |
| 81 | const chapterNumber = document.createElement('div'); |
| 82 | chapterNumber.className = 'chapter-number'; |
| 83 | chapterNumber.textContent = `第${chapterData.number}章`; |
| 84 | header.appendChild(chapterNumber); |
| 85 | |
| 86 | // Chapter title |
| 87 | const title = document.createElement('h1'); |
| 88 | title.className = 'chapter-title'; |
| 89 | title.textContent = chapterData.title; |
| 90 | header.appendChild(title); |
| 91 | |
| 92 | // Subtitle (if exists) |
| 93 | if (chapterData.subtitle) { |
| 94 | const subtitle = document.createElement('p'); |
| 95 | subtitle.className = 'chapter-subtitle'; |
| 96 | subtitle.textContent = chapterData.subtitle; |
| 97 | header.appendChild(subtitle); |
| 98 | } |
no outgoing calls
no test coverage detected