@terreno/admin-frontend 57.3.0 → 57.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/.ai/guidelines/core.md +5 -1
  2. package/README.md +4 -2
  3. package/dist/AdminConflictSheet.d.ts +16 -0
  4. package/dist/AdminConflictSheet.js +52 -0
  5. package/dist/AdminConflictSheet.js.map +1 -0
  6. package/dist/AdminHome.js +2 -1
  7. package/dist/AdminHome.js.map +1 -1
  8. package/dist/AdminMigrations.d.ts +3 -0
  9. package/dist/AdminMigrations.js +19 -0
  10. package/dist/AdminMigrations.js.map +1 -0
  11. package/dist/AdminMigrationsView.d.ts +10 -0
  12. package/dist/AdminMigrationsView.js +94 -0
  13. package/dist/AdminMigrationsView.js.map +1 -0
  14. package/dist/AdminModelForm.js +190 -44
  15. package/dist/AdminModelForm.js.map +1 -1
  16. package/dist/AdminModelTable.js +315 -27
  17. package/dist/AdminModelTable.js.map +1 -1
  18. package/dist/AdminObjectPicker.js +30 -6
  19. package/dist/AdminObjectPicker.js.map +1 -1
  20. package/dist/AdminProvider.d.ts +6 -2
  21. package/dist/AdminProvider.js +29 -7
  22. package/dist/AdminProvider.js.map +1 -1
  23. package/dist/AdminScreenRouter.d.ts +1 -1
  24. package/dist/AdminScreenRouter.js +4 -0
  25. package/dist/AdminScreenRouter.js.map +1 -1
  26. package/dist/AdminShell.d.ts +7 -3
  27. package/dist/AdminShell.js +53 -24
  28. package/dist/AdminShell.js.map +1 -1
  29. package/dist/AdminVersionConfig.js +21 -2
  30. package/dist/AdminVersionConfig.js.map +1 -1
  31. package/dist/AnnouncementEditor.d.ts +45 -0
  32. package/dist/AnnouncementEditor.js +370 -0
  33. package/dist/AnnouncementEditor.js.map +1 -0
  34. package/dist/AnnouncementList.d.ts +15 -0
  35. package/dist/AnnouncementList.js +97 -0
  36. package/dist/AnnouncementList.js.map +1 -0
  37. package/dist/AnnouncementOverview.d.ts +46 -0
  38. package/dist/AnnouncementOverview.js +101 -0
  39. package/dist/AnnouncementOverview.js.map +1 -0
  40. package/dist/AnnouncementOverviewScreenWidget.d.ts +4 -0
  41. package/dist/AnnouncementOverviewScreenWidget.js +28 -0
  42. package/dist/AnnouncementOverviewScreenWidget.js.map +1 -0
  43. package/dist/ConsentFormEditor.js +20 -3
  44. package/dist/ConsentFormEditor.js.map +1 -1
  45. package/dist/DocumentStorageBrowser.js +3 -87
  46. package/dist/DocumentStorageBrowser.js.map +1 -1
  47. package/dist/adminApiQueryParams.d.ts +5 -0
  48. package/dist/adminApiQueryParams.js +25 -0
  49. package/dist/adminApiQueryParams.js.map +1 -0
  50. package/dist/adminConflictSheetStack.d.ts +17 -0
  51. package/dist/adminConflictSheetStack.js +64 -0
  52. package/dist/adminConflictSheetStack.js.map +1 -0
  53. package/dist/adminContext.d.ts +3 -0
  54. package/dist/adminContext.js +6 -0
  55. package/dist/adminContext.js.map +1 -0
  56. package/dist/adminModelListQueryParams.d.ts +3 -2
  57. package/dist/adminModelListQueryParams.js +74 -27
  58. package/dist/adminModelListQueryParams.js.map +1 -1
  59. package/dist/adminRequest.d.ts +51 -0
  60. package/dist/adminRequest.js +161 -0
  61. package/dist/adminRequest.js.map +1 -0
  62. package/dist/adminRpc.d.ts +7 -0
  63. package/dist/adminRpc.js +21 -0
  64. package/dist/adminRpc.js.map +1 -0
  65. package/dist/adminShellNav.d.ts +17 -1
  66. package/dist/adminShellNav.js +41 -9
  67. package/dist/adminShellNav.js.map +1 -1
  68. package/dist/adminWindowRefresh.d.ts +31 -0
  69. package/dist/adminWindowRefresh.js +48 -0
  70. package/dist/adminWindowRefresh.js.map +1 -0
  71. package/dist/adminWindowedTable.d.ts +13 -0
  72. package/dist/adminWindowedTable.js +33 -0
  73. package/dist/adminWindowedTable.js.map +1 -0
  74. package/dist/comms/commsDashboardParams.d.ts +0 -4
  75. package/dist/comms/commsDashboardParams.js +1 -1
  76. package/dist/comms/commsDashboardParams.js.map +1 -1
  77. package/dist/comms/commsMessagePayload.d.ts +2 -1
  78. package/dist/comms/useCommsDashboardApi.d.ts +3 -3
  79. package/dist/comms/useCommsDashboardApi.js +41 -0
  80. package/dist/comms/useCommsDashboardApi.js.map +1 -1
  81. package/dist/index.d.ts +24 -2
  82. package/dist/index.js +23 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/isAuditLogModel.d.ts +2 -0
  85. package/dist/isAuditLogModel.js +8 -0
  86. package/dist/isAuditLogModel.js.map +1 -0
  87. package/dist/jobs/JobsDashboardScreen.d.ts +10 -0
  88. package/dist/jobs/JobsDashboardScreen.js +155 -0
  89. package/dist/jobs/JobsDashboardScreen.js.map +1 -0
  90. package/dist/jobs/JobsDashboardScreenWidget.d.ts +4 -0
  91. package/dist/jobs/JobsDashboardScreenWidget.js +11 -0
  92. package/dist/jobs/JobsDashboardScreenWidget.js.map +1 -0
  93. package/dist/jobs/JobsHomeWidget.d.ts +4 -0
  94. package/dist/jobs/JobsHomeWidget.js +21 -0
  95. package/dist/jobs/JobsHomeWidget.js.map +1 -0
  96. package/dist/jobs/JobsJobDetail.d.ts +8 -0
  97. package/dist/jobs/JobsJobDetail.js +78 -0
  98. package/dist/jobs/JobsJobDetail.js.map +1 -0
  99. package/dist/jobs/JobsStatusBadge.d.ts +5 -0
  100. package/dist/jobs/JobsStatusBadge.js +16 -0
  101. package/dist/jobs/JobsStatusBadge.js.map +1 -0
  102. package/dist/jobs/jobPayload.d.ts +62 -0
  103. package/dist/jobs/jobPayload.js +54 -0
  104. package/dist/jobs/jobPayload.js.map +1 -0
  105. package/dist/jobs/jobsDashboardParams.d.ts +11 -0
  106. package/dist/jobs/jobsDashboardParams.js +70 -0
  107. package/dist/jobs/jobsDashboardParams.js.map +1 -0
  108. package/dist/jobs/useJobsDashboardApi.d.ts +60 -0
  109. package/dist/jobs/useJobsDashboardApi.js +88 -0
  110. package/dist/jobs/useJobsDashboardApi.js.map +1 -0
  111. package/dist/jobs/useJobsDashboardUrlFilters.d.ts +5 -0
  112. package/dist/jobs/useJobsDashboardUrlFilters.js +16 -0
  113. package/dist/jobs/useJobsDashboardUrlFilters.js.map +1 -0
  114. package/dist/orgs/OrgDirectoryScreen.d.ts +16 -0
  115. package/dist/orgs/OrgDirectoryScreen.js +81 -0
  116. package/dist/orgs/OrgDirectoryScreen.js.map +1 -0
  117. package/dist/orgs/OrgMembersScreen.d.ts +9 -0
  118. package/dist/orgs/OrgMembersScreen.js +115 -0
  119. package/dist/orgs/OrgMembersScreen.js.map +1 -0
  120. package/dist/orgs/OrgSettingsScreen.d.ts +9 -0
  121. package/dist/orgs/OrgSettingsScreen.js +80 -0
  122. package/dist/orgs/OrgSettingsScreen.js.map +1 -0
  123. package/dist/orgs/OrgSwitcher.d.ts +8 -0
  124. package/dist/orgs/OrgSwitcher.js +58 -0
  125. package/dist/orgs/OrgSwitcher.js.map +1 -0
  126. package/dist/orgs/adminModelEndpoints.d.ts +18 -0
  127. package/dist/orgs/adminModelEndpoints.js +73 -0
  128. package/dist/orgs/adminModelEndpoints.js.map +1 -0
  129. package/dist/orgs/normalizeListData.d.ts +9 -0
  130. package/dist/orgs/normalizeListData.js +8 -0
  131. package/dist/orgs/normalizeListData.js.map +1 -0
  132. package/dist/orgs/organizationSettings.d.ts +17 -0
  133. package/dist/orgs/organizationSettings.js +6 -0
  134. package/dist/orgs/organizationSettings.js.map +1 -0
  135. package/dist/orgs/shouldSkipOrgScopedAdminQuery.d.ts +4 -0
  136. package/dist/orgs/shouldSkipOrgScopedAdminQuery.js +2 -0
  137. package/dist/orgs/shouldSkipOrgScopedAdminQuery.js.map +1 -0
  138. package/dist/orgs/sortOrganizations.d.ts +6 -0
  139. package/dist/orgs/sortOrganizations.js +9 -0
  140. package/dist/orgs/sortOrganizations.js.map +1 -0
  141. package/dist/orgs/useOrgContext.d.ts +20 -0
  142. package/dist/orgs/useOrgContext.js +57 -0
  143. package/dist/orgs/useOrgContext.js.map +1 -0
  144. package/dist/orgs/useOrganizationsApi.d.ts +14 -0
  145. package/dist/orgs/useOrganizationsApi.js +103 -0
  146. package/dist/orgs/useOrganizationsApi.js.map +1 -0
  147. package/dist/pdfUtils.d.ts +0 -2
  148. package/dist/pdfUtils.js +2 -2
  149. package/dist/pdfUtils.js.map +1 -1
  150. package/dist/types.d.ts +100 -4
  151. package/dist/types.js.map +1 -1
  152. package/dist/useAdminApi.js +7 -61
  153. package/dist/useAdminApi.js.map +1 -1
  154. package/dist/useAdminBackgroundTask.d.ts +1 -1
  155. package/dist/useAdminBackgroundTask.js +18 -3
  156. package/dist/useAdminBackgroundTask.js.map +1 -1
  157. package/dist/useAdminConfig.js +16 -1
  158. package/dist/useAdminConfig.js.map +1 -1
  159. package/dist/useAdminMigrations.d.ts +40 -0
  160. package/dist/useAdminMigrations.js +43 -0
  161. package/dist/useAdminMigrations.js.map +1 -0
  162. package/dist/useAdminRoles.d.ts +1 -0
  163. package/dist/useAdminRoles.js +34 -0
  164. package/dist/useAdminRoles.js.map +1 -1
  165. package/dist/useAdminRpc.d.ts +28 -0
  166. package/dist/useAdminRpc.js +128 -0
  167. package/dist/useAdminRpc.js.map +1 -0
  168. package/dist/useAdminScripts.js +51 -0
  169. package/dist/useAdminScripts.js.map +1 -1
  170. package/dist/useConfigurationApi.js +23 -0
  171. package/dist/useConfigurationApi.js.map +1 -1
  172. package/dist/useConsentHistory.js +9 -1
  173. package/dist/useConsentHistory.js.map +1 -1
  174. package/dist/useDocumentStorageApi.js +72 -0
  175. package/dist/useDocumentStorageApi.js.map +1 -1
  176. package/dist/widgets/AIRequestsScreenWidget.js +17 -7
  177. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -1
  178. package/dist/widgets/ModelsGridWidget.js +10 -3
  179. package/dist/widgets/ModelsGridWidget.js.map +1 -1
  180. package/dist/widgets/RecentActivityWidget.js +11 -4
  181. package/dist/widgets/RecentActivityWidget.js.map +1 -1
  182. package/dist/widgets/builtInWidgets.js +5 -9
  183. package/dist/widgets/builtInWidgets.js.map +1 -1
  184. package/dist/widgets/homeWidgetUtils.d.ts +0 -1
  185. package/dist/widgets/homeWidgetUtils.js +0 -8
  186. package/dist/widgets/homeWidgetUtils.js.map +1 -1
  187. package/package.json +6 -4
  188. package/src/AdminActionMenu.test.tsx +167 -0
  189. package/src/AdminBreadcrumbs.test.tsx +21 -1
  190. package/src/AdminConflictSheet.test.tsx +173 -0
  191. package/src/AdminConflictSheet.tsx +102 -0
  192. package/src/AdminHome.test.tsx +10 -11
  193. package/src/AdminHome.tsx +2 -4
  194. package/src/AdminMigrations.tsx +45 -0
  195. package/src/AdminMigrationsView.tsx +225 -0
  196. package/src/{AdminModelForm.test.tsx → AdminModelForm.isolated.tsx} +461 -154
  197. package/src/AdminModelForm.orgSkip.test.tsx +81 -0
  198. package/src/AdminModelForm.tsx +227 -56
  199. package/src/AdminModelForm.updateDepth.test.tsx +427 -0
  200. package/src/AdminModelList.test.tsx +12 -2
  201. package/src/AdminModelTable.test.tsx +560 -57
  202. package/src/AdminModelTable.tsx +430 -73
  203. package/src/AdminModelTable.windowed.test.tsx +897 -0
  204. package/src/AdminObjectPicker.tsx +32 -6
  205. package/src/AdminPrimitiveArrayField.test.tsx +178 -0
  206. package/src/AdminProvider.test.tsx +213 -3
  207. package/src/AdminProvider.tsx +39 -7
  208. package/src/AdminRolesList.test.tsx +197 -0
  209. package/src/AdminScreenRouter.test.tsx +393 -36
  210. package/src/AdminScreenRouter.tsx +6 -1
  211. package/src/AdminScriptList.test.tsx +180 -0
  212. package/src/AdminShell.test.tsx +595 -1
  213. package/src/AdminShell.tsx +110 -22
  214. package/src/AdminVersionConfig.tsx +31 -3
  215. package/src/AnnouncementEditor.test.tsx +603 -0
  216. package/src/AnnouncementEditor.tsx +673 -0
  217. package/src/AnnouncementList.test.tsx +198 -0
  218. package/src/AnnouncementList.tsx +214 -0
  219. package/src/AnnouncementOverview.test.tsx +325 -0
  220. package/src/AnnouncementOverview.tsx +325 -0
  221. package/src/AnnouncementOverviewScreenWidget.test.tsx +69 -0
  222. package/src/AnnouncementOverviewScreenWidget.tsx +51 -0
  223. package/src/CheckboxListEditor.test.tsx +8 -1
  224. package/src/ConsentFormEditor.test.tsx +28 -29
  225. package/src/ConsentFormEditor.tsx +27 -3
  226. package/src/ConsentFormList.test.tsx +12 -11
  227. package/src/ConsentResponseViewer.test.tsx +10 -11
  228. package/src/DocumentStorageBrowser.tsx +2 -139
  229. package/src/adminApiQueryParams.ts +33 -0
  230. package/src/adminConflictSheetStack.ts +87 -0
  231. package/src/adminContext.ts +8 -0
  232. package/src/adminModelListQueryParams.test.ts +60 -1
  233. package/src/adminModelListQueryParams.ts +89 -30
  234. package/src/adminRequest.test.ts +216 -0
  235. package/src/adminRequest.ts +213 -0
  236. package/src/adminRpc.test.ts +18 -0
  237. package/src/adminRpc.ts +31 -0
  238. package/src/adminScriptsHarness.test.ts +21 -0
  239. package/src/adminShellNav.test.ts +72 -6
  240. package/src/adminShellNav.ts +55 -10
  241. package/src/adminWindowRefresh.test.ts +65 -0
  242. package/src/adminWindowRefresh.ts +76 -0
  243. package/src/adminWindowedTable.test.ts +90 -0
  244. package/src/adminWindowedTable.ts +55 -0
  245. package/src/comms/CommsDashboardScreen.test.tsx +2 -2
  246. package/src/comms/commsDashboardParams.ts +1 -1
  247. package/src/comms/commsMessagePayload.ts +1 -1
  248. package/src/comms/useCommsDashboardApi.tsx +57 -4
  249. package/src/index.tsx +79 -1
  250. package/src/isAuditLogModel.test.ts +14 -0
  251. package/src/isAuditLogModel.ts +11 -0
  252. package/src/isolated/AIRequestsScreenWidget.isolated.tsx +84 -0
  253. package/src/isolated/AdminFieldRenderer.isolated.tsx +160 -0
  254. package/src/isolated/AdminFilterDrawer.isolated.tsx +215 -2
  255. package/src/isolated/AdminFilterDrawerMobile.isolated.tsx +172 -0
  256. package/src/isolated/AdminHomeWidgets.isolated.tsx +73 -0
  257. package/src/isolated/AdminObjectPicker.isolated.tsx +7 -0
  258. package/src/isolated/AdminScriptList.isolated.tsx +124 -0
  259. package/src/isolated/AdminScriptRunModal.isolated.tsx +274 -4
  260. package/src/isolated/DocumentStorageBrowser.isolated.tsx +13 -0
  261. package/src/isolated/RecentActivityWidget.isolated.tsx +138 -0
  262. package/src/isolated/adminWidgets.isolated.tsx +190 -0
  263. package/src/isolated/generateConsentHistoryPdf.isolated.ts +251 -0
  264. package/src/isolated/generateConsentPdfMobile.isolated.ts +87 -0
  265. package/src/isolated/generateConsentPdfsMobile.isolated.ts +129 -0
  266. package/src/isolated/hooks.isolated.tsx +245 -3
  267. package/src/isolated/rpcDualRun.isolated.tsx +449 -0
  268. package/src/isolated/useAdminScripts.isolated.tsx +156 -0
  269. package/src/isolated/useJobsDashboardApi.isolated.tsx +60 -0
  270. package/src/jobs/JobsDashboardScreen.test.tsx +310 -0
  271. package/src/jobs/JobsDashboardScreen.tsx +461 -0
  272. package/src/jobs/JobsDashboardScreenWidget.test.tsx +83 -0
  273. package/src/jobs/JobsDashboardScreenWidget.tsx +20 -0
  274. package/src/jobs/JobsHomeWidget.test.tsx +92 -0
  275. package/src/jobs/JobsHomeWidget.tsx +53 -0
  276. package/src/jobs/JobsJobDetail.test.tsx +253 -0
  277. package/src/jobs/JobsJobDetail.tsx +278 -0
  278. package/src/jobs/JobsStatusBadge.tsx +16 -0
  279. package/src/jobs/jobPayload.ts +114 -0
  280. package/src/jobs/jobsDashboardParams.test.ts +80 -0
  281. package/src/jobs/jobsDashboardParams.ts +84 -0
  282. package/src/jobs/useJobsDashboardApi.test.tsx +152 -0
  283. package/src/jobs/useJobsDashboardApi.tsx +132 -0
  284. package/src/jobs/useJobsDashboardUrlFilters.test.tsx +31 -0
  285. package/src/jobs/useJobsDashboardUrlFilters.tsx +31 -0
  286. package/src/orgs/OrgDirectoryScreen.test.tsx +184 -0
  287. package/src/orgs/OrgDirectoryScreen.tsx +200 -0
  288. package/src/orgs/OrgManagementScreens.test.tsx +270 -0
  289. package/src/orgs/OrgMembersScreen.tsx +254 -0
  290. package/src/orgs/OrgSettingsScreen.tsx +145 -0
  291. package/src/orgs/OrgSwitcher.test.tsx +145 -0
  292. package/src/orgs/OrgSwitcher.tsx +101 -0
  293. package/src/orgs/adminModelEndpoints.test.ts +156 -0
  294. package/src/orgs/adminModelEndpoints.ts +96 -0
  295. package/src/orgs/normalizeListData.test.ts +17 -0
  296. package/src/orgs/normalizeListData.ts +13 -0
  297. package/src/orgs/orgSwitcherOscillation.test.tsx +107 -0
  298. package/src/orgs/organizationSettings.test.ts +11 -0
  299. package/src/orgs/organizationSettings.ts +22 -0
  300. package/src/orgs/shouldSkipOrgScopedAdminQuery.test.ts +22 -0
  301. package/src/orgs/shouldSkipOrgScopedAdminQuery.ts +7 -0
  302. package/src/orgs/sortOrganizations.test.ts +13 -0
  303. package/src/orgs/sortOrganizations.ts +14 -0
  304. package/src/orgs/useOrgContext.test.tsx +94 -0
  305. package/src/orgs/useOrgContext.tsx +90 -0
  306. package/src/orgs/useOrganizationsApi.test.tsx +165 -0
  307. package/src/orgs/useOrganizationsApi.ts +118 -0
  308. package/src/pdfUtils.test.ts +37 -0
  309. package/src/pdfUtils.ts +2 -2
  310. package/src/testing/useAdminApiDouble.ts +70 -0
  311. package/src/types.ts +92 -4
  312. package/src/useAdminApi.test.ts +88 -0
  313. package/src/useAdminApi.ts +7 -65
  314. package/src/useAdminBackgroundTask.ts +20 -4
  315. package/src/useAdminConfig.ts +20 -2
  316. package/src/useAdminMigrations.test.tsx +75 -0
  317. package/src/useAdminMigrations.ts +77 -0
  318. package/src/useAdminRoles.test.ts +28 -0
  319. package/src/useAdminRoles.ts +40 -0
  320. package/src/useAdminRpc.test.tsx +250 -0
  321. package/src/useAdminRpc.ts +173 -0
  322. package/src/useAdminScripts.ts +67 -0
  323. package/src/useConfigurationApi.ts +24 -0
  324. package/src/useConsentHistory.ts +15 -2
  325. package/src/useDocumentStorageApi.ts +77 -0
  326. package/src/widgets/AIRequestsScreenWidget.test.tsx +154 -0
  327. package/src/widgets/AIRequestsScreenWidget.tsx +21 -7
  328. package/src/widgets/ModelsGridWidget.test.tsx +91 -0
  329. package/src/widgets/ModelsGridWidget.tsx +11 -1
  330. package/src/widgets/RecentActivityWidget.tsx +10 -3
  331. package/src/widgets/builtInFieldWidgets.test.tsx +166 -0
  332. package/src/widgets/builtInWidgets.ts +6 -0
  333. package/src/widgets/homeWidgetUtils.ts +0 -9
  334. package/src/widgets/pluginWidgets.test.tsx +10 -1
@@ -71,6 +71,17 @@ describe("AdminRolesList", () => {
71
71
  mockUpdateRole.mockClear();
72
72
  mockUseListStatementsQuery.mockClear();
73
73
  mockUseListStatementsQuery.mockClear();
74
+ mockUseListStatementsQuery.mockReturnValue({
75
+ data: {
76
+ statements: {
77
+ admin: ["access", "runScripts"],
78
+ adminTodo: ["read", "write", "writeOwned"],
79
+ todo: ["read", "update"],
80
+ },
81
+ },
82
+ error: null,
83
+ isLoading: false,
84
+ });
74
85
  mockUseListRolesQuery.mockReturnValue({
75
86
  data: undefined,
76
87
  error: null,
@@ -244,6 +255,192 @@ describe("AdminRolesList", () => {
244
255
 
245
256
  expect(getByText("No roles found.")).toBeTruthy();
246
257
  });
258
+
259
+ it("shows locked badges, descriptions, and permission statement states", () => {
260
+ mockUseListRolesQuery.mockReturnValue({
261
+ data: ROLES,
262
+ error: null,
263
+ isLoading: false,
264
+ refetch: mockRefetch,
265
+ });
266
+ mockUseListStatementsQuery.mockReturnValue({
267
+ data: undefined,
268
+ error: new Error("statements failed"),
269
+ isLoading: true,
270
+ });
271
+
272
+ const {getByText} = renderWithTheme(<AdminRolesList api={mockApi} apiBase="/admin" />);
273
+
274
+ expect(getByText("locked")).toBeTruthy();
275
+ expect(getByText("sealed")).toBeTruthy();
276
+ expect(getByText("Baseline role for signed-up users")).toBeTruthy();
277
+ expect(getByText("Failed to load permissions.")).toBeTruthy();
278
+ });
279
+
280
+ it("creates a role from the add-role modal and refetches the list", async () => {
281
+ mockCreateRole.mockImplementation(() => ({unwrap: async () => ({})}));
282
+ mockUseListRolesQuery.mockReturnValue({
283
+ data: ROLES,
284
+ error: null,
285
+ isLoading: false,
286
+ refetch: mockRefetch,
287
+ });
288
+ const {getByTestId} = renderWithTheme(<AdminRolesList api={mockApi} apiBase="/admin" />);
289
+
290
+ await act(async () => {
291
+ fireEvent.press(getByTestId("admin-roles-add-button"));
292
+ });
293
+ await act(async () => {
294
+ fireEvent.changeText(getByTestId("admin-role-name"), "reviewer");
295
+ fireEvent.changeText(getByTestId("admin-role-display-name"), "Reviewer");
296
+ fireEvent.changeText(getByTestId("admin-role-description"), "Can review todos");
297
+ });
298
+ await act(async () => {
299
+ fireEvent.press(getByTestId("admin-role-save-button"));
300
+ });
301
+
302
+ const createInput = mockCreateRole.mock.calls[0]?.[0] as {
303
+ description?: string;
304
+ displayName?: string;
305
+ name?: string;
306
+ permissions?: Record<string, string[]>;
307
+ };
308
+ assert.equal(createInput.name, "reviewer");
309
+ assert.equal(createInput.displayName, "Reviewer");
310
+ assert.equal(createInput.description, "Can review todos");
311
+ expect(mockRefetch).toHaveBeenCalled();
312
+ });
313
+
314
+ it("shows validation and API errors while saving a role", async () => {
315
+ mockUseListRolesQuery.mockReturnValue({
316
+ data: ROLES,
317
+ error: null,
318
+ isLoading: false,
319
+ refetch: mockRefetch,
320
+ });
321
+ const {getByTestId, getByText} = renderWithTheme(
322
+ <AdminRolesList api={mockApi} apiBase="/admin" />
323
+ );
324
+
325
+ await act(async () => {
326
+ fireEvent.press(getByTestId("admin-roles-add-button"));
327
+ });
328
+ await act(async () => {
329
+ fireEvent.press(getByTestId("admin-role-save-button"));
330
+ });
331
+ expect(getByText("Name and display name are required.")).toBeTruthy();
332
+
333
+ mockUpdateRole.mockImplementation(() => ({
334
+ unwrap: async () => {
335
+ throw {data: {detail: "Role update rejected"}};
336
+ },
337
+ }));
338
+ await act(async () => {
339
+ fireEvent.press(getByTestId("admin-roles-edit-todoUser"));
340
+ });
341
+ await act(async () => {
342
+ fireEvent.press(getByTestId("admin-role-save-button"));
343
+ });
344
+ expect(getByText("Role update rejected")).toBeTruthy();
345
+ });
346
+
347
+ it("dismisses the role editor without saving", async () => {
348
+ mockUseListRolesQuery.mockReturnValue({
349
+ data: ROLES,
350
+ error: null,
351
+ isLoading: false,
352
+ refetch: mockRefetch,
353
+ });
354
+ const {getByTestId, queryByTestId, UNSAFE_root} = renderWithTheme(
355
+ <AdminRolesList api={mockApi} apiBase="/admin" />
356
+ );
357
+
358
+ await act(async () => {
359
+ fireEvent.press(getByTestId("admin-roles-add-button"));
360
+ });
361
+ expect(getByTestId("admin-role-form")).toBeTruthy();
362
+
363
+ const modal = UNSAFE_root.findAll((node) => node.props?.testID === "admin-role-modal")[0];
364
+ await act(async () => {
365
+ modal?.props?.secondaryButtonOnClick?.();
366
+ });
367
+ expect(queryByTestId("admin-role-form")).toBeNull();
368
+ });
369
+
370
+ it("toggles custom permissions and clears standard access", async () => {
371
+ mockUseListRolesQuery.mockReturnValue({
372
+ data: ROLES,
373
+ error: null,
374
+ isLoading: false,
375
+ refetch: mockRefetch,
376
+ });
377
+ const {getByTestId, UNSAFE_root} = renderWithTheme(
378
+ <AdminRolesList api={mockApi} apiBase="/admin" />
379
+ );
380
+
381
+ await act(async () => {
382
+ fireEvent.press(getByTestId("admin-roles-edit-todoUser"));
383
+ });
384
+
385
+ await act(async () => {
386
+ fireEvent.press(getByTestId("admin-role-permission-admin-runScripts-clickable"));
387
+ });
388
+
389
+ const accessSelect = UNSAFE_root.findAllByType(SelectField).find(
390
+ (field) => field.props.testID === "admin-role-access-adminTodo"
391
+ );
392
+ await act(async () => {
393
+ accessSelect?.props.onChange("none");
394
+ });
395
+ await act(async () => {
396
+ fireEvent.press(getByTestId("admin-role-save-button"));
397
+ });
398
+
399
+ const updateInput = mockUpdateRole.mock.calls[0]?.[0] as {
400
+ changes?: {permissions?: Record<string, string[]>};
401
+ };
402
+ assert.deepEqual(updateInput.changes?.permissions, {
403
+ admin: ["runScripts"],
404
+ });
405
+ });
406
+ it("shows an API detail when role creation fails and dismisses the form", async () => {
407
+ mockCreateRole.mockImplementationOnce(() => ({
408
+ unwrap: async () => {
409
+ throw {data: {detail: "Role already exists"}};
410
+ },
411
+ }));
412
+ mockUseListRolesQuery.mockReturnValue({
413
+ data: ROLES,
414
+ error: null,
415
+ isLoading: false,
416
+ refetch: mockRefetch,
417
+ });
418
+ const {UNSAFE_root, getByTestId, getByText, queryByText} = renderWithTheme(
419
+ <AdminRolesList api={mockApi} apiBase="/admin" />
420
+ );
421
+
422
+ await act(async () => {
423
+ fireEvent.press(getByTestId("admin-roles-add-button"));
424
+ });
425
+ await act(async () => {
426
+ fireEvent.changeText(getByTestId("admin-role-name"), "operator");
427
+ fireEvent.changeText(getByTestId("admin-role-display-name"), "Operator");
428
+ });
429
+ await act(async () => {
430
+ fireEvent.press(getByTestId("admin-role-save-button"));
431
+ await Promise.resolve();
432
+ });
433
+ expect(getByText("Role already exists")).toBeTruthy();
434
+
435
+ await act(async () => {
436
+ const modal = UNSAFE_root.findAll(
437
+ (node) =>
438
+ node.props?.testID === "admin-role-modal" && typeof node.props?.onDismiss === "function"
439
+ )[0];
440
+ modal.props.onDismiss();
441
+ });
442
+ expect(queryByText("Role already exists")).toBeNull();
443
+ });
247
444
  });
248
445
 
249
446
  describe("AdminRolesField", () => {
@@ -1,65 +1,86 @@
1
1
  // noExplicitAny: test harness doubles for AdminScreenRouter routing and config mocks
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test harness doubles
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
+ import {act, fireEvent} from "@testing-library/react-native";
4
5
  import React from "react";
5
6
  import {renderWithTheme} from "../../ui/src/test-utils";
6
- import type {AdminApi, AdminConfigResponse} from "./types";
7
+ import {configureUseAdminApiDouble, resetUseAdminApiDouble} from "./testing/useAdminApiDouble";
8
+ import type {AdminApi, AdminConfigResponse, BackgroundTask} from "./types";
7
9
 
8
10
  mock.module("expo-router", () => ({
9
11
  router: {push: mock(() => {})},
10
12
  useNavigation: () => ({setOptions: mock(() => {})}),
11
13
  }));
12
14
 
13
- const configState: {config: AdminConfigResponse | null; isLoading: boolean} = {
15
+ const configState: {
16
+ config: AdminConfigResponse | null;
17
+ error: unknown;
18
+ isLoading: boolean;
19
+ } = {
14
20
  config: null,
21
+ error: null,
15
22
  isLoading: false,
16
23
  };
17
24
 
18
25
  mock.module("./useAdminConfig", () => ({
19
26
  useAdminConfig: () => ({
20
27
  config: configState.config,
21
- error: null,
28
+ error: configState.error,
22
29
  isLoading: configState.isLoading,
23
30
  }),
24
31
  }));
25
32
 
26
- mock.module("./useAdminApi", () => ({
27
- useAdminApi: () => ({
28
- useBulkPatchMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
29
- useCreateMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
30
- useDeleteMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
31
- useListQuery: () => ({
32
- data: {data: [], total: 0},
33
- error: null,
34
- isError: false,
35
- isLoading: false,
36
- refetch: mock(() => {}),
37
- }),
38
- useReadQuery: () => ({data: undefined, isLoading: false}),
39
- useUpdateMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
40
- }),
41
- }));
42
-
43
33
  mock.module("./useAdminBackgroundTask", () => ({
44
34
  useAdminBackgroundTaskMutation: () => [mock(() => ({unwrap: async () => ({taskId: "t1"})}))],
45
35
  }));
46
36
 
47
- import {AdminScreenRouter} from "./AdminScreenRouter";
48
-
49
- const adminApi = {
50
- injectEndpoints: ({endpoints}: {endpoints: (builder: unknown) => Record<string, unknown>}) => {
51
- endpoints({
52
- mutation: (spec: Record<string, unknown>) => spec,
53
- query: (spec: Record<string, unknown>) => spec,
54
- });
55
- return {
56
- useAdminVersionConfigQuery: () => ({data: null, error: null, isLoading: false}),
57
- useUpdateVersionConfigMutation: () => [
58
- () => ({unwrap: async () => ({})}),
37
+ mock.module("./useAdminScripts", () => ({
38
+ useAdminScripts: () => {
39
+ const hooks: Record<string, unknown> = {
40
+ useCancelScriptTaskMutation: () => [
41
+ mock(() => ({unwrap: async () => ({})})),
42
+ {isLoading: false},
43
+ ],
44
+ useListScriptRunsQuery: () => ({
45
+ data: undefined,
46
+ error: null,
47
+ isLoading: false,
48
+ }),
49
+ useRunScriptMutation: () => [
50
+ mock(() => ({unwrap: async () => ({taskId: ""})})),
59
51
  {isLoading: false},
60
52
  ],
61
53
  };
54
+ if (!adminScriptsHarness.omitGetScriptTaskQuery) {
55
+ hooks.useGetScriptTaskQuery = () => adminScriptsHarness.taskQuery;
56
+ }
57
+ return hooks;
62
58
  },
59
+ }));
60
+
61
+ import {AdminMigrations} from "./AdminMigrations";
62
+ import {AdminMigrationsView} from "./AdminMigrationsView";
63
+ import {AdminScreenRouter} from "./AdminScreenRouter";
64
+ import {adminScriptsHarness} from "./adminScriptsHarness.test";
65
+
66
+ const injectAdminEndpoints = ({
67
+ endpoints,
68
+ }: {
69
+ endpoints: (builder: unknown) => Record<string, unknown>;
70
+ }): Record<string, unknown> => {
71
+ endpoints({
72
+ mutation: (spec: Record<string, unknown>) => spec,
73
+ query: (spec: Record<string, unknown>) => spec,
74
+ });
75
+ return {
76
+ useAdminVersionConfigQuery: () => ({data: null, error: null, isLoading: false}),
77
+ useUpdateVersionConfigMutation: () => [() => ({unwrap: async () => ({})}), {isLoading: false}],
78
+ };
79
+ };
80
+
81
+ const adminApi = {
82
+ enhanceEndpoints: () => ({injectEndpoints: injectAdminEndpoints}),
83
+ injectEndpoints: injectAdminEndpoints,
63
84
  } as unknown as AdminApi;
64
85
 
65
86
  const baseConfig: AdminConfigResponse = {
@@ -79,35 +100,371 @@ const baseConfig: AdminConfigResponse = {
79
100
 
80
101
  describe("AdminScreenRouter", () => {
81
102
  beforeEach(() => {
103
+ resetUseAdminApiDouble();
104
+ configureUseAdminApiDouble({
105
+ useBulkPatchMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
106
+ useCreateMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
107
+ useDeleteMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
108
+ useListQuery: () => ({
109
+ data: {data: [], total: 0},
110
+ error: null,
111
+ isError: false,
112
+ isLoading: false,
113
+ refetch: mock(() => {}),
114
+ }),
115
+ useReadQuery: () => ({data: undefined, isLoading: false}),
116
+ useUpdateMutation: () => [mock(() => ({unwrap: async () => ({})})), {isLoading: false}],
117
+ });
82
118
  configState.config = baseConfig;
119
+ configState.error = null;
83
120
  configState.isLoading = false;
84
121
  });
85
122
 
86
- it("renders AdminModelTable for a configured model name", () => {
123
+ it("renders AdminMigrations for __migrations", () => {
87
124
  const {getByTestId} = renderWithTheme(
125
+ <AdminScreenRouter api={adminApi} baseUrl="/admin" name="__migrations" />
126
+ );
127
+ expect(getByTestId("admin-migrations")).toBeTruthy();
128
+ });
129
+
130
+ it("skips page chrome while AdminMigrations config is loading", () => {
131
+ configState.config = null;
132
+ configState.isLoading = true;
133
+ const {getByTestId, queryByText} = renderWithTheme(
134
+ <AdminMigrations api={adminApi} apiBase="/admin" />
135
+ );
136
+ expect(getByTestId("admin-migrations-loading")).toBeTruthy();
137
+ expect(queryByText("Migrations")).toBeNull();
138
+ });
139
+
140
+ it("wraps loaded AdminMigrations in a page", () => {
141
+ configState.config = {migrations: {enabled: true}, models: [], scripts: []};
142
+ const {getByTestId, getByText} = renderWithTheme(
143
+ <AdminMigrations api={adminApi} apiBase="/admin" />
144
+ );
145
+ expect(getByText("Migrations")).toBeTruthy();
146
+ expect(getByTestId("admin-migrations")).toBeTruthy();
147
+ });
148
+
149
+ it("renders AdminModelTable for a configured model name", () => {
150
+ const {getByTestId, unmount} = renderWithTheme(
88
151
  <AdminScreenRouter api={adminApi} baseUrl="/admin" name="Food" />
89
152
  );
90
153
  expect(getByTestId("admin-list-Food")).toBeTruthy();
154
+ unmount();
91
155
  });
92
156
 
93
157
  it("renders built-in version-config screen widget", () => {
94
- const {getByText} = renderWithTheme(
158
+ const {getByText, unmount} = renderWithTheme(
95
159
  <AdminScreenRouter api={adminApi} baseUrl="/admin" name="version-config" />
96
160
  );
97
161
  expect(getByText("Version Config")).toBeTruthy();
162
+ unmount();
98
163
  });
99
164
 
100
165
  it("shows missing widget placeholder for unregistered custom screens", () => {
101
- const {getByTestId} = renderWithTheme(
166
+ const {getByTestId, unmount} = renderWithTheme(
102
167
  <AdminScreenRouter api={adminApi} baseUrl="/admin" name="ai-admin" />
103
168
  );
104
169
  expect(getByTestId("admin-missing-widget-ai-admin")).toBeTruthy();
170
+ unmount();
105
171
  });
106
172
 
107
173
  it("returns not-found for unknown routes", () => {
108
- const {getByTestId} = renderWithTheme(
174
+ const {getByTestId, unmount} = renderWithTheme(
109
175
  <AdminScreenRouter api={adminApi} baseUrl="/admin" name="unknown-route" />
110
176
  );
111
177
  expect(getByTestId("admin-screen-not-found")).toBeTruthy();
178
+ unmount();
179
+ });
180
+ });
181
+
182
+ const mockRun = mock((_args: {wetRun: boolean}) => ({
183
+ unwrap: async () => ({taskId: "task-1"}),
184
+ }));
185
+
186
+ const mockRefetch = mock(() => {});
187
+
188
+ interface MigrationQueryState {
189
+ data:
190
+ | {
191
+ applied: Array<{appliedAt?: string; checksum: string; id: string}>;
192
+ lock: {expiresAt: string; holder: string} | null;
193
+ pending: Array<{checksum: string; id: string}>;
194
+ }
195
+ | undefined;
196
+ error: Error | null;
197
+ isLoading: boolean;
198
+ refetch: typeof mockRefetch;
199
+ }
200
+
201
+ const queryState: MigrationQueryState = {
202
+ data: {
203
+ applied: [],
204
+ lock: null,
205
+ pending: [{checksum: "abc", id: "20260910120000-todos-title-owner-index"}],
206
+ },
207
+ error: null,
208
+ isLoading: false,
209
+ refetch: mockRefetch,
210
+ };
211
+
212
+ const mockTask: {data: {task?: BackgroundTask} | undefined; error: unknown} = {
213
+ data: undefined,
214
+ error: null,
215
+ };
216
+
217
+ const createApiDouble = (): AdminApi => {
218
+ const api = {
219
+ enhanceEndpoints: () => api,
220
+ injectEndpoints: () => ({
221
+ useAdminGetMigrationsQuery: () => queryState,
222
+ useAdminGetScriptTaskQuery: () => mockTask,
223
+ useAdminRunMigrationsMutation: () => [mockRun, {isLoading: false}],
224
+ }),
225
+ };
226
+ return api as unknown as AdminApi;
227
+ };
228
+
229
+ const enabledConfig = {
230
+ migrations: {enabled: true},
231
+ models: [],
232
+ scripts: [],
233
+ } as AdminConfigResponse;
234
+
235
+ const renderView = (
236
+ overrides: Partial<{
237
+ config: AdminConfigResponse | null;
238
+ configError: unknown;
239
+ isConfigLoading: boolean;
240
+ }> = {}
241
+ ): ReturnType<typeof renderWithTheme> => {
242
+ return renderWithTheme(
243
+ <AdminMigrationsView
244
+ api={createApiDouble()}
245
+ apiBase="/admin"
246
+ config={overrides.config === undefined ? enabledConfig : overrides.config}
247
+ configError={overrides.configError}
248
+ isConfigLoading={overrides.isConfigLoading ?? false}
249
+ />
250
+ );
251
+ };
252
+
253
+ const resetQueryState = (): void => {
254
+ queryState.data = {
255
+ applied: [],
256
+ lock: null,
257
+ pending: [{checksum: "abc", id: "20260910120000-todos-title-owner-index"}],
258
+ };
259
+ queryState.error = null;
260
+ queryState.isLoading = false;
261
+ queryState.refetch = mockRefetch;
262
+ };
263
+
264
+ describe("AdminMigrationsView", () => {
265
+ beforeEach(() => {
266
+ mockRun.mockClear();
267
+ mockRefetch.mockClear();
268
+ mockTask.data = undefined;
269
+ mockTask.error = null;
270
+ adminScriptsHarness.omitGetScriptTaskQuery = false;
271
+ adminScriptsHarness.taskQuery = mockTask;
272
+ resetQueryState();
273
+ });
274
+
275
+ it("renders a spinner while admin config loads", () => {
276
+ const {getByTestId} = renderView({config: null, isConfigLoading: true});
277
+ expect(getByTestId("admin-migrations-loading")).toBeTruthy();
278
+ });
279
+
280
+ it("renders a config error", () => {
281
+ const {getByTestId} = renderView({config: null, configError: new Error("network")});
282
+ expect(getByTestId("admin-migrations-config-error")).toBeTruthy();
283
+ });
284
+
285
+ it("renders a disabled message when migrations are not configured", () => {
286
+ const {getByText} = renderView({
287
+ config: {migrations: {enabled: false}, models: [], scripts: []},
288
+ });
289
+ expect(getByText("Migrations are not configured on this server.")).toBeTruthy();
290
+ });
291
+
292
+ it("lists pending files and starts a dry-run", async () => {
293
+ const {getByTestId, getByText} = renderView();
294
+
295
+ expect(getByTestId("admin-migrations")).toBeTruthy();
296
+ expect(getByText("20260910120000-todos-title-owner-index")).toBeTruthy();
297
+
298
+ await act(async () => {
299
+ fireEvent.press(getByText("Dry run"));
300
+ });
301
+ expect(mockRun).toHaveBeenCalledWith({wetRun: false});
302
+ });
303
+
304
+ it("starts a wet apply", async () => {
305
+ const {getByText} = renderView();
306
+ await act(async () => {
307
+ fireEvent.press(getByText("Apply pending"));
308
+ });
309
+ expect(mockRun).toHaveBeenCalledWith({wetRun: true});
310
+ });
311
+
312
+ it("disables dry-run and apply when runScripts is false", () => {
313
+ const {getByTestId} = renderView({
314
+ config: {
315
+ migrations: {enabled: true},
316
+ models: [],
317
+ platformTools: {runScripts: false},
318
+ scripts: [],
319
+ } as AdminConfigResponse,
320
+ });
321
+ expect(getByTestId("admin-migrations-dry-run").props.accessibilityState.disabled).toBe(true);
322
+ expect(getByTestId("admin-migrations-apply").props.accessibilityState.disabled).toBe(true);
323
+ });
324
+
325
+ it("renders a status error", () => {
326
+ queryState.data = undefined;
327
+ queryState.error = new Error("status failed");
328
+ const {getByText} = renderView();
329
+ expect(getByText("Failed to load migration status.")).toBeTruthy();
330
+ });
331
+
332
+ it("renders a spinner while migration status loads", () => {
333
+ queryState.data = undefined;
334
+ queryState.isLoading = true;
335
+ const {getByTestId, queryByTestId} = renderView();
336
+ expect(getByTestId("admin-migrations")).toBeTruthy();
337
+ expect(queryByTestId("admin-migrations-pending")).toBeNull();
338
+ });
339
+
340
+ it("renders lock and applied rows", () => {
341
+ queryState.data = {
342
+ applied: [
343
+ {
344
+ appliedAt: "2026-09-10T12:00:00.000Z",
345
+ checksum: "def",
346
+ id: "20260910110000-todos-title-index",
347
+ },
348
+ ],
349
+ lock: {expiresAt: "2026-09-10T13:00:00.000Z", holder: "api-1"},
350
+ pending: [],
351
+ };
352
+ const {getByText} = renderView();
353
+ expect(getByText("Lock held by api-1")).toBeTruthy();
354
+ expect(getByText(/20260910110000-todos-title-index/)).toBeTruthy();
355
+ expect(getByText(/2026-09-10 12:00:00 UTC/)).toBeTruthy();
356
+ });
357
+
358
+ it("omits appliedAt when the timestamp is missing", () => {
359
+ queryState.data = {
360
+ applied: [{checksum: "def", id: "20260910110000-todos-title-index"}],
361
+ lock: null,
362
+ pending: [],
363
+ };
364
+ const {getByText, queryByText} = renderView();
365
+ expect(getByText("20260910110000-todos-title-index")).toBeTruthy();
366
+ expect(queryByText(/UTC/)).toBeNull();
367
+ });
368
+
369
+ it("renders an invalid appliedAt timestamp as-is", () => {
370
+ queryState.data = {
371
+ applied: [
372
+ {
373
+ appliedAt: "not-a-date",
374
+ checksum: "ghi",
375
+ id: "20260910100000-invalid-applied-at",
376
+ },
377
+ ],
378
+ lock: null,
379
+ pending: [],
380
+ };
381
+ const {getByText} = renderView();
382
+ expect(getByText(/20260910100000-invalid-applied-at · not-a-date/)).toBeTruthy();
383
+ });
384
+
385
+ it("renders an empty pending list", () => {
386
+ queryState.data = {applied: [], lock: null, pending: []};
387
+ const {getByText} = renderView();
388
+ expect(getByText("No pending migrations.")).toBeTruthy();
389
+ });
390
+
391
+ it("renders a failed task error", async () => {
392
+ mockTask.data = {
393
+ task: {
394
+ error: "migrate exploded",
395
+ logs: [{level: "error", message: "Migration failed", timestamp: "2026-09-11T22:00:00Z"}],
396
+ result: ["No migrations applied"],
397
+ status: "failed",
398
+ } as BackgroundTask,
399
+ };
400
+ const {getByTestId, getByText} = renderView();
401
+ await act(async () => {
402
+ fireEvent.press(getByText("Dry run"));
403
+ });
404
+ expect(getByTestId("admin-migrations-task")).toBeTruthy();
405
+ expect(getByText(/migrate exploded/)).toBeTruthy();
406
+ expect(getByText("Migration failed")).toBeTruthy();
407
+ expect(getByText("No migrations applied")).toBeTruthy();
408
+ });
409
+
410
+ it("disables apply while a queued task is in flight", async () => {
411
+ mockTask.data = {task: {status: "queued"}};
412
+ const {getByTestId, getByText} = renderView();
413
+ await act(async () => {
414
+ fireEvent.press(getByText("Dry run"));
415
+ });
416
+ expect(getByTestId("admin-migrations-task")).toBeTruthy();
417
+ expect(getByTestId("admin-migrations-apply").props.accessibilityState.disabled).toBe(true);
418
+ });
419
+
420
+ it("refetches status after a completed task", async () => {
421
+ mockTask.data = {task: {status: "completed"}};
422
+ const {getByText} = renderView();
423
+ await act(async () => {
424
+ fireEvent.press(getByText("Dry run"));
425
+ });
426
+ expect(mockRefetch).toHaveBeenCalled();
427
+ });
428
+
429
+ it("keeps apply disabled while a task is running", async () => {
430
+ mockTask.data = {task: {status: "running"}};
431
+ const {getByTestId, getByText} = renderView();
432
+ await act(async () => {
433
+ fireEvent.press(getByText("Dry run"));
434
+ });
435
+ expect(getByTestId("admin-migrations-apply").props.accessibilityState.disabled).toBe(true);
436
+ });
437
+
438
+ it("re-enables dry-run when task polling fails", async () => {
439
+ mockTask.data = undefined;
440
+ mockTask.error = new Error("forbidden");
441
+ const {getByTestId, getByText} = renderView();
442
+ await act(async () => {
443
+ fireEvent.press(getByText("Dry run"));
444
+ });
445
+ expect(getByTestId("admin-migrations-task-error")).toBeTruthy();
446
+ expect(getByTestId("admin-migrations-dry-run").props.accessibilityState.disabled).toBe(false);
447
+ });
448
+
449
+ it("still starts a dry-run when script task polling is unavailable", async () => {
450
+ adminScriptsHarness.omitGetScriptTaskQuery = true;
451
+ const {getByText} = renderView();
452
+ await act(async () => {
453
+ fireEvent.press(getByText("Dry run"));
454
+ });
455
+ expect(mockRun).toHaveBeenCalledWith({wetRun: false});
456
+ });
457
+
458
+ it("surfaces unwrap errors from run", async () => {
459
+ mockRun.mockImplementationOnce(() => ({
460
+ unwrap: async () => {
461
+ throw new Error("cannot run");
462
+ },
463
+ }));
464
+ const {getByTestId, getByText} = renderView();
465
+ await act(async () => {
466
+ fireEvent.press(getByText("Dry run"));
467
+ });
468
+ expect(getByTestId("admin-migrations-start-error")).toBeTruthy();
112
469
  });
113
470
  });