Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[AuButton] deprecate the default loading message #497

Merged
merged 1 commit into from
Jul 31, 2024
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
28 changes: 26 additions & 2 deletions addon/components/au-button.gts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from '@glimmer/component';
import { deprecate } from '@ember/debug';
import AuIcon, { type AuIconSignature } from './au-icon';
import { LoadingAnimation } from '../private/components/loading-animation';

Expand Down Expand Up @@ -71,8 +72,31 @@ export default class AuButton extends Component<AuButtonSignature> {
}

get loadingMessage() {
if (this.args.loadingMessage) return this.args.loadingMessage;
else return 'Aan het laden';
if (this.args.loadingMessage) {
return this.args.loadingMessage;
}

deprecate(
`[AuButton] Not providing \`@loadingMessage\` when setting \`@loading\` to \`true\` is deprecated. Add the \`@loadingMessage\` argument explicitly.

Use \`@loadingMessage="Aan het laden"\` to get the same behavior as before.

More info in the migration guide: https://github.com/appuniversum/ember-appuniversum/pull/497

`,
false,
{
id: '@appuniversum/ember-appuniversum.au-button-loading-message',
until: '4.0.0',
for: '@appuniversum/ember-appuniversum',
since: {
available: '3.5.0',
enabled: '3.5.0',
},
},
);

return 'Aan het laden';
}

get isIconLeft() {
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/components/au-button-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
import { tracked } from '@glimmer/tracking';
import { hasDeprecationStartingWith } from 'dummy/tests/helpers/deprecations';

class TestState {
@tracked isDisabled?: boolean;
@tracked isLoading?: boolean;
@tracked loadingMessage?: string;
}

module('Integration | Component | au-button', function (hooks) {
Expand Down Expand Up @@ -65,4 +67,47 @@ module('Integration | Component | au-button', function (hooks) {
await settled();
assert.dom('[data-test-button]').isDisabled();
});

test('the default loading message is deprecated', async function (assert) {
const state = new TestState();
state.isLoading = false;

await render(
<template>
<AuButton
@loading={{state.isLoading}}
@loadingMessage={{state.loadingMessage}}
data-test-button
>
Foo
</AuButton>
</template>,
);

assert.false(
showsDeprecationMessage(),
"it does't show the deprecation if @loading isn't true",
);

state.isLoading = true;
state.loadingMessage = 'Loading';
await settled();
assert.false(
showsDeprecationMessage(),
"it does't show the deprecation if @loadingMessage is set",
);

state.loadingMessage = undefined;
await settled();
assert.true(
showsDeprecationMessage(),
"it shows the deprecation message if @loadingMessage isn't set",
);
});
});

function showsDeprecationMessage() {
return hasDeprecationStartingWith(
'[AuButton] Not providing `@loadingMessage` when setting `@loading` to `true` is deprecated.',
);
}
Loading