import { TestBed } from '@angular/core/testing';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { NotificationService } from './notification.service';

describe('NotificationService', () => {
  let service: NotificationService;
  let snackBarSpy: jasmine.SpyObj<MatSnackBar>;

  beforeEach(() => {
    snackBarSpy = jasmine.createSpyObj('MatSnackBar', ['open']);

    TestBed.configureTestingModule({
      imports: [MatSnackBarModule],
      providers: [
        NotificationService,
        { provide: MatSnackBar, useValue: snackBarSpy },
      ],
    });

    service = TestBed.inject(NotificationService);
  });

  describe('success', () => {
    it('should show success snackbar with correct config', () => {
      service.success('Operación exitosa');

      expect(snackBarSpy.open).toHaveBeenCalledWith(
        'Operación exitosa',
        'Cerrar',
        jasmine.objectContaining({
          duration: 4000,
          panelClass: ['success-snackbar'],
        })
      );
    });
  });

  describe('error', () => {
    it('should show error snackbar with correct config', () => {
      service.error('Error en la operación');

      expect(snackBarSpy.open).toHaveBeenCalledWith(
        'Error en la operación',
        'Cerrar',
        jasmine.objectContaining({
          duration: 6000,
          panelClass: ['error-snackbar'],
        })
      );
    });
  });

  describe('info', () => {
    it('should show info snackbar with correct config', () => {
      service.info('Información importante');

      expect(snackBarSpy.open).toHaveBeenCalledWith(
        'Información importante',
        'Cerrar',
        jasmine.objectContaining({
          duration: 4000,
        })
      );
    });
  });
});
