|
| 1 | +/* |
| 2 | + * These tests cover SamacSys WRL-only export edge cases. They live separately |
| 3 | + * from the main direct-flow suite so targeted regressions do not push the |
| 4 | + * broader SamacSys test file past the repository line-count limit. |
| 5 | + */ |
| 6 | + |
| 7 | +import { describe, expect, it, vi } from "vitest"; |
| 8 | + |
| 9 | +import { |
| 10 | + createSamacsysFetchImpl, |
| 11 | + createSamacsysPartContext, |
| 12 | + createServiceWorkerChrome, |
| 13 | + loadServiceWorker, |
| 14 | + MOUSER_FOOTPRINT, |
| 15 | + sendRuntimeMessage |
| 16 | +} from "./helpers/service_worker_harness.js"; |
| 17 | + |
| 18 | +function decodeDataUrl(dataUrl) { |
| 19 | + return Buffer.from(String(dataUrl).split(",")[1] || "", "base64").toString( |
| 20 | + "utf8" |
| 21 | + ); |
| 22 | +} |
| 23 | + |
| 24 | +describe("service worker SamacSys WRL exports", () => { |
| 25 | + it("keeps Mouser library footprint model references when only a WRL model is present", async () => { |
| 26 | + const { chrome, listeners } = createServiceWorkerChrome({ |
| 27 | + storageState: { |
| 28 | + downloadIndividually: false, |
| 29 | + libraryDownloadRoot: "KiCad/Workspace" |
| 30 | + } |
| 31 | + }); |
| 32 | + const readZipEntries = vi.fn(async () => [ |
| 33 | + { |
| 34 | + name: "STM32C552KEU6/KiCad/QFN50P500X500X60-33N-D.kicad_mod", |
| 35 | + data: new TextEncoder().encode(MOUSER_FOOTPRINT) |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "STM32C552KEU6/3D/STM32C552KEU6.wrl", |
| 39 | + data: new TextEncoder().encode("#VRML V2.0") |
| 40 | + } |
| 41 | + ]); |
| 42 | + const fetchImpl = createSamacsysFetchImpl({ |
| 43 | + zipStatus: 200 |
| 44 | + }); |
| 45 | + |
| 46 | + loadServiceWorker({ |
| 47 | + chrome, |
| 48 | + fetchImpl, |
| 49 | + readZipEntries, |
| 50 | + urlApi: {} |
| 51 | + }); |
| 52 | + |
| 53 | + const result = await sendRuntimeMessage(listeners.runtimeMessage[0], { |
| 54 | + type: "EXPORT_PART", |
| 55 | + partContext: createSamacsysPartContext("mouser"), |
| 56 | + options: { |
| 57 | + symbol: false, |
| 58 | + footprint: true, |
| 59 | + model3d: true, |
| 60 | + datasheet: false |
| 61 | + } |
| 62 | + }); |
| 63 | + |
| 64 | + expect(result.response).toEqual({ |
| 65 | + ok: true, |
| 66 | + warnings: [], |
| 67 | + downloadCount: 2 |
| 68 | + }); |
| 69 | + |
| 70 | + const downloadCalls = chrome.downloads.download.mock.calls.map( |
| 71 | + ([options]) => options |
| 72 | + ); |
| 73 | + const footprintCall = downloadCalls.find((options) => |
| 74 | + options.filename.endsWith("Workspace.pretty/QFN50P500X500X60-33N-D.kicad_mod") |
| 75 | + ); |
| 76 | + const footprintContent = decodeDataUrl(footprintCall.url); |
| 77 | + expect(footprintContent).toContain( |
| 78 | + "../Workspace.3dshapes/STM32C552KEU6.wrl" |
| 79 | + ); |
| 80 | + expect(footprintContent).not.toContain("STM32C552KEU6.stp"); |
| 81 | + |
| 82 | + const filenames = downloadCalls.map((options) => options.filename); |
| 83 | + expect(filenames).toContain( |
| 84 | + "KiCad/Workspace/Workspace.3dshapes/STM32C552KEU6.wrl" |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + it("exports Mouser WRL-only model archives when only 3D output is selected", async () => { |
| 89 | + const { chrome, listeners } = createServiceWorkerChrome({ |
| 90 | + storageState: { |
| 91 | + downloadIndividually: true |
| 92 | + } |
| 93 | + }); |
| 94 | + const readZipEntries = vi.fn(async () => [ |
| 95 | + { |
| 96 | + name: "STM32C552KEU6/3D/STM32C552KEU6.wrl", |
| 97 | + data: new TextEncoder().encode("#VRML V2.0") |
| 98 | + } |
| 99 | + ]); |
| 100 | + const fetchImpl = createSamacsysFetchImpl({ |
| 101 | + zipStatus: 200 |
| 102 | + }); |
| 103 | + |
| 104 | + loadServiceWorker({ |
| 105 | + chrome, |
| 106 | + fetchImpl, |
| 107 | + readZipEntries |
| 108 | + }); |
| 109 | + |
| 110 | + const result = await sendRuntimeMessage(listeners.runtimeMessage[0], { |
| 111 | + type: "EXPORT_PART", |
| 112 | + partContext: createSamacsysPartContext("mouser"), |
| 113 | + options: { |
| 114 | + symbol: false, |
| 115 | + footprint: false, |
| 116 | + model3d: true, |
| 117 | + datasheet: false |
| 118 | + } |
| 119 | + }); |
| 120 | + |
| 121 | + expect(result.response).toEqual({ |
| 122 | + ok: true, |
| 123 | + warnings: [], |
| 124 | + downloadCount: 1 |
| 125 | + }); |
| 126 | + |
| 127 | + const filenames = chrome.downloads.download.mock.calls.map( |
| 128 | + ([options]) => options.filename |
| 129 | + ); |
| 130 | + expect(filenames).toEqual(["STM32C552KEU6.wrl"]); |
| 131 | + }); |
| 132 | +}); |
| 133 | + |
| 134 | +/* |
| 135 | +###################################################################################################################### |
| 136 | +
|
| 137 | +
|
| 138 | + AAAAAAAA |
| 139 | + AAAA AAAAA AAAAAAAA |
| 140 | + AAA AAA AAAA AAA |
| 141 | + AA AA AAA AAA |
| 142 | + AA AAAAAAAAAA AAA AAAAAAAAAA |
| 143 | + AAA AAA AAA AA |
| 144 | + AAA AAA AAAAA AA |
| 145 | + AAAAA AAA AAA AA |
| 146 | + AAA AAA AA |
| 147 | + AAA AAA AA |
| 148 | + AA AAA AA |
| 149 | + AA AAA AA |
| 150 | + AAA AAAAAAAAA AA |
| 151 | + AAA AAAAAAAAA AA |
| 152 | + AA AAAAAAAAAAAAAA AA |
| 153 | + AA AAAAAAAAAAAAAAAAAAAAAAAA AAAAAAA AA |
| 154 | + AAAAAAAAAAA AA AA |
| 155 | + AAA AA |
| 156 | + AAAA AA |
| 157 | + AAAA AA |
| 158 | + AAAAA AA |
| 159 | + AAAAA AA |
| 160 | + AAAAA AA |
| 161 | + AAAAAA AA |
| 162 | + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 163 | +
|
| 164 | +
|
| 165 | +###################################################################################################################### |
| 166 | +
|
| 167 | + Copyright (c) JoeShade |
| 168 | + Licensed under the GNU Affero General Public License v3.0 |
| 169 | +
|
| 170 | +###################################################################################################################### |
| 171 | +
|
| 172 | + +44 (0) 7356 042702 | joe@jshade.co.uk |
| 173 | +
|
| 174 | +###################################################################################################################### |
| 175 | +*/ |
0 commit comments