Skip to content

Commit 7ad3bd4

Browse files
authored
Merge pull request #11 from DaPulse/component/orr/link-component
feat: add link component
2 parents e3e41e2 + d94dba7 commit 7ad3bd4

File tree

16 files changed

+395
-216
lines changed

16 files changed

+395
-216
lines changed

.circleci/config.yml

Lines changed: 0 additions & 212 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monday-ui-react-core",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Official monday.com UI resources for application development in React.js",
55
"main": "dist/main.js",
66
"scripts": {

plop/component/component-js.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import PropTypes from "prop-types";
23
import cx from "classnames";
34
import "./{{properCase componentName}}.scss";
45

@@ -13,4 +14,7 @@ const {{properCase componentName}} = ({
1314
);
1415
};
1516

17+
{{properCase componentName}}.defaultProps = {};
18+
{{properCase componentName}}.propTypes = {};
19+
1620
export default {{properCase componentName}};

plop/component/component-scss.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@import "../../styles/themes.scss";
22

3-
{{dashCase componentName}}--wrapper {
3+
.{{dashCase componentName}}--wrapper {
44

55
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import cx from "classnames"
3+
import ComponentStateDescription from "../../components/storybook-helpers/component-state-description/ComponentStateDescription";
4+
import "./StoryLine.scss";
5+
6+
const StoryLine = ({ title, children, componentWrapperClass, wrapperClassName }) => {
7+
return (
8+
<>
9+
<ComponentStateDescription title={title} />
10+
<div className={cx(wrapperClassName, "width-35")}>
11+
<div className={componentWrapperClass}>{children}</div>
12+
</div>
13+
</>
14+
);
15+
};
16+
17+
StoryLine.propTypes = {};
18+
StoryLine.defaultProps = {};
19+
export default StoryLine;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.wrapperClassName {
2+
direction: rtl;
3+
}

src/components/Icon/Icon.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
.icon_component {
44
position: relative;
5+
6+
&:before {
7+
text-decoration: none !important;
8+
}
9+
510
&:focus {
611
outline: none;
712
-webkit-text-stroke-width: 1px;

src/components/Link/Link-test.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React from "react";
2+
import { render, fireEvent, cleanup } from "@testing-library/react";
3+
import { expect, sinon } from "../../test/test-helpers";
4+
import Link from "./Link";
5+
6+
describe("<Link />", () => {
7+
const ariaLabel = "Read more about the interesting article";
8+
const text = "Read More";
9+
const href = "https://www.monday.com";
10+
let onClickStub;
11+
beforeEach(() => {
12+
onClickStub = sinon.stub();
13+
});
14+
15+
afterEach(() => {
16+
cleanup();
17+
onClickStub.reset();
18+
});
19+
20+
describe("default props", () => {
21+
it("should open link in a new window", () => {
22+
const { getByText } = render(<Link text={text} />);
23+
const element = getByText(text).closest("a");
24+
expect(element.target).to.equal(Link.target.NEW_WINDOW);
25+
});
26+
it("should open link to have noreferrer attribute", () => {
27+
const { getByText } = render(<Link text={text} />);
28+
const element = getByText(text).closest("a");
29+
expect(element.rel).to.equal("noreferrer");
30+
});
31+
});
32+
33+
it("should call onClick", () => {
34+
const { getByText } = render(<Link text={text} onClick={onClickStub} />);
35+
const element = getByText(text).closest("a");
36+
fireEvent.click(element);
37+
expect(onClickStub).to.be.called;
38+
});
39+
40+
it("should have the correct href", () => {
41+
const { getByText } = render(<Link text={text} href={href} />);
42+
const element = getByText(text).closest("a");
43+
expect(element.href).to.equal(`${href}/`);
44+
});
45+
46+
it("should have the correct target", () => {
47+
const target = Link.target.SELF;
48+
const { getByText } = render(
49+
<Link text={text} href={href} target={target} />
50+
);
51+
const element = getByText(text).closest("a");
52+
expect(element.target).to.equal(target);
53+
});
54+
55+
it("should apply aria label correctly", () => {
56+
const { getByLabelText } = render(
57+
<Link text={text} ariaLabelDescription={ariaLabel} />
58+
);
59+
const element = getByLabelText(ariaLabel);
60+
expect(element).to.be.ok;
61+
});
62+
63+
describe("Icons", () => {
64+
it("Should present the icon", () => {
65+
const { container } = render(
66+
<Link ariaLabelDescription={ariaLabel} iconName="icon-name" />
67+
);
68+
const element = container.querySelector(".icon_component");
69+
expect(element).to.be.ok;
70+
});
71+
72+
it("Icon should be before of the text", () => {
73+
const { container } = render(
74+
<Link
75+
text={text}
76+
ariaLabelDescription={ariaLabel}
77+
iconName="icon-name"
78+
/>
79+
);
80+
const textElement = container.querySelector(".monday-style-link--text");
81+
const iconElement = container.querySelector(".icon_component");
82+
const textBox = textElement.getBoundingClientRect();
83+
const iconBox = iconElement.getBoundingClientRect();
84+
expect(textBox.left > iconBox.left).to.equal(true);
85+
});
86+
87+
it("Icon should be after of the text", () => {
88+
const { container } = render(
89+
<Link
90+
text={text}
91+
ariaLabelDescription={ariaLabel}
92+
iconName="icon-name"
93+
iconPosition={Link.position.END}
94+
/>
95+
);
96+
const textElement = container.querySelector(".monday-style-link--text");
97+
const iconElement = container.querySelector(".icon_component");
98+
const textBox = textElement.getBoundingClientRect();
99+
const iconBox = iconElement.getBoundingClientRect();
100+
expect(textBox.left < iconBox.left).to.equal(true);
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)