const mockedChanged = jest.fn()
jest.mock('../../gulpfile.ts/internal')
jest.mock('gulp')
jest.mock('gulp-changed', () => mockedChanged)
const cb = jest.fn()

import * as gulp from 'gulp'
import * as internal from '../../gulpfile.ts/internal'
import { TIMPLA_DEFAULTS } from '../../gulpfile.ts/lib/TIMPLA_DEFAULTS'
import { IFullTimplaConfig } from '../../gulpfile.ts/lib/TIMPLA_INTERFACES'
import { staticFiles as staticFilesTask } from '../../gulpfile.ts/tasks/staticFiles'
import { clone } from '../helpers'

describe('staticFilesTask', () => {
  it('should correctly pipe assets', () => {
    const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
    if (!conf.staticFiles) {
      return
    }
    const staticFiles = staticFilesTask(conf)
    const spyProjectSrcPath = jest.spyOn(internal, 'projectSrcPath')
    const spyProjectDestPath = jest.spyOn(internal, 'projectDestPath')
    const spyGulpDest = jest.spyOn(gulp, 'dest')

    staticFiles(cb)
    expect(spyProjectSrcPath).toHaveBeenCalledWith(conf.staticFiles.src, '**/*')
    expect(spyProjectDestPath).toHaveBeenCalledWith(conf.staticFiles.dest)
    expect(spyGulpDest).toHaveBeenCalled()
    expect(mockedChanged).toHaveBeenCalled()
  })
  it('should call the gulp cb if the task is disabled', () => {
    const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
    conf.staticFiles = false
    const staticFiles = staticFilesTask(conf)
    staticFiles(cb)
    expect(cb).toHaveBeenCalled()
  })
})
