import { Spectator, createComponentFactory } from '@ngneat/spectator';
import { UiSliderModule } from '@ui/slider';
import { ShellProcessComponent } from './process.component';

describe('ShellProcessComponent', () => {
  let spectator: Spectator<ShellProcessComponent>;
  const createComponent = createComponentFactory({
    component: ShellProcessComponent,
    declarations: [],
    imports: [UiSliderModule],
  });

  beforeEach(() => (spectator = createComponent()));

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

  it('should emit after add process button click', () => {
    spectator.setInput('canAddProcess', true);
    spyOn(spectator.component.addProcess, 'emit');
    spectator.click('button.add');
    expect(spectator.component.addProcess.emit).toHaveBeenCalled();
  });

  it('should render button.add if canAddProcess is true', () => {
    spectator.setInput('canAddProcess', true);
    expect(spectator.query('button.add')).toExist();
  });

  it('should not render button.add if canAddProcess is false', () => {
    spectator.setInput('canAddProcess', false);
    expect(spectator.query('button.add')).not.toExist();
  });

  it('should render the lable in button.add if label is set', () => {
    spectator.setInput('canAddProcess', true);
    spectator.setInput('label', 'Add Process');
    expect(spectator.query('button.add span.label')).toHaveText('Add Process');
  });

  it('should not render the lable in button.add if label is not set', () => {
    spectator.setInput('canAddProcess', true);
    expect(spectator.query('button.add span.label')).not.toExist();
  });
});
