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

Fix button logic for when noIcon param is set to false #3418

Merged
merged 5 commits into from
Nov 12, 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
2 changes: 1 addition & 1 deletion src/components/button/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{# Default icon position before label #}
{% set iconPosition = "before" %}
{% endif %}
{% elif params.iconType is not defined and params.noIcon is not defined %}
{% elif params.iconType is not defined and params.noIcon != true %}
{% if params.url and params.newWindow %}
{# CTA link opening in new tab #}
{% set iconType = "external-link" %}
Expand Down
24 changes: 24 additions & 0 deletions src/components/button/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,30 @@ describe('macro: button', () => {
expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
});

it('has no icon when noIcon is set to true', () => {
const faker = templateFaker();
const iconsSpy = faker.spy('icon');

faker.renderComponent('button', {
url: 'http://example.com',
noIcon: true,
});

expect(iconsSpy.occurrences[0]).toBeUndefined();
});

it('has default `arrow-next` icon when noIcon is set to false', () => {
const faker = templateFaker();
const iconsSpy = faker.spy('icon');

faker.renderComponent('button', {
url: 'http://example.com',
noIcon: false,
});

expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
});

it('opens in a new window when `newWindow` is `true`', () => {
const $ = cheerio.load(
renderComponent('button', {
Expand Down