59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
/**
|
|
* Covers the cluster selector's model: the toggle picks the mode, choosing remote exposes a scheduler
|
|
* field whose text joins the choice, and leaving remote drops the scheduler again. The component does
|
|
* no HTTP, so fixtures are only the rendered component.
|
|
*/
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { ClusterSelector } from './cluster-selector';
|
|
|
|
describe('ClusterSelector', () => {
|
|
function create() {
|
|
TestBed.configureTestingModule({ imports: [ClusterSelector] });
|
|
const fixture = TestBed.createComponent(ClusterSelector);
|
|
fixture.detectChanges();
|
|
return fixture;
|
|
}
|
|
|
|
// Fails if the initial mode stops being 'auto', or the scheduler field shows before remote is picked.
|
|
it('starts on auto with the scheduler field hidden', () => {
|
|
const fixture = create();
|
|
expect(fixture.componentInstance.choice()).toEqual({ mode: 'auto' });
|
|
expect(fixture.nativeElement.querySelector('.cluster-selector__scheduler')).toBeNull();
|
|
expect(fixture.nativeElement.textContent).toContain('Remoto');
|
|
});
|
|
|
|
// Fails if picking remote stops asking for the scheduler, or its text stops joining the choice.
|
|
it('adds the scheduler address to the choice only while remote is selected', () => {
|
|
const fixture = create();
|
|
const selector = fixture.componentInstance;
|
|
|
|
selector.setMode('remote');
|
|
fixture.detectChanges();
|
|
expect(selector.choice()).toEqual({ mode: 'remote' });
|
|
expect(fixture.nativeElement.querySelector('.cluster-selector__scheduler')).not.toBeNull();
|
|
|
|
selector.scheduler.setValue('tcp://equipo:8786');
|
|
expect(selector.choice()).toEqual({ mode: 'remote', scheduler: 'tcp://equipo:8786' });
|
|
|
|
selector.setMode('local');
|
|
fixture.detectChanges();
|
|
expect(selector.choice()).toEqual({ mode: 'local' });
|
|
expect(fixture.nativeElement.querySelector('.cluster-selector__scheduler')).toBeNull();
|
|
});
|
|
|
|
// Fails if the typed address is lost on a round trip, or an empty one is sent as an empty string.
|
|
it('keeps the typed address across modes and drops it when empty', () => {
|
|
const fixture = create();
|
|
const selector = fixture.componentInstance;
|
|
|
|
selector.setMode('remote');
|
|
selector.scheduler.setValue('tcp://equipo:8786');
|
|
selector.setMode('sync');
|
|
selector.setMode('remote');
|
|
expect(selector.choice()).toEqual({ mode: 'remote', scheduler: 'tcp://equipo:8786' });
|
|
|
|
selector.scheduler.setValue(' ');
|
|
expect(selector.choice()).toEqual({ mode: 'remote' });
|
|
});
|
|
});
|