|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +// Part of PyBLE (https://pyble.dev) — see /LICENSE. |
| 3 | + |
| 4 | +import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
| 5 | +import { tmpdir } from "node:os"; |
| 6 | +import { join } from "node:path"; |
| 7 | + |
| 8 | +import { render, screen } from "@testing-library/react"; |
| 9 | +import { describe, expect, it } from "vitest"; |
| 10 | + |
| 11 | +import FlashPage from "@/app/flash/page"; |
| 12 | +import { passedPublicFirmwareRelease } from "@/test/fixtures/firmware-release"; |
| 13 | + |
| 14 | +describe("firmware installer release copy", () => { |
| 15 | + it("describes a qualified public selector as available", async () => { |
| 16 | + const selectionRoot = await mkdtemp( |
| 17 | + join(tmpdir(), "pyble-flash-qualified-selection-"), |
| 18 | + ); |
| 19 | + const selectionFile = join(selectionRoot, "selection.json"); |
| 20 | + const previousSelection = process.env.PYBLE_FLASH_SELECTION_FILE; |
| 21 | + process.env.PYBLE_FLASH_SELECTION_FILE = selectionFile; |
| 22 | + |
| 23 | + try { |
| 24 | + await writeFile( |
| 25 | + selectionFile, |
| 26 | + JSON.stringify(passedPublicFirmwareRelease), |
| 27 | + "utf8", |
| 28 | + ); |
| 29 | + render(<FlashPage />); |
| 30 | + |
| 31 | + expect( |
| 32 | + screen.getByText(/qualified v0\.4\.2 firmware is available/i), |
| 33 | + ).toBeInTheDocument(); |
| 34 | + expect( |
| 35 | + screen.queryByText(/public install action remains unavailable/i), |
| 36 | + ).toBeNull(); |
| 37 | + } finally { |
| 38 | + if (previousSelection === undefined) { |
| 39 | + delete process.env.PYBLE_FLASH_SELECTION_FILE; |
| 40 | + } else { |
| 41 | + process.env.PYBLE_FLASH_SELECTION_FILE = previousSelection; |
| 42 | + } |
| 43 | + await rm(selectionRoot, { recursive: true, force: true }); |
| 44 | + } |
| 45 | + }); |
| 46 | +}); |
0 commit comments