Skip to content

Commit 3b889e3

Browse files
author
Mikhail Bashkirov
committed
fix: public test-helpers
1 parent 9efdef7 commit 3b889e3

File tree

18 files changed

+123
-110
lines changed

18 files changed

+123
-110
lines changed

packages/calendar/test-helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { CalendarObject } from './test-helpers/CalendarObject.js';
2+
export { DayObject } from './test-helpers/DayObject.js';
3+
export { weekdayNames } from './test-helpers/weekdayNames.js';

packages/calendar/test/test-utils.js renamed to packages/calendar/test-helpers/CalendarObject.js

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,4 @@
1-
export const weekdayNames = {
2-
'en-GB': {
3-
Sunday: {
4-
long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
5-
short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
6-
},
7-
},
8-
};
9-
10-
/**
11-
* Abstraction around calendar day DOM structure,
12-
* allows for writing readable, 'DOM structure agnostic' tests
13-
*/
14-
export class DayObject {
15-
constructor(dayEl) {
16-
this.el = dayEl;
17-
}
18-
19-
/**
20-
* Node references
21-
*/
22-
23-
get calendarShadowRoot() {
24-
return this.el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
25-
}
26-
27-
get cellEl() {
28-
return this.el.parentElement;
29-
}
30-
31-
get buttonEl() {
32-
return this.el;
33-
}
34-
35-
/**
36-
* States
37-
*/
38-
39-
get isDisabled() {
40-
return this.buttonEl.hasAttribute('disabled');
41-
}
42-
43-
get isSelected() {
44-
return this.buttonEl.hasAttribute('selected');
45-
}
46-
47-
get isToday() {
48-
return this.buttonEl.hasAttribute('today');
49-
}
50-
51-
get isCentral() {
52-
return this.buttonEl.getAttribute('tabindex') === '0';
53-
}
54-
55-
get isFocused() {
56-
this.calendarShadowRoot.activeElement;
57-
this.buttonEl;
58-
return this.calendarShadowRoot.activeElement === this.buttonEl;
59-
}
60-
61-
get monthday() {
62-
return Number(this.buttonEl.textContent);
63-
}
64-
65-
/**
66-
* Text
67-
*/
68-
69-
get weekdayNameShort() {
70-
const weekdayEls = Array.from(
71-
this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'),
72-
);
73-
const dayIndex = weekdayEls.indexOf(this.el.parentElement);
74-
return weekdayNames['en-GB'].Sunday.short[dayIndex];
75-
}
76-
77-
get weekdayNameLong() {
78-
const weekdayEls = Array.from(
79-
this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'),
80-
);
81-
const dayIndex = weekdayEls.indexOf(this.el.parentElement);
82-
return weekdayNames['en-GB'].Sunday.long[dayIndex];
83-
}
84-
85-
/**
86-
* Other
87-
*/
88-
get cellIndex() {
89-
return Array.from(this.cellEl.parentElement.children).indexOf(this.cellEl);
90-
}
91-
}
1+
import { DayObject } from './DayObject.js';
922

933
/**
944
* Abstraction around calendar DOM structure,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { weekdayNames } from './weekdayNames.js';
2+
3+
/**
4+
* Abstraction around calendar day DOM structure,
5+
* allows for writing readable, 'DOM structure agnostic' tests
6+
*/
7+
export class DayObject {
8+
constructor(dayEl) {
9+
this.el = dayEl;
10+
}
11+
12+
/**
13+
* Node references
14+
*/
15+
16+
get calendarShadowRoot() {
17+
return this.el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
18+
}
19+
20+
get cellEl() {
21+
return this.el.parentElement;
22+
}
23+
24+
get buttonEl() {
25+
return this.el;
26+
}
27+
28+
/**
29+
* States
30+
*/
31+
32+
get isDisabled() {
33+
return this.buttonEl.hasAttribute('disabled');
34+
}
35+
36+
get isSelected() {
37+
return this.buttonEl.hasAttribute('selected');
38+
}
39+
40+
get isToday() {
41+
return this.buttonEl.hasAttribute('today');
42+
}
43+
44+
get isCentral() {
45+
return this.buttonEl.getAttribute('tabindex') === '0';
46+
}
47+
48+
get isFocused() {
49+
return this.calendarShadowRoot.activeElement === this.buttonEl;
50+
}
51+
52+
get monthday() {
53+
return Number(this.buttonEl.textContent);
54+
}
55+
56+
/**
57+
* Text
58+
*/
59+
60+
get weekdayNameShort() {
61+
const weekdayEls = Array.from(
62+
this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'),
63+
);
64+
const dayIndex = weekdayEls.indexOf(this.el.parentElement);
65+
return weekdayNames['en-GB'].Sunday.short[dayIndex];
66+
}
67+
68+
get weekdayNameLong() {
69+
const weekdayEls = Array.from(
70+
this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'),
71+
);
72+
const dayIndex = weekdayEls.indexOf(this.el.parentElement);
73+
return weekdayNames['en-GB'].Sunday.long[dayIndex];
74+
}
75+
76+
/**
77+
* Other
78+
*/
79+
get cellIndex() {
80+
return Array.from(this.cellEl.parentElement.children).indexOf(this.cellEl);
81+
}
82+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const weekdayNames = {
2+
'en-GB': {
3+
Sunday: {
4+
long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
5+
short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
6+
},
7+
},
8+
};

packages/calendar/test/lion-calendar.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { html } from '@lion/core';
55
import { localize } from '@lion/localize';
66
import { localizeTearDown } from '@lion/localize/test-helpers.js';
77

8-
import { CalendarObject, DayObject } from './test-utils.js';
8+
import { CalendarObject, DayObject } from '../test-helpers.js';
99
import './keyboardEventShimIE.js';
1010

1111
import { isSameDate } from '../src/utils/isSameDate.js';

packages/calendar/test/utils/dataTemplate.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, fixture } from '@open-wc/testing';
33

44
import { createMultipleMonth } from '../../src/utils/createMultipleMonth.js';
55
import { dataTemplate } from '../../src/utils/dataTemplate.js';
6-
import { weekdayNames } from '../test-utils.js';
6+
import { weekdayNames } from '../../test-helpers.js';
77

88
// eslint-disable-next-line camelcase
99
import snapshot_enGB_Sunday_201812 from './snapshots/monthTemplate_en-GB_Sunday_2018-12.js';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { DatepickerInputObject } from './test-helpers/DatepickerInputObject.js';

packages/input-datepicker/test/test-utils.js renamed to packages/input-datepicker/test-helpers/DatepickerInputObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CalendarObject } from '@lion/calendar/test/test-utils.js';
1+
import { CalendarObject } from '@lion/calendar/test-helpers.js';
22

33
// TODO: refactor CalendarObject to this approach (only methods when arguments are needed)
44
export class DatepickerInputObject {

packages/input-datepicker/test/lion-input-datepicker.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { keyCodes } from '@lion/overlays/src/utils/key-codes.js';
1212
import { keyUpOn } from '@polymer/iron-test-helpers/mock-interactions.js';
1313
import { LionCalendar } from '@lion/calendar';
1414
import { isSameDate } from '@lion/calendar/src/utils/isSameDate.js';
15-
import { DatepickerInputObject } from './test-utils.js';
15+
import { DatepickerInputObject } from '../test-helpers.js';
1616
import { LionInputDatepicker } from '../src/LionInputDatepicker.js';
1717
import '../lion-input-datepicker.js';
1818

packages/input-iban/test/validators.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@open-wc/testing';
2-
import { smokeTestValidator } from '@lion/validate/test/test-utils.js';
2+
import { smokeTestValidator } from '@lion/validate/test-helpers.js';
33

44
import {
55
isIBAN,

0 commit comments

Comments
 (0)