Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
"use strict";
13
14
var React;
15
var ReactTransitionChildMapping;
16
17
describe('ReactTransitionChildMapping', function() {
18
beforeEach(function() {
19
React = require('React');
20
ReactTransitionChildMapping = require('ReactTransitionChildMapping');
21
});
22
23
it('should support getChildMapping', function() {
24
var oneone = <div key="oneone" />;
25
var onetwo = <div key="onetwo" />;
26
var one = <div key="one">{oneone}{onetwo}</div>;
27
var two = <div key="two" />;
28
var component = <div>{one}{two}</div>;
29
expect(
30
ReactTransitionChildMapping.getChildMapping(component.props.children)
31
).toEqual({
32
'.$one': one,
33
'.$two': two
34
});
35
});
36
37
it('should support mergeChildMappings for adding keys', function() {
38
var prev = {
39
one: true,
40
two: true
41
};
42
var next = {
43
one: true,
44
two: true,
45
three: true
46
};
47
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
48
one: true,
49
two: true,
50
three: true
51
});
52
});
53
54
it('should support mergeChildMappings for removing keys', function() {
55
var prev = {
56
one: true,
57
two: true,
58
three: true
59
};
60
var next = {
61
one: true,
62
two: true
63
};
64
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
65
one: true,
66
two: true,
67
three: true
68
});
69
});
70
71
it('should support mergeChildMappings for adding and removing', function() {
72
var prev = {
73
one: true,
74
two: true,
75
three: true
76
};
77
var next = {
78
one: true,
79
two: true,
80
four: true
81
};
82
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
83
one: true,
84
two: true,
85
three: true,
86
four: true
87
});
88
});
89
90
it('should reconcile overlapping insertions and deletions', function() {
91
var prev = {
92
one: true,
93
two: true,
94
four: true,
95
five: true
96
};
97
var next = {
98
one: true,
99
two: true,
100
three: true,
101
five: true
102
};
103
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
104
one: true,
105
two: true,
106
three: true,
107
four: true,
108
five: true
109
});
110
});
111
112
it('should support mergeChildMappings with undefined input', function() {
113
var prev = {
114
one: true,
115
two: true
116
};
117
118
var next = undefined;
119
120
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
121
one: true,
122
two: true
123
});
124
125
prev = undefined;
126
127
next = {
128
three: true,
129
four: true
130
};
131
132
expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({
133
three: true,
134
four: true
135
});
136
});
137
});
138
139