All files / src/services homeLocationSelectionStore.ts

90% Statements 9/10
100% Branches 2/2
75% Functions 3/4
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                  2x         2x   2x     310x     2x       8x     2x       2x 40x    
import type { LocationSuggestion } from '@/models/event';
 
export type HomeLocationSelectionMode = 'DEFAULT' | 'CUSTOM';
 
export interface HomeLocationSelectionState {
  mode: HomeLocationSelectionMode;
  location: LocationSuggestion | null;
}
 
const DEFAULT_SELECTION_STATE: HomeLocationSelectionState = {
  mode: 'DEFAULT',
  location: null,
};
 
const selectionsByScope = new Map<string, HomeLocationSelectionState>();
 
export function getHomeLocationSelection(
  scope: string,
): HomeLocationSelectionState {
  return selectionsByScope.get(scope) ?? DEFAULT_SELECTION_STATE;
}
 
export function setHomeLocationSelection(
  scope: string,
  selection: HomeLocationSelectionState,
): void {
  selectionsByScope.set(scope, selection);
}
 
export function clearHomeLocationSelection(scope: string): void {
  selectionsByScope.delete(scope);
}
 
export function __resetHomeLocationSelectionStoreForTests(): void {
  selectionsByScope.clear();
}