@@ -90,3 +90,58 @@ describe('URL Check in Content Script', () => {
9090 expect ( match ) . toBeNull ( ) ;
9191 } ) ;
9292} ) ;
93+
94+ describe ( 'DOM manipulation in content script' , ( ) => {
95+ beforeEach ( ( ) => {
96+ // Set up the DOM
97+ document . body . innerHTML = `
98+ <div id="article-metadata">
99+ <local-time datetime="2025-10-08T00:00:00.000Z"></local-time>
100+ </div>
101+ <div id="article-metadata-footer">
102+ <ul class="metadata page-metadata">
103+ <li class="visibility-hidden-visual-diff">
104+ <span class="badge">Last updated on 2025/10/08</span>
105+ </li>
106+ </ul>
107+ </div>
108+ <button data-theme-to="light" aria-pressed="true"></button>
109+ ` ;
110+
111+ // Mock window.location.href
112+ Object . defineProperty ( window , 'location' , {
113+ value : {
114+ href : 'https://learn.microsoft.com/ja-jp/test' ,
115+ } ,
116+ writable : true
117+ } ) ;
118+
119+ // Mock fetch
120+ global . fetch = jest . fn ( ( ) =>
121+ Promise . resolve ( {
122+ text : ( ) => Promise . resolve ( '<html><body><local-time datetime="2025-11-26T00:00:00.000Z"></local-time></body></html>' ) ,
123+ } )
124+ ) ;
125+ } ) ;
126+
127+ test ( 'should create and insert the custom header' , async ( ) => {
128+ // Run the content script
129+ require ( '../../src/content.js' ) ;
130+
131+ // Wait for the async operations to complete
132+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
133+
134+ // Check if the custom header was created
135+ const customHeader = document . getElementById ( 'custom-header-from-article-metadata-footer' ) ;
136+ expect ( customHeader ) . not . toBeNull ( ) ;
137+
138+ // Check if the custom header is in the correct position
139+ const articleMetadata = document . getElementById ( 'article-metadata' ) ;
140+ expect ( articleMetadata . nextElementSibling ) . toBe ( customHeader ) ;
141+
142+ // Check if the update information is correct
143+ const updateInfo = customHeader . querySelector ( 'p' ) ;
144+ expect ( updateInfo ) . not . toBeNull ( ) ;
145+ expect ( updateInfo . innerHTML ) . toContain ( '英語版の更新日' ) ;
146+ } ) ;
147+ } ) ;
0 commit comments