mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 22:31:46 +00:00
fix: repair test suite after SWR offline-read changes
Add navigator.onLine guard to SWR refresh IIFEs so background network calls don't fire in offline mode (prevents fake-IDB leakage in tests via MSW default handlers). Fix IDB isolation in affected test files by flushing pending macro tasks then clearing IDB tables in beforeEach, so stale IDB writes from previous tests' background IIFEs don't bleed into the next test. Restore loadBudgetItems and refreshPlaces to apply background refresh results to store state. Move tags/categories API calls before the main Promise.all in loadTrip so MSW handlers resolve during the await window.
This commit is contained in:
@@ -9,6 +9,7 @@ export const accommodationRepo = {
|
||||
.where('trip_id').equals(Number(tripId)).toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await accommodationsApi.list(tripId)
|
||||
upsertAccommodations(result.accommodations || []).catch(() => {})
|
||||
|
||||
@@ -11,6 +11,7 @@ export const budgetRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await budgetApi.list(tripId)
|
||||
upsertBudgetItems(result.items)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const dayRepo = {
|
||||
.sortBy('day_number' as keyof Day)) as Day[]
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await daysApi.list(tripId)
|
||||
upsertDays(result.days)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const fileRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await filesApi.list(tripId)
|
||||
upsertTripFiles(result.files)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const packingRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await packingApi.list(tripId)
|
||||
upsertPackingItems(result.items)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const placeRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await placesApi.list(tripId, params)
|
||||
upsertPlaces(result.places)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const reservationRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await reservationsApi.list(tripId)
|
||||
upsertReservations(result.reservations)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const todoRepo = {
|
||||
.toArray()
|
||||
|
||||
const refresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await todoApi.list(tripId)
|
||||
upsertTodoItems(result.items)
|
||||
|
||||
@@ -11,6 +11,7 @@ export const tripRepo = {
|
||||
const all = await offlineDb.trips.toArray()
|
||||
|
||||
const refresh: TripsRefresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const [active, archived] = await Promise.all([
|
||||
tripsApi.list(),
|
||||
@@ -41,6 +42,7 @@ export const tripRepo = {
|
||||
const cached = await offlineDb.trips.get(Number(tripId))
|
||||
|
||||
const refresh: TripRefresh = (async () => {
|
||||
if (!navigator.onLine) return null
|
||||
try {
|
||||
const result = await tripsApi.get(tripId)
|
||||
upsertTrip(result.trip)
|
||||
|
||||
Reference in New Issue
Block a user