-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): restore look&feel of HTML
a
tags pretending to look as bu…
…ttons (#1536) #1494 introduced a typo when migrating former and temporary _src/components/core/ButtonLink_ to TypeScript, making it to stop looking as a button. Although the fix was ridicously simple, just adding the missing `e` to `scondary`, this PR takes the opportunity for improving the whole component, getting ride of a pending FIXME, using a better name for it, and also adding simple but useful unit tests.
- Loading branch information
Showing
12 changed files
with
164 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
------------------------------------------------------------------- | ||
Tue Aug 13 14:57:21 UTC 2024 - David Diaz <[email protected]> | ||
|
||
- Allow links look like buttons again (gh#openSUSE/agama#1536). | ||
|
||
------------------------------------------------------------------- | ||
Fri Jul 26 11:42:05 UTC 2024 - Imobach Gonzalez Sosa <[email protected]> | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { screen } from "@testing-library/react"; | ||
import { installerRender } from "~/test-utils"; | ||
import { Link } from "~/components/core"; | ||
|
||
describe("Link", () => { | ||
it("renders an HTML `a` tag with the `href` attribute set to given `to` prop", () => { | ||
installerRender(<Link to="somewhere">Agama Link</Link>); | ||
const link = screen.getByRole("link", { name: "Agama Link" }) as HTMLLinkElement; | ||
// NOTE: Link uses ReactRouter#useHref hook which is mocked in test-utils.js | ||
// TODO: Not using toHaveAttribute("href", "somewhere") because some weird problems at CI | ||
expect(link.href).toContain("somewhere"); | ||
}); | ||
|
||
it("renders it as primary when either, using a truthy `isPrimary` prop or `variant` is set to primary", () => { | ||
const { rerender } = installerRender(<Link to="somewhere">Agama Link</Link>); | ||
const link = screen.getByRole("link", { name: "Agama Link" }); | ||
|
||
expect(link.classList.contains("pf-m-primary")).not.toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" isPrimary> | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-primary")).toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" isPrimary={false}> | ||
{" "} | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-primary")).not.toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" variant="primary"> | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-primary")).toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" isPrimary={false} variant="primary"> | ||
{" "} | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-primary")).toBe(true); | ||
}); | ||
|
||
it("renders it as secondary when neither is given, a truthy `isPrimary` nor `variant`", () => { | ||
const { rerender } = installerRender(<Link to="somewhere">Agama Link</Link>); | ||
const link = screen.getByRole("link", { name: "Agama Link" }); | ||
|
||
expect(link.classList.contains("pf-m-secondary")).toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" isPrimary={false}> | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-secondary")).toBe(true); | ||
|
||
rerender( | ||
// Unexpected, but possible since isPrimary is just a "helper" | ||
<Link to="somewhere" isPrimary={false} variant="primary"> | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-secondary")).not.toBe(true); | ||
|
||
rerender( | ||
<Link to="somewhere" variant="link"> | ||
Agama Link | ||
</Link>, | ||
); | ||
expect(link.classList.contains("pf-m-secondary")).not.toBe(true); | ||
}); | ||
}); |
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
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
Oops, something went wrong.