Skip to content

Commit

Permalink
add some units
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemyslaw Jan Pietrzak committed Oct 1, 2018
1 parent 14fcd7c commit add7c15
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 2 deletions.
14 changes: 14 additions & 0 deletions __tests__/Elements/ATest.re
@@ -0,0 +1,14 @@
open Jest;

open Rembrandt.Elements;

describe("Elements: A", () =>
Expect.(
test("<a /> should create node with url", () =>
(<a href="url" />).attributes
|> List.filter(((_, value)) => value !== "")
|> expect
|> toEqual([("href", "url")])
)
)
);
30 changes: 30 additions & 0 deletions __tests__/Elements/DivTest.re
@@ -0,0 +1,30 @@
open Jest;

open Rembrandt.Elements;

describe("Elements: div", () => {
open Expect;

let filterEmpty = List.filter(((_, value)) => value !== "");

test("<div /> should create node with class", () =>
(<div _class="class-value" />).attributes
|> filterEmpty
|> expect
|> toEqual([("class", "class-value")])
);

test("<div /> should create node with id", () =>
(<div id="id-value" />).attributes
|> filterEmpty
|> expect
|> toEqual([("id", "id-value")])
);

test("<div /> should create node with class & id", () =>
(<div id="id-value" _class="class-value" />).attributes
|> filterEmpty
|> expect
|> toEqual([("id", "id-value"), ("class", "class-value")])
);
});
12 changes: 12 additions & 0 deletions __tests__/Elements/TextTest.re
@@ -0,0 +1,12 @@
open Jest;

open Rembrandt.Elements;

describe("Elements: Text", () => {
open Expect;

test("text should contains string from argument", () => {
text("example text").text |> expect |> toEqual("example text");
});

});
4 changes: 4 additions & 0 deletions bsconfig.json
Expand Up @@ -10,6 +10,10 @@
"dir": "__tests__",
"type": "dev"
},
{
"dir": "__tests__/Elements",
"type": "dev"
},
{
"dir": "examples",
"type": "dev"
Expand Down
2 changes: 1 addition & 1 deletion package-scripts.js
Expand Up @@ -17,7 +17,7 @@ module.exports = {
examples: examples.map(buildExample).join(' && '),
},
test: {
default: 'jest __tests__',
default: 'jest __tests__ __tests__/**/*.bs.js',
e2e: {
script: `node cypress/server/main.js & ./node_modules/.bin/cypress run --spec 'cypress/integration/**'`
}
Expand Down
27 changes: 27 additions & 0 deletions src/Elements/A.re
@@ -0,0 +1,27 @@
open ElementFactory;
open ElementsTypes;
open Dom;

let a =
(
~id="",
~_class="",
~style="",
~key="",
~href="",
~onClick: eventHandler=defaultHandler,
~children,
_rest,
)
: node =>
generateNode(
~name=A,
~id,
~_class,
~style,
~key,
~href,
~onClick,
~children,
(),
);
2 changes: 2 additions & 0 deletions src/Elements/ElementFactory.re
Expand Up @@ -15,6 +15,7 @@ let generateNode =
~value="",
~action="",
~method="",
~href="",
~onClick,
~onChange=defaultHandler,
~onInput=defaultHandler,
Expand All @@ -35,6 +36,7 @@ let generateNode =
("key", key),
("type", _type),
("value", value),
("href", href),
("method", method),
("action", action),
],
Expand Down
3 changes: 2 additions & 1 deletion src/Elements/ElementsTypes.re
Expand Up @@ -6,7 +6,8 @@ type nodeName =
| SPAN
| Button
| Input
| Form;
| Form
| A;

type attributes = list((string, string));

Expand Down
1 change: 1 addition & 0 deletions src/Rembrandt.re
Expand Up @@ -6,6 +6,7 @@ module Elements = {
let input = Input.input;
let text = Text.text;
let form = FormElement.form;
let a = A.a;
}

module Commands = {
Expand Down

0 comments on commit add7c15

Please sign in to comment.