Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/tests/wave16_toast_reducer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe('Wave 16 Zenith: Real-time Toast Notification State Reducer', () => {
interface Toast {
id: string;
type: 'success' | 'error' | 'info';
message: string;
timestamp: number;
}

interface ToastState {
toasts: Toast[];
maxToasts: number;
}

const toastReducer = (state: ToastState, action: { type: 'ADD_TOAST' | 'DISMISS_TOAST'; payload?: any }): ToastState => {

Check failure on line 14 in src/tests/wave16_toast_reducer.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
switch (action.type) {
case 'ADD_TOAST': {
const next = [action.payload, ...state.toasts].slice(0, state.maxToasts);
return { ...state, toasts: next };
}
case 'DISMISS_TOAST': {
return {
...state,
toasts: state.toasts.filter(t => t.id !== action.payload.id)
};
}
default:
return state;
}
};

it('should add new payment toast and respect max toast limit', () => {
const initialState: ToastState = { toasts: [], maxToasts: 3 };
let state = toastReducer(initialState, {
type: 'ADD_TOAST',
payload: { id: 't1', type: 'success', message: 'Payment settled', timestamp: 1000 }
});
state = toastReducer(state, {
type: 'ADD_TOAST',
payload: { id: 't2', type: 'info', message: 'Processing intent', timestamp: 2000 }
});
expect(state.toasts.length).toBe(2);
expect(state.toasts[0].id).toBe('t2');

Check failure on line 42 in src/tests/wave16_toast_reducer.test.ts

View workflow job for this annotation

GitHub Actions / Build

Object is possibly 'undefined'.

Check failure on line 42 in src/tests/wave16_toast_reducer.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Object is possibly 'undefined'.
});

it('should dismiss toast by unique identifier', () => {
const initialState: ToastState = {
toasts: [
{ id: 't1', type: 'success', message: 'Tx 1', timestamp: 1000 },
{ id: 't2', type: 'error', message: 'Tx 2', timestamp: 2000 }
],
maxToasts: 5
};
const nextState = toastReducer(initialState, { type: 'DISMISS_TOAST', payload: { id: 't1' } });
expect(nextState.toasts.length).toBe(1);
expect(nextState.toasts[0].id).toBe('t2');

Check failure on line 55 in src/tests/wave16_toast_reducer.test.ts

View workflow job for this annotation

GitHub Actions / Build

Object is possibly 'undefined'.

Check failure on line 55 in src/tests/wave16_toast_reducer.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Object is possibly 'undefined'.
});
});
Loading