# -*- coding: utf-8 -*-
from spinningyogurt.Report import Report


def test_report_template():
    result = Report.generate('example.com', {})
    assert result == '# example.com\n\n## Sitemap\n\n\n## Assets\n\n'


def test_report_sitemap():
    result = Report.generate('example.com', {'/home': {}, '/docs': {}})
    sitemap = result.split('## Sitemap')[1].split('## Assets')[0]
    assert sitemap == '\n\n- /docs\n- /home\n\n'


def test_report_assets():
    data = {
        '/home': {
            'script': ['angular.js'],
            'img': ['flowers.png', 'butterflies.jpg'],
        }
    }
    result = Report.generate('example.com', data)
    assets = result.split('## Assets')[1]
    assets_template = '#### img\n\n- {}\n- {}\n\n#### script\n\n- {}\n\n\n'
    template = '\n\n### /home\n\n{}'.format(assets_template)
    expected = template.format('flowers.png', 'butterflies.jpg', 'angular.js')
    assert assets == expected


def test_report_assets_no_empties():
    data = {
        '/home': {
            'script': []
        }
    }
    result = Report.generate('example.com', data)
    assert 'script' not in result


def test_report_assets_only_lists():
    data = {
        '/home': {
            'attribute': 'argh',
            'parsed': True
        }
    }
    result = Report.generate('example.com', data)
    assert 'attribute' not in result
    assert 'parsed' not in result
