import { ComponentFixture, TestBed } from '@angular/core/testing';
import { describe, it, expect, beforeEach } from 'vitest';
import { StockInfoComponent } from './stock-info.component';
import { RemissionStockService } from '@isa/remission/data-access';

describe('StockInfoComponent', () => {
  let component: StockInfoComponent;
  let fixture: ComponentFixture<StockInfoComponent>;
  let mockStockService: any;

  beforeEach(() => {
    mockStockService = {
      fetchStockInfos: () => Promise.resolve([]),
    };

    TestBed.configureTestingModule({
      imports: [StockInfoComponent],
      providers: [
        { provide: RemissionStockService, useValue: mockStockService },
      ],
    });

    fixture = TestBed.createComponent(StockInfoComponent);
    component = fixture.componentInstance;
    fixture.componentRef.setInput('item', {
      id: 123,
      catalogAvailability: { ssc: '10', sscText: 'Available' },
    });
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should have item input', () => {
    expect(component.item()).toEqual({
      id: 123,
      catalogAvailability: { ssc: '10', sscText: 'Available' },
    });
  });

  it('should initialize with zero inStock when no data loaded', () => {
    expect(component.inStock()).toBe(0);
  });

  it('should have stockInfoResource ResourceRef defined', () => {
    expect(component.stockInfoResource).toBeDefined();
    expect(component.stockInfoResource.value).toBeDefined();
    expect(component.stockInfoResource.isLoading).toBeDefined();
    expect(component.stockInfoResource.hasValue).toBeDefined();
    expect(component.stockInfoResource.error).toBeDefined();
    expect(component.stockInfoResource.status).toBeDefined();
    expect(component.stockInfoResource.reload).toBeDefined();
  });
});
