import { allSettled, fork } from 'effector'
import { describe, it, expect } from 'vitest'
import { $cartSnackOpen, cartAdded, cartDismissed } from '../cart-notifications'

describe('cart-notifications store', () => {
  it('opens on cartAdded', async () => {
    const scope = fork()
    await allSettled(cartAdded, { scope })
    expect(scope.getState($cartSnackOpen)).toBe(true)
  })

  it('closes on cartDismissed', async () => {
    const scope = fork()
    await allSettled(cartAdded, { scope })
    await allSettled(cartDismissed, { scope })
    expect(scope.getState($cartSnackOpen)).toBe(false)
  })

  it('starts closed by default', () => {
    const scope = fork()
    expect(scope.getState($cartSnackOpen)).toBe(false)
  })
})
