-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
384d201
commit f0e6dbb
Showing
6 changed files
with
238 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 213 additions & 9 deletions
222
tests/integration/components/paper-expansion-panel-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,229 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { find, click, keyEvent } from 'ember-native-dom-helpers'; | ||
|
||
moduleForComponent('paper-expansion-panel', 'Integration | Component | paper expansion panel', { | ||
integration: true | ||
}); | ||
|
||
test('it renders', function(assert) { | ||
test('it renders the collapsed state', function(assert) { | ||
assert.expect(1); | ||
|
||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.on('myAction', function(val) { ... }); | ||
this.render(hbs` | ||
{{#paper-expansion-panel as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
assert.equal(find('.md-button').textContent.trim(), 'collapsed content'); | ||
}); | ||
|
||
test('it renders the expanded state when button is clicked', async function(assert) { | ||
assert.expect(3); | ||
|
||
this.render(hbs` | ||
{{#paper-expansion-panel as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
await click('.md-button'); | ||
|
||
assert.equal(find('md-list-item').textContent.trim(), 'expanded header'); | ||
assert.equal(find('md-expansion-panel-content').textContent.trim(), 'expanded content'); | ||
assert.equal(find('md-expansion-panel-footer').textContent.trim(), 'expanded footer'); | ||
}); | ||
|
||
test('it renders the expanded state when expanded=true', function(assert) { | ||
assert.expect(3); | ||
|
||
this.render(hbs`{{paper-expansion-panel}}`); | ||
this.render(hbs` | ||
{{#paper-expansion-panel expanded=true as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
assert.equal(find('md-list-item').textContent.trim(), 'expanded header'); | ||
assert.equal(find('md-expansion-panel-content').textContent.trim(), 'expanded content'); | ||
assert.equal(find('md-expansion-panel-footer').textContent.trim(), 'expanded footer'); | ||
}); | ||
|
||
assert.equal(this.$().text().trim(), ''); | ||
test('toggling expanded toggles states', function(assert) { | ||
assert.expect(4); | ||
|
||
// Template block usage: | ||
this.render(hbs` | ||
{{#paper-expansion-panel}} | ||
template block text | ||
{{#paper-expansion-panel expanded=expanded as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
assert.equal(this.$().text().trim(), 'template block text'); | ||
assert.equal(find('.md-button').textContent.trim(), 'collapsed content'); | ||
|
||
this.set('expanded', true); | ||
|
||
assert.equal(find('md-list-item').textContent.trim(), 'expanded header'); | ||
assert.equal(find('md-expansion-panel-content').textContent.trim(), 'expanded content'); | ||
assert.equal(find('md-expansion-panel-footer').textContent.trim(), 'expanded footer'); | ||
}); | ||
|
||
test('yielded expand/collapse actions work', async function(assert) { | ||
assert.expect(3); | ||
|
||
this.render(hbs` | ||
{{#paper-expansion-panel as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
<div class="expand" onclick={{action panel.expand}}></div> | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
<div class="collapse" onclick={{action panel.collapse}}></div> | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
assert.ok(find('md-expansion-panel').classList.contains('md-close')); | ||
|
||
await click('.expand'); | ||
assert.ok(find('md-expansion-panel').classList.contains('md-open')); | ||
|
||
await click('.collapse'); | ||
assert.ok(find('md-expansion-panel').classList.contains('md-close')); | ||
}); | ||
|
||
test('onExpandedChange is sent on expand/collapse', async function(assert) { | ||
assert.expect(2); | ||
|
||
this.set('onExpandedChange', (state) => { | ||
assert.ok(state, 'action was sent with true'); | ||
}); | ||
|
||
this.render(hbs` | ||
{{#paper-expansion-panel onExpandedChange=(action onExpandedChange) as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
await click('.md-button'); | ||
|
||
this.set('onExpandedChange', (state) => { | ||
assert.notOk(state, 'action was sent with false'); | ||
}); | ||
|
||
await click('.md-button'); | ||
}); | ||
|
||
test('pressing enter/escape expands/collapses', async function(assert) { | ||
assert.expect(2); | ||
|
||
this.render(hbs` | ||
{{#paper-expansion-panel as |panel|}} | ||
{{#panel.collapsed}} | ||
collapsed content | ||
{{/panel.collapsed}} | ||
{{#panel.expanded as |expanded|}} | ||
{{#expanded.header}} | ||
expanded header | ||
{{/expanded.header}} | ||
{{#expanded.content}} | ||
expanded content | ||
{{/expanded.content}} | ||
{{#expanded.footer}} | ||
expanded footer | ||
{{/expanded.footer}} | ||
{{/panel.expanded}} | ||
{{/paper-expansion-panel}} | ||
`); | ||
|
||
await keyEvent('.md-button', 'keydown', 13); | ||
assert.ok(find('md-expansion-panel').classList.contains('md-open')); | ||
|
||
await keyEvent('.md-button', 'keydown', 27); | ||
assert.ok(find('md-expansion-panel').classList.contains('md-close')); | ||
}); |