|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs-extra'); |
| 5 | +const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); |
| 6 | + |
| 7 | +let setupTestHooks = blueprintHelpers.setupTestHooks; |
| 8 | +let emberNew = blueprintHelpers.emberNew; |
| 9 | +let emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; |
| 10 | + |
| 11 | +const expect = require('ember-cli-blueprint-test-helpers/chai').expect; |
| 12 | +const file = require('ember-cli-blueprint-test-helpers/chai').file; |
| 13 | + |
| 14 | +describe('Blueprints | non-pods docs page test', function() { |
| 15 | + setupTestHooks(this); |
| 16 | + |
| 17 | + it('it generates a docs page and updates router with no docs.hbs present', function() { |
| 18 | + return emberNew({ target: 'addon' }).then(() => { |
| 19 | + return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => { |
| 20 | + expect(_file('tests/dummy/app/templates/docs/foo-bar.md')) |
| 21 | + .to.exist.to.contain('# Foo bar') |
| 22 | + .to.contain('Foo bar content'); |
| 23 | + |
| 24 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 25 | + "this.route('foo-bar');" |
| 26 | + ); |
| 27 | + |
| 28 | + expect(file('tests/dummy/app/templates/docs.hbs')).to.not.exist; |
| 29 | + }); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() { |
| 34 | + return emberNew({ target: 'addon' }) |
| 35 | + .then(() => |
| 36 | + copyFixtureFile( |
| 37 | + getFixturePath('docs.hbs'), |
| 38 | + 'tests/dummy/app/templates/docs.hbs' |
| 39 | + ) |
| 40 | + ) |
| 41 | + .then(() => { |
| 42 | + return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => { |
| 43 | + expect(_file('tests/dummy/app/templates/docs/foo-bar.md')) |
| 44 | + .to.exist.to.contain('# Foo bar') |
| 45 | + .to.contain('Foo bar content'); |
| 46 | + |
| 47 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 48 | + "this.route('foo-bar');" |
| 49 | + ); |
| 50 | + |
| 51 | + expect( |
| 52 | + file('tests/dummy/app/templates/docs.hbs') |
| 53 | + ).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}'); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() { |
| 59 | + return emberNew({ target: 'addon' }) |
| 60 | + .then(() => |
| 61 | + copyFixtureFile( |
| 62 | + getFixturePath('docs-subnav.hbs'), |
| 63 | + 'tests/dummy/app/templates/docs.hbs' |
| 64 | + ) |
| 65 | + ) |
| 66 | + .then(() => { |
| 67 | + return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => { |
| 68 | + expect(_file('tests/dummy/app/templates/docs/foo-bar.md')) |
| 69 | + .to.exist.to.contain('# Foo bar') |
| 70 | + .to.contain('Foo bar content'); |
| 71 | + |
| 72 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 73 | + "this.route('foo-bar');" |
| 74 | + ); |
| 75 | + |
| 76 | + expect( |
| 77 | + file('tests/dummy/app/templates/docs.hbs') |
| 78 | + ).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}'); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +describe('Blueprints | pods docs page test', function() { |
| 85 | + setupTestHooks(this); |
| 86 | + |
| 87 | + it('it generates a docs page and updates router with no docs.hbs present', function() { |
| 88 | + return emberNew({ target: 'addon', pod: true }).then(() => { |
| 89 | + return emberGenerateDestroy(['docs-page', 'foo-bar', '--pod'], _file => { |
| 90 | + expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md')) |
| 91 | + .to.exist.to.contain('# Foo bar') |
| 92 | + .to.contain('Foo bar content'); |
| 93 | + |
| 94 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 95 | + "this.route('foo-bar');" |
| 96 | + ); |
| 97 | + |
| 98 | + expect(file('tests/dummy/app/pods/docs/template.hbs')).to.not.exist; |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() { |
| 104 | + return emberNew({ target: 'addon', pod: true }) |
| 105 | + .then(() => |
| 106 | + copyFixtureFile( |
| 107 | + getFixturePath('docs.hbs'), |
| 108 | + 'tests/dummy/app/pods/docs/template.hbs' |
| 109 | + ) |
| 110 | + ) |
| 111 | + .then(() => { |
| 112 | + return emberGenerateDestroy( |
| 113 | + ['docs-page', 'foo-bar', '--pod'], |
| 114 | + _file => { |
| 115 | + expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md')) |
| 116 | + .to.exist.to.contain('# Foo bar') |
| 117 | + .to.contain('Foo bar content'); |
| 118 | + |
| 119 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 120 | + "this.route('foo-bar');" |
| 121 | + ); |
| 122 | + |
| 123 | + expect( |
| 124 | + file('tests/dummy/app/pods/docs/template.hbs') |
| 125 | + ).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}'); |
| 126 | + } |
| 127 | + ); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() { |
| 132 | + return emberNew({ target: 'addon', pod: true }) |
| 133 | + .then(() => |
| 134 | + copyFixtureFile( |
| 135 | + getFixturePath('docs-subnav.hbs'), |
| 136 | + 'tests/dummy/app/pods/docs/template.hbs' |
| 137 | + ) |
| 138 | + ) |
| 139 | + .then(() => { |
| 140 | + return emberGenerateDestroy( |
| 141 | + ['docs-page', 'foo-bar', '--pod'], |
| 142 | + _file => { |
| 143 | + expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md')) |
| 144 | + .to.exist.to.contain('# Foo bar') |
| 145 | + .to.contain('Foo bar content'); |
| 146 | + |
| 147 | + expect(file('tests/dummy/app/router.js')).to.contain( |
| 148 | + "this.route('foo-bar');" |
| 149 | + ); |
| 150 | + |
| 151 | + expect( |
| 152 | + file('tests/dummy/app/pods/docs/template.hbs') |
| 153 | + ).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}'); |
| 154 | + } |
| 155 | + ); |
| 156 | + }); |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
| 160 | +function copyFixtureFile(src, dest) { |
| 161 | + return fs.copy(src, path.join(process.cwd(), dest)); |
| 162 | +} |
| 163 | + |
| 164 | +function getFixturePath(fixtureRelativePath) { |
| 165 | + const fixturesPath = path.join(__dirname, '../..', 'fixtures', 'blueprints'); |
| 166 | + |
| 167 | + return path.join(fixturesPath, fixtureRelativePath); |
| 168 | +} |
0 commit comments