import expect from 'expect.js'
import {stripIndent} from 'common-tags'
import {create} from 'jss'
import functionPlugin from 'jss-plugin-rule-value-function'

import camelCase from './index'

const settings = {
  createGenerateId: () => rule => `${rule.key}-id`
}

describe('jss-plugin-camel-case', () => {
  let jss

  beforeEach(() => {
    jss = create(settings).use(camelCase())
  })

  describe('regular rule', () => {
    let sheet

    beforeEach(() => {
      sheet = jss.createStyleSheet({
        a: {
          fontSize: '20px',
          zIndex: 1,
          lineHeight: 1.2
        }
      })
    })

    it('should generate correct CSS', () => {
      expect(sheet.toString()).to.be(
        '.a-id {\n  font-size: 20px;\n  z-index: 1;\n  line-height: 1.2;\n}'
      )
    })
  })

  describe('@font-face with array of styles', () => {
    let sheet

    beforeEach(() => {
      sheet = jss.createStyleSheet({
        '@font-face': [
          {
            fontFamily: 'Lato-Light',
            src: 'url("/fonts/Lato-Light.ttf") format("truetype")'
          },
          {
            fontFamily: 'Lato-Bold',
            src: 'url("/fonts/Lato-Bold.ttf") format("truetype")'
          }
        ]
      })
    })

    it('should generate correct CSS', () => {
      expect(sheet.toString()).to.be(
        '@font-face {\n' +
          '  font-family: Lato-Light;\n' +
          '  src: url("/fonts/Lato-Light.ttf") format("truetype");\n' +
          '}\n' +
          '@font-face {\n' +
          '  font-family: Lato-Bold;\n' +
          '  src: url("/fonts/Lato-Bold.ttf") format("truetype");\n' +
          '}'
      )
    })
  })

  describe('fallbacks object', () => {
    let sheet

    beforeEach(() => {
      sheet = jss.createStyleSheet({
        '@font-face': {
          fontFamily: 'MyWebFont',
          fallbacks: {
            fontFamily: 'MyWebFontFallback'
          }
        }
      })
    })

    it('should generate correct CSS', () => {
      expect(sheet.toString()).to.be(
        '@font-face {\n' +
          '  font-family: MyWebFontFallback;\n' +
          '  font-family: MyWebFont;\n' +
          '}'
      )
    })
  })

  describe('fallbacks array', () => {
    let sheet

    beforeEach(() => {
      sheet = jss.createStyleSheet({
        '@font-face': {
          fontFamily: 'MyWebFont',
          fallbacks: [{fontFamily: 'MyWebFontFallback'}]
        }
      })
    })

    it('should generate correct CSS', () => {
      expect(sheet.toString()).to.be(
        '@font-face {\n' +
          '  font-family: MyWebFontFallback;\n' +
          '  font-family: MyWebFont;\n' +
          '}'
      )
    })
  })

  describe('font faces with fallbacks', () => {
    let sheet

    beforeEach(() => {
      sheet = jss.createStyleSheet({
        '@font-face': [
          {
            fontFamily: 'MyWebFont',
            fallbacks: {
              fontFamily: 'MyWebFontFallback'
            }
          }
        ]
      })
    })

    it('should generate correct CSS', () => {
      expect(sheet.toString()).to.be(
        '@font-face {\n' +
          '  font-family: MyWebFontFallback;\n' +
          '  font-family: MyWebFont;\n' +
          '}'
      )
    })
  })

  describe('function values', () => {
    let sheet

    beforeEach(() => {
      const localJss = create(settings).use(functionPlugin(), camelCase())
      sheet = localJss.createStyleSheet({
        a: {
          fontSize: () => 12
        }
      })
    })

    it('should generate correct CSS', () => {
      sheet.update()
      expect(sheet.toString()).to.be(stripIndent`
        .a-id {
          font-size: 12;
        }
      `)
    })
  })
})

@@ -3666,12 +3666,884 @@
  %7D)%0A  %7D)
+%0A%0A  describe('css variables', () =%3E %7B%0A    let localJss%0A    beforeEach(() =%3E %7B%0A      localJss = create(settings).use(functionPlugin(), camelCase())%0A    %7D)%0A%0A    it('with static css variable', () =%3E %7B%0A      const sheet = localJss.createStyleSheet(%7B%0A        a: %7B%0A          '--fontSize': 12,%0A        %7D%0A      %7D)%0A      expect(sheet.toString()).to.be(stripIndent%60%0A        .a-id %7B%0A          --fontSize: 12;%0A        %7D%0A      %60)%0A    %7D)%0A%0A    it('with dynamic css variable', () =%3E %7B%0A      const sheet = localJss.createStyleSheet(%7B%0A        a: %7B%0A          '--fontSize': size =%3E size,%0A        %7D%0A      %7D)%0A%0A      sheet.update(12);%0A%0A      expect(sheet.toString()).to.be(stripIndent%60%0A        .a-id %7B%0A          --fontSize: 12;%0A        %7D%0A      %60)%0A%0A      sheet.update(16);%0A%0A      expect(sheet.toString()).to.be(stripIndent%60%0A        .a-id %7B%0A          --fontSize: 16;%0A        %7D%0A      %60)%0A    %7D)%0A  %7D)
 %0A%7D)%0A

Add tests for css variables in camel case plugins