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

[PLAY-259] Typescript Conversion: Home Address Street #2042

Merged
merged 3 commits into from
Sep 19, 2022
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import React from 'react'
import classnames from 'classnames'

import { joinPresent, titleize } from '../utilities/text'
import { globalProps } from '../utilities/globalProps'

import Body from '../pb_body/_body'
import Hashtag from '../pb_hashtag/_hashtag'
import Title from '../pb_title/_title'
import { buildAriaProps, buildDataProps } from '../utilities/props'

type HomeAddressStreetProps = {
aria?: { [key: string]: string },
address: string,
addressCont: string,
city: string,
className?: string,
data?: { [key: string]: string },
dark?: boolean,
emphasis: "street" | "city",
homeId: string,
houseStyle: string,
homeUrl: string,
newWindow: boolean,
state: string,
zipcode: string,
territory: string,
}

const HomeAddressStreet = (props: HomeAddressStreetProps) => {
const {
address,
addressCont,
aria = {},
city,
className,
data = {},
dark = false,
emphasis = 'street',
homeId,
homeUrl,
newWindow,
houseStyle,
state,
zipcode,
territory,
} = props

const classes = (className: string, dark: boolean) =>
classnames(
{
'pb_home_address_street': !dark,
'pb_home_address_street_dark': dark,
},
globalProps(props),
className
)

const dataProps: { [key: string]: any } = buildDataProps(data)
const ariaProps: { [key: string]: any } = buildAriaProps(aria)

return (
<div className={classes(className, dark)} {...ariaProps} {...dataProps}>
{emphasis == 'street' &&
<div>
<Title
className="pb_home_address_street_address"
dark={dark}
size={4}
>
{joinPresent([titleize(address), houseStyle], ' · ')}
</Title>
<Title
className="pb_home_address_street_address"
dark={dark}
size={4}
>
{titleize(addressCont)}
</Title>
<Body color="light">
{`${titleize(city)}, ${state} ${zipcode}`}
</Body>
</div>
}
{emphasis == 'city' &&
<div>
<Body color="light">
{joinPresent([titleize(address), houseStyle], ' · ')}
</Body>
<Body color="light">{titleize(addressCont)}</Body>
<div>
<Title
className="pb_home_address_street_address"
dark={dark}
size={4}
tag="span"
>
{`${titleize(city)}, ${state}`}
</Title>
<Body
color="light"
tag="span"
>
{` ${zipcode}`}
</Body>
</div>
</div>
}
{homeId &&
<Hashtag
classname="home-hashtag"
dark={dark}
newWindow={newWindow}
text={homeId}
type="home"
url={homeUrl || '#'}
/>
}
<Body
color="light"
tag="span"
>
<small>{territory}</small>
</Body>
</div>
)
}

export default HomeAddressStreet
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const HomeAddressStreetDefault = (props) => {
address="70 Prospect Ave"
addressCont="Apt M18"
city="West Chester"
homeId={8250263}
homeId="8250263"
homeUrl="https://powerhrg.com/"
houseStyle="Colonial"
state="PA"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const HomeAddressStreetEmphasis = (props) => {
address="70 Prospect Ave"
addressCont="Apt M18"
city="West Chester"
homeId={8250263}
homeId="8250263"
homeUrl="https://powerhrg.com/"
houseStyle="Colonial"
state="PA"
Expand All @@ -24,7 +24,7 @@ const HomeAddressStreetEmphasis = (props) => {
addressCont="Apt M18"
city="West Chester"
emphasis="city"
homeId={8250263}
homeId="8250263"
homeUrl="https://powerhrg.com/"
houseStyle="Colonial"
state="PA"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react'
import { render, screen, cleanup } from "../utilities/test-utils";

import { HomeAddressStreet } from "..";


const testId = "primary-test"
const address = "70 Prospect Ave"
const city = "West Chester"
const homeId = "8250263"

function HomeAdressStreetTest(props) {
return (
<HomeAddressStreet
address={address}
addressCont="Apt M18"
city={city}
data={{ testid: testId }}
homeId={homeId}
homeUrl="https://powerhrg.com/"
houseStyle="Colonial"
state="PA"
territory="PHL"
zipcode="19382"
{...props}
/>
);
}

test("renders the component", () => {
render(<HomeAdressStreetTest />);
const kit = screen.getByTestId("primary-test");
expect(kit).toBeInTheDocument();
expect(kit).toHaveClass("pb_home_address_street");

cleanup()
});

test("emphasize street by not setting a prop", () => {
const { container } = render(<HomeAdressStreetTest />);
expect(container.getElementsByClassName("pb_title_kit_size_4 pb_home_address_street_address")[0]).toHaveTextContent(address);

cleanup()
});

test("emphasize city", () => {
const { container } = render(<HomeAdressStreetTest emphasis="city" />);
expect(container.getElementsByClassName("pb_title_kit_size_4 pb_home_address_street_address")[0]).toHaveTextContent(city);

cleanup()
});

test("renders the hashtag kit", () => {
const { container } = render(<HomeAdressStreetTest />);
expect(container.getElementsByClassName("pb_hashtag_kit")[0]).toBeInTheDocument;
expect(container.getElementsByClassName("pb_hashtag_kit")[0].firstChild).toHaveAttribute("href");
expect(container.getElementsByClassName("pb_hashtag_kit")[0].firstChild).toHaveTextContent(homeId);

cleanup()
});
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/utilities/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const titleize = (sentence: string): string => (

const notEmpty = (value: string | Record<string, unknown>): boolean => !isEmpty(value)

export const joinPresent = (array: [], separator: string): string => (
export const joinPresent = (array: string[], separator: string): string => (
filter(array, notEmpty).join(separator)
)

Expand Down