import test from 'ava';
import { css } from 'glamor';
import nested from './';

test('sanity check', (t) => {
  t.is(typeof nested, 'function');
});

test('single level', (t) => {
  t.deepEqual(nested({
    font: {
      family: 'Lato',
      size: '1em',
    },
  }), {
    fontFamily: 'Lato',
    fontSize: '1em',
  });
});

test('recursive levels', (t) => {
  t.deepEqual(nested({
    border: {
      style: 'dashed',
      top: {
        width: '1px',
        color: 'black',
      },
      bottom: {
        width: '2px',
        color: 'red',
      },
    },
  }), {
    borderStyle: 'dashed',
    borderTopWidth: '1px',
    borderTopColor: 'black',
    borderBottomWidth: '2px',
    borderBottomColor: 'red',
  });
});

test('multiple recursive levels', (t) => {
  t.deepEqual(nested({
    border: {
      style: 'dashed',
      top: {
        width: '1px',
        color: 'black',
      },
      bottom: {
        width: '2px',
        color: 'red',
      },
    },
    margin: {
      top: 10,
      bottom: 5,
    },
  }), {
    borderStyle: 'dashed',
    borderTopWidth: '1px',
    borderTopColor: 'black',
    borderBottomWidth: '2px',
    borderBottomColor: 'red',
    marginTop: 10,
    marginBottom: 5,
  });
});

test('with glamor', (t) => {
  t.deepEqual(css({
    background: 'green',
    ...nested({
      border: {
        style: 'dashed',
        top: {
          width: '1px',
          color: 'black',
        },
        bottom: {
          width: '2px',
          color: 'red',
        },
      },
      margin: {
        top: 10,
        bottom: 5,
      },
    }),
  }), css({
    background: 'green',
    borderStyle: 'dashed',
    borderTopWidth: '1px',
    borderTopColor: 'black',
    borderBottomWidth: '2px',
    borderBottomColor: 'red',
    marginTop: 10,
    marginBottom: 5,
  }));
});

test('with glamor (no object-rest-spread)', (t) => {
  t.deepEqual(css(nested({
    background: 'green',
    border: {
      style: 'dashed',
      top: {
        width: '1px',
        color: 'black',
      },
      bottom: {
        width: '2px',
        color: 'red',
      },
    },
    margin: {
      top: 10,
      bottom: 5,
    },
  })), css({
    background: 'green',
    borderStyle: 'dashed',
    borderTopWidth: '1px',
    borderTopColor: 'black',
    borderBottomWidth: '2px',
    borderBottomColor: 'red',
    marginTop: 10,
    marginBottom: 5,
  }));
});

@@ -47,16 +47,53 @@
 lamor';%0A
+import %7B compose %7D from 'lodash/fp';%0A
 import n
@@ -2404,28 +2404,654 @@
 marginBottom: 5,%0A  %7D));%0A%7D);%0A
+%0Atest('with glamor (composed)', (t) =%3E %7B%0A  const ncss = compose(css, nested);%0A  t.deepEqual(ncss(nested(%7B%0A    background: 'green',%0A    border: %7B%0A      style: 'dashed',%0A      top: %7B%0A        width: '1px',%0A        color: 'black',%0A      %7D,%0A      bottom: %7B%0A        width: '2px',%0A        color: 'red',%0A      %7D,%0A    %7D,%0A    margin: %7B%0A      top: 10,%0A      bottom: 5,%0A    %7D,%0A  %7D)), css(%7B // Match without composition%0A    background: 'green',%0A    borderStyle: 'dashed',%0A    borderTopWidth: '1px',%0A    borderTopColor: 'black',%0A    borderBottomWidth: '2px',%0A    borderBottomColor: 'red',%0A    marginTop: 10,%0A    marginBottom: 5,%0A  %7D));%0A%7D);%0A

Add composition test.