@@ -17,7 +17,8 @@ beforeEach(async () => {
1717 <input type="checkbox" id="build-across-platforms" />
1818 <button type="submit" id="generate-button"></button>
1919 </form>
20- <a id="downloadButton"></a>
20+ <a id="download-alert-link"></a>
21+ <div id="download-alert" class="d-none"></div>
2122 ` ;
2223
2324 await import ( "../public/scripts/main.js" ) ;
@@ -98,3 +99,29 @@ test("advanced options are passed to generateWorkflow", async () => {
9899 jsyaml : window . jsyaml ,
99100 } ) ;
100101} ) ;
102+
103+ test ( "download link triggers file download" , ( ) => {
104+ const repoInput = document . getElementById ( "repo" ) ;
105+ repoInput . value = "owner/repo" ;
106+
107+ window . jsyaml = { dump : ( ) => "yaml-content" } ;
108+
109+ const mockCreateObjectURL = jest . fn ( ( ) => "blob:url" ) ;
110+ const mockRevokeObjectURL = jest . fn ( ) ;
111+ global . URL . createObjectURL = mockCreateObjectURL ;
112+ global . URL . revokeObjectURL = mockRevokeObjectURL ;
113+
114+ const a = document . createElement ( "a" ) ;
115+ document . body . appendChild ( a ) ;
116+ jest . spyOn ( document , "createElement" ) . mockImplementation ( ( tag ) => {
117+ if ( tag === "a" ) return a ;
118+ return document . createElement ( tag ) ;
119+ } ) ;
120+ const clickSpy = jest . spyOn ( a , "click" ) ;
121+
122+ document . getElementById ( "download-alert-link" ) . click ( ) ;
123+
124+ expect ( mockCreateObjectURL ) . toHaveBeenCalled ( ) ;
125+ expect ( clickSpy ) . toHaveBeenCalled ( ) ;
126+ expect ( mockRevokeObjectURL ) . toHaveBeenCalled ( ) ;
127+ } ) ;
0 commit comments