import { Subject , Subscription } from 'rxjs' ; import { DrakeWithModels } from './DrakeWithModels' ; import { filter } from 'rxjs/operators' ; import { EventTypes } from './EventTypes' ; import { DragulaOptions } from './DragulaOptions' ; import { DrakeFactory } from './DrakeFactory' ; export const MockDrakeFactory = new DrakeFactory ( ( containers , options ) => { return new MockDrake ( containers , options ) ; } ) ; /** You can use MockDrake to simulate Drake events.
 *
 * The three methods that actually do anything are `on(event, listener)`,
 * `destroy()`, and a new method, `emit()`. Use `emit()` to manually emit Drake
 * events, and if you injected MockDrake properly with MockDrakeFactory or
 * mocked the DragulaService.find() method, then you can make ng2-dragula think
 * drags and drops are happening.
 *
 * Caveats:
 *
 * 1. YOU MUST MAKE THE DOM CHANGES YOURSELF.
 * 2. REPEAT: YOU MUST MAKE THE DOM CHANGES YOURSELF.
 *    That means `source.removeChild(el)`, and `target.insertBefore(el)`.
 * 3. None of the other methods do anything.
 *    That's ok, because ng2-dragula doesn't use them.
 */ export class MockDrake implements DrakeWithModels { param containers param options param models constructor ( public containers = [ ] , public options = { } , public models ? ) { } dragging : boolean = false ; start ( item ) { this . dragging = true ; } end ( ) { this . dragging = false ; } cancel ( revert ) ; cancel ( ) ; cancel ( revert ? ) { this . dragging = false ; } remove ( ) { this . dragging = false ; } private emitter$ = new Subject < { eventType : EventTypes ; args : any [ ] ; } > ( ) ; private subs = new Subscription ( ) ; on ( event , callback ) { this . subs . add ( this . emitter$ . pipe ( filter ( ( { eventType } ) => eventType === event ) ) . subscribe ( ( { args } ) => { callback ( ... args ) ; } ) ) ; } destroy ( ) { this . subs . unsubscribe ( ) ; } /**
     * This is the most useful method. You can use it to manually fire events that would normally
     * be fired by a real drake.
     *
     * You're likely most interested in firing `drag`, `remove` and `drop`, the three events
     * DragulaService uses to implement [dragulaModel].
     *
     * See https://github.com/bevacqua/dragula#drakeon-events for what you should emit (and in what order).
     *
     * (Note also, firing dropModel and removeModel won't work. You would have to mock DragulaService for that.)
     */ emit ( eventType , ... args ) { this . emitter$ . next ( { eventType , args } ) ; } }