Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit 1b51e5f

Browse files
committed
Add tests.
1 parent 8706758 commit 1b51e5f

File tree

4 files changed

+108
-58
lines changed

4 files changed

+108
-58
lines changed

Tags/__tests__/Tags_enzyme-tests.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
import React from 'react';
2-
import enzyme, { shallow } from 'enzyme'
3-
import Adapter from 'enzyme-adapter-react-16'
1+
import React from "react";
2+
import enzyme, { shallow, mount } from "enzyme";
3+
import Adapter from "enzyme-adapter-react-16";
44

5-
import Tags from '../../';
5+
import Tags from "../../";
66

77
enzyme.configure({ adapter: new Adapter() });
88

9-
describe('Tags', () => {
10-
describe('TextInput', () => {
11-
describe('onChangeText', () => {
12-
it('should add a new tag when a space, or comma is detected', () => {
9+
describe("Tags", () => {
10+
describe("TextInput", () => {
11+
describe("onChangeText", () => {
12+
it("should add a new tag when a space, or comma is detected", () => {
1313
const onChangeTags = jest.fn();
14-
const wrapper = shallow(<Tags onChangeTags={onChangeTags} />)
15-
.find('TextInput');
16-
wrapper.simulate('ChangeText', 'dog ');
17-
expect(onChangeTags.mock.calls).toEqual([[[ 'dog' ]]]);
18-
wrapper.simulate('ChangeText', 'cat,');
19-
expect(onChangeTags.mock.calls).toEqual([
20-
[[ 'dog' ]],
21-
[[ 'dog', 'cat' ]],
22-
]);
14+
const wrapper = shallow(<Tags onChangeTags={onChangeTags} />).find(
15+
"TextInput"
16+
);
17+
wrapper.simulate("ChangeText", "dog ");
18+
expect(onChangeTags.mock.calls).toEqual([[["dog"]]]);
19+
wrapper.simulate("ChangeText", "cat,");
20+
expect(onChangeTags.mock.calls).toEqual([[["dog"]], [["dog", "cat"]]]);
2321
});
2422

25-
it('should remove a tag when the text is empty', () => {
23+
it("should remove a tag when the text is empty", () => {
2624
const onChangeTags = jest.fn();
27-
const wrapper = shallow(<Tags onChangeTags={onChangeTags} />)
28-
.find('TextInput');
29-
wrapper.simulate('ChangeText', 'dog ');
30-
expect(onChangeTags.mock.calls).toEqual([[[ 'dog' ]]]);
31-
wrapper.simulate('ChangeText', '');
32-
expect(onChangeTags.mock.calls).toEqual([
33-
[[ 'dog' ]],
34-
[[]],
35-
]);
25+
const wrapper = shallow(<Tags onChangeTags={onChangeTags} />).find(
26+
"TextInput"
27+
);
28+
wrapper.simulate("ChangeText", "dog ");
29+
expect(onChangeTags.mock.calls).toEqual([[["dog"]]]);
30+
wrapper.simulate("ChangeText", "");
31+
expect(onChangeTags.mock.calls).toEqual([[["dog"]], [[]]]);
32+
});
33+
34+
it("text input should not be available if it's readyonly", () => {
35+
const wrapper = shallow(<Tags readonly />).find("TextInput");
36+
expect(wrapper.length).toEqual(0);
37+
});
38+
39+
it("textinput should dissapear after maxNumberOfTags is reached", () => {
40+
const wrapper = shallow(
41+
<Tags initialTags={["love"]} maxNumberOfTags={2} />
42+
);
43+
wrapper.find("TextInput").simulate("ChangeText", "dog ");
44+
expect(wrapper.find("TextInput").length).toEqual(0);
3645
});
3746
});
3847
});

Tags/__tests__/__snapshots__/Tags-tests.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports[`Tags should render props correctly 1`] = `
4343
"paddingRight": 12,
4444
}
4545
}
46-
testID={undefined}
46+
testID="tag"
4747
tvParallaxProperties={undefined}
4848
>
4949
<Text
@@ -92,7 +92,7 @@ exports[`Tags should render props correctly 1`] = `
9292
"paddingRight": 12,
9393
}
9494
}
95-
testID={undefined}
95+
testID="tag"
9696
tvParallaxProperties={undefined}
9797
>
9898
<Text
@@ -141,7 +141,7 @@ exports[`Tags should render props correctly 1`] = `
141141
"paddingRight": 12,
142142
}
143143
}
144-
testID={undefined}
144+
testID="tag"
145145
tvParallaxProperties={undefined}
146146
>
147147
<Text

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"devDependencies": {
2121
"babel-jest": "^22.4.3",
2222
"babel-preset-react-native": "^4.0.0",
23-
"enzyme": "^3.3.0",
24-
"enzyme-adapter-react-16": "^1.1.1",
23+
"enzyme": "^3.4.1",
24+
"enzyme-adapter-react-16": "^1.2.0",
2525
"jest": "^22.4.3",
2626
"prop-types": "^15.6.1",
2727
"react": "16.3.1",

yarn.lock

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,14 @@ array-unique@^0.3.2:
602602
version "0.3.2"
603603
resolved "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
604604

605+
array.prototype.flat@^1.2.1:
606+
version "1.2.1"
607+
resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.2.1.tgz#812db8f02cad24d3fab65dd67eabe3b8903494a4"
608+
dependencies:
609+
define-properties "^1.1.2"
610+
es-abstract "^1.10.0"
611+
function-bind "^1.1.1"
612+
605613
arrify@^1.0.1:
606614
version "1.0.1"
607615
resolved "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
@@ -1927,40 +1935,42 @@ envinfo@^3.0.0:
19271935
os-name "^2.0.1"
19281936
which "^1.2.14"
19291937

1930-
enzyme-adapter-react-16@^1.1.1:
1931-
version "1.1.1"
1932-
resolved "https://registry.npmjs.org/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.1.1.tgz#a8f4278b47e082fbca14f5bfb1ee50ee650717b4"
1938+
enzyme-adapter-react-16@^1.2.0:
1939+
version "1.2.0"
1940+
resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.2.0.tgz#c6e80f334e0a817873262d7d01ee9e4747e3c97e"
19331941
dependencies:
1934-
enzyme-adapter-utils "^1.3.0"
1935-
lodash "^4.17.4"
1936-
object.assign "^4.0.4"
1942+
enzyme-adapter-utils "^1.5.0"
1943+
function.prototype.name "^1.1.0"
1944+
object.assign "^4.1.0"
19371945
object.values "^1.0.4"
1938-
prop-types "^15.6.0"
1946+
prop-types "^15.6.2"
1947+
react-is "^16.4.2"
19391948
react-reconciler "^0.7.0"
19401949
react-test-renderer "^16.0.0-0"
19411950

1942-
enzyme-adapter-utils@^1.3.0:
1943-
version "1.3.0"
1944-
resolved "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.3.0.tgz#d6c85756826c257a8544d362cc7a67e97ea698c7"
1951+
enzyme-adapter-utils@^1.5.0:
1952+
version "1.5.0"
1953+
resolved "https://registry.yarnpkg.com/enzyme-adapter-utils/-/enzyme-adapter-utils-1.5.0.tgz#a020ab3ae79bb1c85e1d51f48f35e995e0eed810"
19451954
dependencies:
1946-
lodash "^4.17.4"
1947-
object.assign "^4.0.4"
1948-
prop-types "^15.6.0"
1955+
function.prototype.name "^1.1.0"
1956+
object.assign "^4.1.0"
1957+
prop-types "^15.6.2"
19491958

1950-
enzyme@^3.3.0:
1951-
version "3.3.0"
1952-
resolved "https://registry.npmjs.org/enzyme/-/enzyme-3.3.0.tgz#0971abd167f2d4bf3f5bd508229e1c4b6dc50479"
1959+
enzyme@^3.4.1:
1960+
version "3.4.1"
1961+
resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-3.4.1.tgz#d305af5bdb30b8aca56d199110421588c670ea0e"
19531962
dependencies:
1963+
array.prototype.flat "^1.2.1"
19541964
cheerio "^1.0.0-rc.2"
1955-
function.prototype.name "^1.0.3"
1956-
has "^1.0.1"
1965+
function.prototype.name "^1.1.0"
1966+
has "^1.0.3"
19571967
is-boolean-object "^1.0.0"
1958-
is-callable "^1.1.3"
1968+
is-callable "^1.1.4"
19591969
is-number-object "^1.0.3"
19601970
is-string "^1.0.4"
19611971
is-subset "^0.1.1"
19621972
lodash "^4.17.4"
1963-
object-inspect "^1.5.0"
1973+
object-inspect "^1.6.0"
19641974
object-is "^1.0.1"
19651975
object.assign "^4.1.0"
19661976
object.entries "^1.0.4"
@@ -1981,6 +1991,16 @@ errorhandler@^1.5.0:
19811991
accepts "~1.3.3"
19821992
escape-html "~1.0.3"
19831993

1994+
es-abstract@^1.10.0:
1995+
version "1.12.0"
1996+
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165"
1997+
dependencies:
1998+
es-to-primitive "^1.1.1"
1999+
function-bind "^1.1.1"
2000+
has "^1.0.1"
2001+
is-callable "^1.1.3"
2002+
is-regex "^1.0.4"
2003+
19842004
es-abstract@^1.5.1, es-abstract@^1.6.1:
19852005
version "1.11.0"
19862006
resolved "https://registry.npmjs.org/es-abstract/-/es-abstract-1.11.0.tgz#cce87d518f0496893b1a30cd8461835535480681"
@@ -2381,9 +2401,9 @@ function-bind@^1.0.2, function-bind@^1.1.0, function-bind@^1.1.1:
23812401
version "1.1.1"
23822402
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
23832403

2384-
function.prototype.name@^1.0.3:
2404+
function.prototype.name@^1.1.0:
23852405
version "1.1.0"
2386-
resolved "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.0.tgz#8bd763cc0af860a859cc5d49384d74b932cd2327"
2406+
resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.0.tgz#8bd763cc0af860a859cc5d49384d74b932cd2327"
23872407
dependencies:
23882408
define-properties "^1.1.2"
23892409
function-bind "^1.1.1"
@@ -2605,6 +2625,12 @@ has@^1.0.1:
26052625
dependencies:
26062626
function-bind "^1.0.2"
26072627

2628+
has@^1.0.3:
2629+
version "1.0.3"
2630+
resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
2631+
dependencies:
2632+
function-bind "^1.1.1"
2633+
26082634
hawk@3.1.3, hawk@~3.1.3:
26092635
version "3.1.3"
26102636
resolved "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
@@ -2791,6 +2817,10 @@ is-callable@^1.1.1, is-callable@^1.1.3:
27912817
version "1.1.3"
27922818
resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
27932819

2820+
is-callable@^1.1.4:
2821+
version "1.1.4"
2822+
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
2823+
27942824
is-ci@^1.0.10:
27952825
version "1.1.0"
27962826
resolved "https://registry.npmjs.org/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
@@ -4120,9 +4150,9 @@ object-copy@^0.1.0:
41204150
define-property "^0.2.5"
41214151
kind-of "^3.0.3"
41224152

4123-
object-inspect@^1.5.0:
4124-
version "1.5.0"
4125-
resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.5.0.tgz#9d876c11e40f485c79215670281b767488f9bfe3"
4153+
object-inspect@^1.6.0:
4154+
version "1.6.0"
4155+
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.6.0.tgz#c70b6cbf72f274aab4c34c0c82f5167bf82cf15b"
41264156

41274157
object-is@^1.0.1:
41284158
version "1.0.1"
@@ -4138,7 +4168,7 @@ object-visit@^1.0.0:
41384168
dependencies:
41394169
isobject "^3.0.0"
41404170

4141-
object.assign@^4.0.4, object.assign@^4.1.0:
4171+
object.assign@^4.1.0:
41424172
version "4.1.0"
41434173
resolved "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da"
41444174
dependencies:
@@ -4466,6 +4496,13 @@ prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1:
44664496
loose-envify "^1.3.1"
44674497
object-assign "^4.1.1"
44684498

4499+
prop-types@^15.6.2:
4500+
version "15.6.2"
4501+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
4502+
dependencies:
4503+
loose-envify "^1.3.1"
4504+
object-assign "^4.1.1"
4505+
44694506
pseudomap@^1.0.2:
44704507
version "1.0.2"
44714508
resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
@@ -4551,6 +4588,10 @@ react-is@^16.3.1:
45514588
version "16.3.1"
45524589
resolved "https://registry.npmjs.org/react-is/-/react-is-16.3.1.tgz#ee66e6d8283224a83b3030e110056798488359ba"
45534590

4591+
react-is@^16.4.2:
4592+
version "16.4.2"
4593+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.2.tgz#84891b56c2b6d9efdee577cc83501dfc5ecead88"
4594+
45544595
react-native@^0.55.2:
45554596
version "0.55.2"
45564597
resolved "https://registry.npmjs.org/react-native/-/react-native-0.55.2.tgz#80d26a3f4193ebd1fd49a4859011c501b0ca3bab"

0 commit comments

Comments
 (0)