Skip to content

Commit 1e8f27b

Browse files
Merge pull request #89 from SAP/calendar-unit-test-fix
fix calendar unit test failing
2 parents fe7de54 + 63e0b68 commit 1e8f27b

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

src/Calendar/Calendar.test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ describe('<Calendar />', () => {
151151
.at(0)
152152
.simulate('click');
153153
let newDateDisplayed = wrapper.state('currentDateDisplayed');
154+
currentDateDisplayed.setMonth(currentDateDisplayed.getMonth() - 1);
154155

155156
expect(newDateDisplayed.getMonth()).toEqual(
156-
currentDateDisplayed.getMonth() - 1
157+
currentDateDisplayed.getMonth()
157158
);
158159

159160
// previous button when year shown
@@ -175,9 +176,9 @@ describe('<Calendar />', () => {
175176
.simulate('click');
176177

177178
let newYearDisplayed = wrapper.state('currentYear');
178-
179+
currentYearDisplayed.setFullYear(currentYearDisplayed.getFullYear() - 12);
179180
expect(newYearDisplayed.getFullYear()).toEqual(
180-
currentYearDisplayed.getFullYear() - 12
181+
currentYearDisplayed.getFullYear()
181182
);
182183
});
183184

@@ -193,8 +194,10 @@ describe('<Calendar />', () => {
193194
.simulate('click');
194195
let newDateDisplayed = wrapper.state('currentDateDisplayed');
195196

197+
currentDateDisplayed.setMonth(currentDateDisplayed.getMonth() + 1);
198+
196199
expect(newDateDisplayed.getMonth()).toEqual(
197-
currentDateDisplayed.getMonth() + 1
200+
currentDateDisplayed.getMonth()
198201
);
199202

200203
// previous button when year shown
@@ -208,6 +211,7 @@ describe('<Calendar />', () => {
208211
expect(wrapper.state('showYears')).toBeTruthy();
209212

210213
let currentYearDisplayed = new Date(wrapper.state('currentYear'));
214+
211215
wrapper
212216
.find(
213217
'header.fd-calendar__header button.fd-button--light.fd-button--compact'
@@ -217,8 +221,9 @@ describe('<Calendar />', () => {
217221

218222
let newYearDisplayed = wrapper.state('currentYear');
219223

224+
currentYearDisplayed.setFullYear(currentYearDisplayed.getFullYear() + 12);
220225
expect(newYearDisplayed.getFullYear()).toEqual(
221-
currentYearDisplayed.getFullYear() + 12
226+
currentYearDisplayed.getFullYear()
222227
);
223228
});
224229

@@ -243,10 +248,9 @@ describe('<Calendar />', () => {
243248
.simulate('click');
244249

245250
const newDateDisplayed = wrapper.state('selectedDate');
251+
currentDateDisplayed.setDate(currentDateDisplayed.getDate() + 1);
246252

247-
expect(newDateDisplayed.getDate()).toEqual(
248-
currentDateDisplayed.getDate() + 1
249-
);
253+
expect(newDateDisplayed.getDate()).toEqual(currentDateDisplayed.getDate());
250254
});
251255

252256
test('click on day with range enabled', () => {
@@ -270,10 +274,8 @@ describe('<Calendar />', () => {
270274
.simulate('click');
271275

272276
const newDateDisplayed = wrapper.state('selectedDate');
273-
274-
expect(newDateDisplayed.getDate()).toEqual(
275-
currentDateDisplayed.getDate() + 4
276-
);
277+
currentDateDisplayed.setDate(currentDateDisplayed.getDate() + 4);
278+
expect(newDateDisplayed.getDate()).toEqual(currentDateDisplayed.getDate());
277279

278280
expect(wrapper.state('arrSelectedDates').length).toEqual(2);
279281
});

src/Identifier/Identifier.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('<Identifier />', () => {
2121
);
2222
const accentColor = <Identifier size="m" glyph="money-bills" color={9} />;
2323

24+
const bgImage = (
25+
<Identifier
26+
backgroundImageUrl="https://placeimg.com/400/400/nature"
27+
modifier="circle"
28+
/>
29+
);
30+
2431
test('Create identifier', () => {
2532
// create default icon
2633
let component = renderer.create(defaultIcon);
@@ -46,5 +53,10 @@ describe('<Identifier />', () => {
4653
component = renderer.create(accentColor);
4754
tree = component.toJSON();
4855
expect(tree).toMatchSnapshot();
56+
57+
// create background image icon
58+
component = renderer.create(bgImage);
59+
tree = component.toJSON();
60+
expect(tree).toMatchSnapshot();
4961
});
5062
});

src/Identifier/__snapshots__/Identifier.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ exports[`<Identifier /> Create identifier 5`] = `
3737
role="presentation"
3838
/>
3939
`;
40+
41+
exports[`<Identifier /> Create identifier 6`] = `
42+
<span
43+
className="fd-identifier fd-identifier--circle fd-identifier--thumbnail"
44+
role="presentation"
45+
style={
46+
Object {
47+
"backgroundImage": "url(https://placeimg.com/400/400/nature)",
48+
}
49+
}
50+
/>
51+
`;

0 commit comments

Comments
 (0)