Skip to content

Commit

Permalink
test(fastboot): Add fastboot tests for cards and atoms (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic authored Mar 7, 2017
1 parent 6a33c74 commit cc6b20c
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/libpeerconnection.log
npm-debug.log*
testem.log
.vscode
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ To pass atom names to the renderer, use the `atomNames` property, e.g.:
{{render-mobiledoc mobiledoc=myMobileDoc atomNames=myAtomNames}}
```

The component will be passed a `payload` and `value` property.

To customize atom lookup, extend the `render-mobiledoc` component and override
its `atomNameToComponentName` method.

Expand Down
4 changes: 4 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/components/test-atom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Component.extend({
});
4 changes: 4 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/components/test-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Component.extend({
});
32 changes: 27 additions & 5 deletions fastboot-tests/fixtures/fastboot/app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import Ember from 'ember';
import {
createSimpleMobiledoc,
createMobiledocWithMarkup
createMobiledocWithMarkup,
createMobiledocWithCard,
createMobiledocWithAtom
} from '../utils/mobiledoc';

const mobiledocs = [
{
name: 'simple',
mobiledoc: createSimpleMobiledoc('hello world')
mobiledoc: createSimpleMobiledoc('hello world'),
cardNames: [],
atomNames: []
},
{
name: 'with-markup',
mobiledoc: createMobiledocWithMarkup('markup text', ['em'])
mobiledoc: createMobiledocWithMarkup('markup text', ['em']),
cardNames: [],
atomNames: []
},
{
name: 'with-link',
mobiledoc: createMobiledocWithMarkup('linked', ['a', ['href', 'http://example.com/with-link']])
mobiledoc: createMobiledocWithMarkup('linked', ['a', ['href', 'http://example.com/with-link']]),
cardNames: [],
atomNames: []
},
{
name: 'with-unsafe-link',
mobiledoc: createMobiledocWithMarkup('linked unsafe', ['a', ['href', 'javascript:evil']])
mobiledoc: createMobiledocWithMarkup('linked unsafe', ['a', ['href', 'javascript:evil']]),
cardNames: [],
atomNames: []
},
{
name: 'card',
mobiledoc: createMobiledocWithCard('test-card'),
cardNames: ['test-card'],
atomNames: []
},
{
name: 'atom',
mobiledoc: createMobiledocWithAtom('test-atom'),
cardNames: [],
atomNames: ['test-atom']
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span class='test-atom-component'>
payload.foo = <span class='test-atom-component-payload'>{{payload.foo}}</span>
value: <span class='test-atom-component-value'>{{value}}</span>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class='test-card-component'>
payload.foo = <span class='test-card-component-payload'>{{payload.foo}}</span>
</div>
2 changes: 1 addition & 1 deletion fastboot-tests/fixtures/fastboot/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div id="mobiledocs">
{{#each mobiledocs as |mobiledocInfo|}}
<div class="render-mobiledoc-wrapper {{mobiledocInfo.name}}">
{{render-mobiledoc mobiledoc=mobiledocInfo.mobiledoc}}
{{render-mobiledoc mobiledoc=mobiledocInfo.mobiledoc cardNames=mobiledocInfo.cardNames atomNames=mobiledocInfo.atomNames}}
</div>
{{/each}}
</div>
48 changes: 48 additions & 0 deletions fastboot-tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,52 @@ describe('index', function() {
});
});

it('renders mobiledoc with card', function() {
let name = 'card';
let componentClassName = 'test-card-component';
let payloadClassName = 'test-card-component-payload';

return this.visit('/')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;
expect(response.statusCode).to.equal(200);

let wrapper = $(`.render-mobiledoc-wrapper.${name}`);
expect(wrapper.length, 'rendered mobiledoc').to.equal(1);

let component = $(`.render-mobiledoc-wrapper.${name} .${componentClassName}`);
expect(component.length, 'rendered component').to.equal(1);

let payload = $(`.render-mobiledoc-wrapper.${name} .${payloadClassName}`);
expect(payload.text().trim(), 'payload').to.equal('bar');
});
});

it('renders mobiledoc with atom', function() {
let name = 'atom';
let componentClassName = 'test-atom-component';
let payloadClassName = 'test-atom-component-payload';
let valueClassName = 'test-atom-component-value';

return this.visit('/')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;
expect(response.statusCode).to.equal(200);

let wrapper = $(`.render-mobiledoc-wrapper.${name}`);
expect(wrapper.length, 'rendered mobiledoc').to.equal(1);

let component = $(`.render-mobiledoc-wrapper.${name} .${componentClassName}`);
expect(component.length, 'rendered component').to.equal(1);

let payload = $(`.render-mobiledoc-wrapper.${name} .${payloadClassName}`);
expect(payload.text().trim(), 'payload').to.equal('bar');

let value = $(`.render-mobiledoc-wrapper.${name} .${valueClassName}`);
expect(value.text().trim(), 'value').to.equal('value');
});
});

});

0 comments on commit cc6b20c

Please sign in to comment.