@operato/event-view 10.10.2 → 10.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/coverage/lcov-report/index.html +66 -21
- package/coverage/lcov.info +6394 -3195
- package/dist/src/calendar-monthly-styles.js +242 -12
- package/dist/src/calendar-monthly-styles.js.map +1 -1
- package/dist/src/calendar-monthly.d.ts +8 -1
- package/dist/src/calendar-monthly.js +90 -17
- package/dist/src/calendar-monthly.js.map +1 -1
- package/dist/src/calendar-weekly-styles.js +136 -13
- package/dist/src/calendar-weekly-styles.js.map +1 -1
- package/dist/src/calendar-weekly.d.ts +8 -1
- package/dist/src/calendar-weekly.js +92 -12
- package/dist/src/calendar-weekly.js.map +1 -1
- package/dist/src/day-overflow.d.ts +42 -0
- package/dist/src/day-overflow.js +71 -0
- package/dist/src/day-overflow.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-event-view.d.ts +3 -0
- package/dist/src/ox-event-view.js +33 -2
- package/dist/src/ox-event-view.js.map +1 -1
- package/dist/src/types.d.ts +66 -1
- package/dist/src/types.js +64 -1
- package/dist/src/types.js.map +1 -1
- package/dist/test/calendar-layout.test.js +102 -0
- package/dist/test/calendar-layout.test.js.map +1 -1
- package/dist/test/day-overflow.test.d.ts +1 -0
- package/dist/test/day-overflow.test.js +81 -0
- package/dist/test/day-overflow.test.js.map +1 -0
- package/dist/test/day-state.test.d.ts +1 -0
- package/dist/test/day-state.test.js +115 -0
- package/dist/test/day-state.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/test/calendar-layout.test.ts +130 -0
- package/test/day-overflow.test.ts +103 -0
- package/test/day-state.test.ts +139 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { html, fixture, expect } from '@open-wc/testing'
|
|
2
|
+
|
|
3
|
+
import '../src/ox-event-view.js'
|
|
4
|
+
import { OxEventView } from '../src/ox-event-view.js'
|
|
5
|
+
import { CALENDAR, DayState, EventProvider } from '../src/types.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A host can say something about a day itself, not only about what happened in it.
|
|
9
|
+
*
|
|
10
|
+
* Before this there was no such channel: CALENDAR carried only what the component works out
|
|
11
|
+
* (which month a date is in, whether it is today), so a screen wanting to mark a holiday had to
|
|
12
|
+
* send an event, and it drew as one more 6px dot among the day's actual work. That was the
|
|
13
|
+
* component's shape, not the screen's choice.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function providerMarking(pick: (calendar: CALENDAR) => Date[], state: DayState): EventProvider {
|
|
17
|
+
return {
|
|
18
|
+
async fetchEventsForCalendar() {
|
|
19
|
+
return new Map()
|
|
20
|
+
},
|
|
21
|
+
async fetchDayStatesForCalendar(calendar: CALENDAR) {
|
|
22
|
+
/*
|
|
23
|
+
* Key by the very Date objects the component handed over. The component looks the day up
|
|
24
|
+
* by identity, the way it already does for events - a fresh Date with the same instant
|
|
25
|
+
* would not match, and a host that built its own would silently mark nothing.
|
|
26
|
+
*/
|
|
27
|
+
return new Map(pick(calendar).map(date => [date, state]))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const HOLIDAY: DayState = { name: 'non-working', color: 'rgb(1, 2, 3)' }
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* A bare test page carries no theme, and every surface in this component is a var() onto one.
|
|
36
|
+
* Without these the month cells compute to transparent and "the state did not paint" looks the
|
|
37
|
+
* same as "nothing paints here at all" — which is precisely the confusion these tests exist to
|
|
38
|
+
* rule out. Only the tokens the cell surfaces read.
|
|
39
|
+
*/
|
|
40
|
+
const THEME: Record<string, string> = {
|
|
41
|
+
'--md-sys-color-surface-container-lowest': 'rgb(255, 255, 255)',
|
|
42
|
+
'--md-sys-color-surface-variant': 'rgb(232, 235, 238)',
|
|
43
|
+
'--md-sys-color-surface': 'rgb(240, 242, 244)',
|
|
44
|
+
'--md-sys-color-tertiary-container': 'rgb(200, 220, 255)',
|
|
45
|
+
'--md-sys-color-primary': 'rgb(38, 46, 56)'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
before(() => Object.entries(THEME).forEach(([name, value]) => document.documentElement.style.setProperty(name, value)))
|
|
49
|
+
after(() => Object.keys(THEME).forEach(name => document.documentElement.style.removeProperty(name)))
|
|
50
|
+
|
|
51
|
+
async function calendarWith(provider: EventProvider | undefined, mode: 'monthly' | 'weekly') {
|
|
52
|
+
const el = (await fixture(html`<ox-event-view mode=${mode}></ox-event-view>`)) as OxEventView
|
|
53
|
+
if (provider) el.eventProvider = provider
|
|
54
|
+
await el.updateComplete
|
|
55
|
+
/* The grid is filled in updated(), after the provider has answered. */
|
|
56
|
+
await new Promise(resolve => setTimeout(resolve, 50))
|
|
57
|
+
|
|
58
|
+
const view = el.renderRoot.querySelector(mode === 'monthly' ? 'calendar-monthly' : 'calendar-weekly')!
|
|
59
|
+
return view.shadowRoot!
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('a host can mark the day itself', () => {
|
|
63
|
+
it('paints the marked day and leaves the rest alone', async () => {
|
|
64
|
+
const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')
|
|
65
|
+
|
|
66
|
+
const marked = root.querySelectorAll('li[day-state]')
|
|
67
|
+
expect(marked.length, 'exactly the day the host named').to.equal(1)
|
|
68
|
+
expect(getComputedStyle(marked[0] as HTMLElement).backgroundColor).to.equal('rgb(1, 2, 3)')
|
|
69
|
+
expect(marked[0].getAttribute('day-state'), 'the host word reaches the dom').to.equal('non-working')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('leaves every cell unmarked when the host does not answer', async () => {
|
|
73
|
+
/* The old EventProvider shape, which must keep working - the method is optional. */
|
|
74
|
+
const root = await calendarWith({ async fetchEventsForCalendar() { return new Map() } }, 'monthly')
|
|
75
|
+
|
|
76
|
+
expect(root.querySelectorAll('li[day-state]').length).to.equal(0)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('does not blank a cell when there is no state to draw', async () => {
|
|
80
|
+
/*
|
|
81
|
+
* The failure this guards. `background-color: var(--day-state-color)` with the property
|
|
82
|
+
* unset is invalid at computed-value time, which resolves to transparent - so an attribute
|
|
83
|
+
* written without a colour would erase the month surface underneath instead of adding to
|
|
84
|
+
* it. Unmarked days must keep the surface the month view gave them.
|
|
85
|
+
*/
|
|
86
|
+
const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')
|
|
87
|
+
|
|
88
|
+
const plain = root.querySelector('li[current-month]:not([day-state])') as HTMLElement
|
|
89
|
+
expect(getComputedStyle(plain).backgroundColor, 'the month surface, untouched').to.equal('rgb(255, 255, 255)')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('marks both cells of a day in the week view', async () => {
|
|
93
|
+
/*
|
|
94
|
+
* A day is two cells stacked there - the date band and the events under it. Marking only
|
|
95
|
+
* the band would tint a 37px strip and leave the 600px body untouched.
|
|
96
|
+
*/
|
|
97
|
+
const root = await calendarWith(providerMarking(calendar => [calendar[3].date], HOLIDAY), 'weekly')
|
|
98
|
+
|
|
99
|
+
const marked = Array.from(root.querySelectorAll('li[day-state]')) as HTMLElement[]
|
|
100
|
+
expect(marked.length).to.equal(2)
|
|
101
|
+
expect(marked.some(li => li.hasAttribute('day-of-week')), 'the date band').to.be.true
|
|
102
|
+
expect(marked.some(li => !li.hasAttribute('day-of-week')), 'the events under it').to.be.true
|
|
103
|
+
marked.forEach(li => expect(getComputedStyle(li).backgroundColor).to.equal('rgb(1, 2, 3)'))
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('lets a selection win over the day state', async () => {
|
|
107
|
+
/*
|
|
108
|
+
* Both rules are (0,1,1), so the order they are written in is what decides. A day you have
|
|
109
|
+
* selected should look selected even if it is a holiday; a holiday you have not touched
|
|
110
|
+
* should look like a holiday. Get the order wrong and dragging across a holiday leaves a
|
|
111
|
+
* hole in the selection.
|
|
112
|
+
*/
|
|
113
|
+
const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')
|
|
114
|
+
const cell = root.querySelector('li[day-state]') as HTMLElement
|
|
115
|
+
|
|
116
|
+
cell.setAttribute('selected', '')
|
|
117
|
+
|
|
118
|
+
expect(getComputedStyle(cell).backgroundColor).to.not.equal('rgb(1, 2, 3)')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('keeps today readable on a marked day', async () => {
|
|
122
|
+
/*
|
|
123
|
+
* Today rides on a background-image and an outline, precisely so it survives whatever claims
|
|
124
|
+
* the background colour. A holiday that is also today has to show both.
|
|
125
|
+
*/
|
|
126
|
+
const root = await calendarWith(
|
|
127
|
+
providerMarking(calendar => calendar.filter(one => one.today).map(one => one.date), HOLIDAY),
|
|
128
|
+
'monthly'
|
|
129
|
+
)
|
|
130
|
+
const today = root.querySelector('li[today]') as HTMLElement
|
|
131
|
+
const style = getComputedStyle(today)
|
|
132
|
+
|
|
133
|
+
expect(today.hasAttribute('day-state'), 'today was the day marked').to.be.true
|
|
134
|
+
expect(style.backgroundColor, 'the holiday surface').to.equal('rgb(1, 2, 3)')
|
|
135
|
+
expect(style.backgroundImage, 'today, still drawn on top').to.not.equal('none')
|
|
136
|
+
expect(style.outlineStyle, 'and the ring, which is an outline so it can sit inset').to.equal('solid')
|
|
137
|
+
expect(parseFloat(style.outlineWidth)).to.be.greaterThan(0)
|
|
138
|
+
})
|
|
139
|
+
})
|