forked from M3-Academy/desafio-react-e-typescript
feat: adiciona test-ids em menu lateral
This commit is contained in:
parent
d727fdb369
commit
80fda5ebe2
@ -4,7 +4,7 @@ import { NavLink, NavLinkProps } from "react-router-dom";
|
||||
|
||||
interface LiProps extends NavLinkProps {
|
||||
text: string;
|
||||
to: NavLinkProps["to"];
|
||||
to: string;
|
||||
}
|
||||
|
||||
const LiForm = (props: LiProps) => {
|
||||
@ -12,6 +12,7 @@ const LiForm = (props: LiProps) => {
|
||||
return (
|
||||
<li>
|
||||
<NavLink
|
||||
data-testid={geDataTestId(to)}
|
||||
to={to}
|
||||
className={({ isActive }) =>
|
||||
isActive
|
||||
@ -25,4 +26,12 @@ const LiForm = (props: LiProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
function geDataTestId(url: string ) {
|
||||
return "lateralMenu__item" + (isCurrentUrl()) ? "lateralMenu__itemActive" : "";
|
||||
|
||||
function isCurrentUrl() {
|
||||
return window.location.href.includes(url);
|
||||
}
|
||||
}
|
||||
|
||||
export { LiForm };
|
||||
|
@ -10,7 +10,10 @@ const Nav = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<nav className={styles["page-subject__nav"]}>
|
||||
<nav
|
||||
className={styles["page-subject__nav"]}
|
||||
data-testid="lateralMenu__container"
|
||||
>
|
||||
<ul className={styles["page-subject__menu"]}>
|
||||
<LiForm to="/" text="Sobre" />
|
||||
<LiForm to="/forma-de-pagamento" text="Forma de Pagamento" />
|
||||
|
Loading…
Reference in New Issue
Block a user