Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

forward primary/warn configuration to the toasts' paper-button #794

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/templates/components/paper-toaster.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{else}}
{{#toast.text}}{{activeToast.text}}{{/toast.text}}
{{#if activeToast.action}}
{{#paper-button accent=activeToast.action.accent onClick=activeToast.action.onClick}}
{{#paper-button primary=activeToast.action.primary accent=activeToast.action.accent warn=activeToast.action.warn onClick=activeToast.action.onClick}}
{{activeToast.action.label}}
{{/paper-button}}
{{/if}}
Expand Down
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/demo/toast.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
(p-row "position" "string" "Possible values are `bottom left` (default), `bottom right`, `top left` and `top right`")
(p-row "toastClass" "string" "CSS class to be applied to the md-toast element")
(p-row "action.label" "string" "The label of the action button.")
(p-row "action.primary" "boolean" "Wether or not you want the action button to be higlighted with the primary color.")
(p-row "action.accent" "boolean" "Wether or not you want the action button to be higlighted with the accent color.")
(p-row "action.warn" "boolean" "Wether or not you want the action button to be higlighted with the warn color.")
(p-row "action.onClick" "function" "This function gets called when the button is pressed.")
)
}}
Expand Down
88 changes: 75 additions & 13 deletions tests/integration/components/paper-toaster-test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,89 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { render, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | paper toaster', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
hooks.beforeEach(function() {
this.set('paperToaster', {
cancelToast() {
}
});
});

test('it can shows an action', async function(assert) {
assert.expect(2);

this.set('paperToaster.activeToast', {
show: true,
position: 'bottom left',
duration: 500,
action: {
label: 'label',
primary: true,
onClick() {
assert.ok(true, 'onClick is called');
}
}
});

await render(hbs`{{paper-toaster paperToaster=paperToaster}}`);

assert.dom('md-toast .md-button').hasText('label');

await click('md-toast .md-button');
});

// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
test('it shows a primary action', async function(assert) {
this.set('paperToaster.activeToast', {
show: true,
position: 'bottom left',
duration: 500,
action: {
label: 'label',
primary: true,
onClick: () => {}
}
});

await render(hbs`{{paper-toaster}}`);
await render(hbs`{{paper-toaster paperToaster=paperToaster}}`);

assert.dom('md-toast .md-button').hasClass('md-primary');
});

test('it shows a accent action', async function(assert) {
this.set('paperToaster.activeToast', {
show: true,
position: 'bottom left',
duration: 500,
action: {
label: 'label',
accent: true,
onClick: () => {}
}
});

await render(hbs`{{paper-toaster paperToaster=paperToaster}}`);

assert.dom('md-toast .md-button').hasClass('md-accent');
});

assert.equal(this.$().text().trim(), '');
test('it shows a warn action', async function(assert) {
this.set('paperToaster.activeToast', {
show: true,
position: 'bottom left',
duration: 500,
action: {
label: 'label',
warn: true,
onClick: () => {}
}
});

// Template block usage:
await render(hbs`
{{#paper-toaster}}
template block text
{{/paper-toaster}}
`);
await render(hbs`{{paper-toaster paperToaster=paperToaster}}`);

assert.equal(this.$().text().trim(), 'template block text');
assert.dom('md-toast .md-button').hasClass('md-warn');
});
});