@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/coverage/lcov-report/index.html +66 -21
  3. package/coverage/lcov.info +6394 -3195
  4. package/dist/src/calendar-monthly-styles.js +242 -12
  5. package/dist/src/calendar-monthly-styles.js.map +1 -1
  6. package/dist/src/calendar-monthly.d.ts +8 -1
  7. package/dist/src/calendar-monthly.js +90 -17
  8. package/dist/src/calendar-monthly.js.map +1 -1
  9. package/dist/src/calendar-weekly-styles.js +136 -13
  10. package/dist/src/calendar-weekly-styles.js.map +1 -1
  11. package/dist/src/calendar-weekly.d.ts +8 -1
  12. package/dist/src/calendar-weekly.js +92 -12
  13. package/dist/src/calendar-weekly.js.map +1 -1
  14. package/dist/src/day-overflow.d.ts +42 -0
  15. package/dist/src/day-overflow.js +71 -0
  16. package/dist/src/day-overflow.js.map +1 -0
  17. package/dist/src/index.d.ts +1 -0
  18. package/dist/src/index.js +1 -0
  19. package/dist/src/index.js.map +1 -1
  20. package/dist/src/ox-event-view.d.ts +3 -0
  21. package/dist/src/ox-event-view.js +33 -2
  22. package/dist/src/ox-event-view.js.map +1 -1
  23. package/dist/src/types.d.ts +66 -1
  24. package/dist/src/types.js +64 -1
  25. package/dist/src/types.js.map +1 -1
  26. package/dist/test/calendar-layout.test.js +102 -0
  27. package/dist/test/calendar-layout.test.js.map +1 -1
  28. package/dist/test/day-overflow.test.d.ts +1 -0
  29. package/dist/test/day-overflow.test.js +81 -0
  30. package/dist/test/day-overflow.test.js.map +1 -0
  31. package/dist/test/day-state.test.d.ts +1 -0
  32. package/dist/test/day-state.test.js +115 -0
  33. package/dist/test/day-state.test.js.map +1 -0
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +3 -2
  36. package/test/calendar-layout.test.ts +130 -0
  37. package/test/day-overflow.test.ts +103 -0
  38. package/test/day-state.test.ts +139 -0
@@ -0,0 +1,81 @@
1
+ import { html, fixture, expect } from '@open-wc/testing';
2
+ import '../src/ox-event-view.js';
3
+ /**
4
+ * A cell takes a ceiling so one busy day does not set the height of every day beside it, and
5
+ * says what the ceiling cut so the host can fold harder.
6
+ *
7
+ * The ceiling on its own would be the defect it replaces - the old "+763 more" hid rows the same
8
+ * way. What makes it different is that somebody is told.
9
+ */
10
+ const ROW_HEIGHT = 20;
11
+ function providerWith(rowsOnFirstDay) {
12
+ return {
13
+ async fetchEventsForCalendar(calendar) {
14
+ const events = Array.from({ length: rowsOnFirstDay }, (unused, index) => ({
15
+ title: `row ${index}`,
16
+ color: 'rgb(0, 0, 0)',
17
+ template: html `<div style="height: ${ROW_HEIGHT}px">row ${index}</div>`
18
+ }));
19
+ return new Map([[calendar[0].date, events]]);
20
+ }
21
+ };
22
+ }
23
+ async function calendarWith(rows, cap) {
24
+ const el = (await fixture(html `
25
+ <ox-event-view mode="monthly" style=${cap ? `--calendar-monthly-date-max-height:${cap}` : ''}></ox-event-view>
26
+ `));
27
+ const seen = [];
28
+ el.addEventListener('day-overflow', event => seen.push(event.detail));
29
+ el.eventProvider = providerWith(rows);
30
+ await el.updateComplete;
31
+ await new Promise(resolve => setTimeout(resolve, 80));
32
+ const root = el.renderRoot.querySelector('calendar-monthly').shadowRoot;
33
+ return { root, seen };
34
+ }
35
+ describe('a day cell that cannot hold everything says so', () => {
36
+ it('stays uncapped, and silent, when no theme sets a ceiling', async () => {
37
+ /*
38
+ * The default has to be none. A ceiling is only safe once the host folds its rows, so a
39
+ * component that capped by default would start hiding rows in every app that upgraded.
40
+ */
41
+ const { root, seen } = await calendarWith(40);
42
+ const cell = root.querySelector('li[date]');
43
+ expect(getComputedStyle(cell).maxHeight).to.equal('none');
44
+ expect(cell.getBoundingClientRect().height, 'the cell grew to hold all forty').to.be.greaterThan(40 * ROW_HEIGHT);
45
+ expect(seen, 'nothing was cut, so nothing is reported').to.deep.equal([]);
46
+ });
47
+ it('reports the rows a ceiling cut, and which day lost them', async () => {
48
+ const { root, seen } = await calendarWith(40, '160px');
49
+ const cell = root.querySelector('li[date]');
50
+ expect(cell.getBoundingClientRect().height, 'held to the ceiling').to.be.at.most(161);
51
+ const last = seen[seen.length - 1];
52
+ expect(last, 'the host was told').to.not.be.undefined;
53
+ expect(last.length).to.equal(1);
54
+ expect(last[0].hidden, 'roughly the rows past 160px, not all forty').to.be.greaterThan(20);
55
+ expect(last[0].date, 'named by day, so the host knows where to fold').to.be.instanceOf(Date);
56
+ });
57
+ it('keeps every other cell off the busy day\'s height', async () => {
58
+ /*
59
+ * The measured failure: a grid row is as tall as its tallest cell, so 767 events on the 8th
60
+ * made all seven of the week view's cells 670px, the two empty ones included.
61
+ */
62
+ const { root } = await calendarWith(40, '160px');
63
+ const cells = Array.from(root.querySelectorAll('li[date]'));
64
+ const heights = cells.map(cell => Math.round(cell.getBoundingClientRect().height));
65
+ expect(Math.max(...heights)).to.be.at.most(161);
66
+ });
67
+ it('does not repeat itself when nothing changed', async () => {
68
+ /*
69
+ * This measurement runs after every render, and a host that re-renders in response would
70
+ * otherwise be told the same thing forever.
71
+ */
72
+ const { seen } = await calendarWith(40, '160px');
73
+ const signatures = seen.map(one => one.map(day => `${day.date?.getTime()}:${day.hidden}`).join(','));
74
+ expect(new Set(signatures).size, 'one distinct report, however many renders').to.equal(signatures.length);
75
+ });
76
+ it('says nothing for a day that fits under the ceiling', async () => {
77
+ const { seen } = await calendarWith(2, '160px');
78
+ expect(seen.flat()).to.deep.equal([]);
79
+ });
80
+ });
81
+ //# sourceMappingURL=day-overflow.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day-overflow.test.js","sourceRoot":"","sources":["../../test/day-overflow.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,yBAAyB,CAAA;AAKhC;;;;;;GAMG;AAEH,MAAM,UAAU,G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,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QAEpG,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,2CAA2C,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC3G,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;QAE/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { html, fixture, expect } from '@open-wc/testing'\n\nimport '../src/ox-event-view.js'\nimport { OxEventView } from '../src/ox-event-view.js'\nimport { BizEvent, CALENDAR, EventProvider } from '../src/types.js'\nimport { DayOverflow } from '../src/day-overflow.js'\n\n/**\n * A cell takes a ceiling so one busy day does not set the height of every day beside it, and\n * says what the ceiling cut so the host can fold harder.\n *\n * The ceiling on its own would be the defect it replaces - the old \"+763 more\" hid rows the same\n * way. What makes it different is that somebody is told.\n */\n\nconst ROW_HEIGHT = 20\n\nfunction providerWith(rowsOnFirstDay: number): EventProvider {\n return {\n async fetchEventsForCalendar(calendar: CALENDAR) {\n const events: BizEvent[] = Array.from({ length: rowsOnFirstDay }, (unused, index) => ({\n title: `row ${index}`,\n color: 'rgb(0, 0, 0)',\n template: html`<div style=\"height: ${ROW_HEIGHT}px\">row ${index}</div>`\n }))\n\n return new Map([[calendar[0].date, events]])\n }\n }\n}\n\nasync function calendarWith(rows: number, cap?: string) {\n const el = (await fixture(html`\n <ox-event-view mode=\"monthly\" style=${cap ? `--calendar-monthly-date-max-height:${cap}` : ''}></ox-event-view>\n `)) as OxEventView\n\n const seen: DayOverflow[][] = []\n el.addEventListener('day-overflow', event => seen.push((event as CustomEvent<DayOverflow[]>).detail))\n\n el.eventProvider = providerWith(rows)\n await el.updateComplete\n await new Promise(resolve => setTimeout(resolve, 80))\n\n const root = el.renderRoot.querySelector('calendar-monthly')!.shadowRoot!\n return { root, seen }\n}\n\ndescribe('a day cell that cannot hold everything says so', () => {\n it('stays uncapped, and silent, when no theme sets a ceiling', async () => {\n /*\n * The default has to be none. A ceiling is only safe once the host folds its rows, so a\n * component that capped by default would start hiding rows in every app that upgraded.\n */\n const { root, seen } = await calendarWith(40)\n const cell = root.querySelector('li[date]') as HTMLElement\n\n expect(getComputedStyle(cell).maxHeight).to.equal('none')\n expect(cell.getBoundingClientRect().height, 'the cell grew to hold all forty').to.be.greaterThan(40 * ROW_HEIGHT)\n expect(seen, 'nothing was cut, so nothing is reported').to.deep.equal([])\n })\n\n it('reports the rows a ceiling cut, and which day lost them', async () => {\n const { root, seen } = await calendarWith(40, '160px')\n const cell = root.querySelector('li[date]') as HTMLElement\n\n expect(cell.getBoundingClientRect().height, 'held to the ceiling').to.be.at.most(161)\n\n const last = seen[seen.length - 1]\n expect(last, 'the host was told').to.not.be.undefined\n expect(last.length).to.equal(1)\n expect(last[0].hidden, 'roughly the rows past 160px, not all forty').to.be.greaterThan(20)\n expect(last[0].date, 'named by day, so the host knows where to fold').to.be.instanceOf(Date)\n })\n\n it('keeps every other cell off the busy day\\'s height', async () => {\n /*\n * The measured failure: a grid row is as tall as its tallest cell, so 767 events on the 8th\n * made all seven of the week view's cells 670px, the two empty ones included.\n */\n const { root } = await calendarWith(40, '160px')\n const cells = Array.from(root.querySelectorAll('li[date]')) as HTMLElement[]\n const heights = cells.map(cell => Math.round(cell.getBoundingClientRect().height))\n\n expect(Math.max(...heights)).to.be.at.most(161)\n })\n\n it('does not repeat itself when nothing changed', async () => {\n /*\n * This measurement runs after every render, and a host that re-renders in response would\n * otherwise be told the same thing forever.\n */\n const { seen } = await calendarWith(40, '160px')\n const signatures = seen.map(one => one.map(day => `${day.date?.getTime()}:${day.hidden}`).join(','))\n\n expect(new Set(signatures).size, 'one distinct report, however many renders').to.equal(signatures.length)\n })\n\n it('says nothing for a day that fits under the ceiling', async () => {\n const { seen } = await calendarWith(2, '160px')\n\n expect(seen.flat()).to.deep.equal([])\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import '../src/ox-event-view.js';
@@ -0,0 +1,115 @@
1
+ import { html, fixture, expect } from '@open-wc/testing';
2
+ import '../src/ox-event-view.js';
3
+ /**
4
+ * A host can say something about a day itself, not only about what happened in it.
5
+ *
6
+ * Before this there was no such channel: CALENDAR carried only what the component works out
7
+ * (which month a date is in, whether it is today), so a screen wanting to mark a holiday had to
8
+ * send an event, and it drew as one more 6px dot among the day's actual work. That was the
9
+ * component's shape, not the screen's choice.
10
+ */
11
+ function providerMarking(pick, state) {
12
+ return {
13
+ async fetchEventsForCalendar() {
14
+ return new Map();
15
+ },
16
+ async fetchDayStatesForCalendar(calendar) {
17
+ /*
18
+ * Key by the very Date objects the component handed over. The component looks the day up
19
+ * by identity, the way it already does for events - a fresh Date with the same instant
20
+ * would not match, and a host that built its own would silently mark nothing.
21
+ */
22
+ return new Map(pick(calendar).map(date => [date, state]));
23
+ }
24
+ };
25
+ }
26
+ const HOLIDAY = { name: 'non-working', color: 'rgb(1, 2, 3)' };
27
+ /*
28
+ * A bare test page carries no theme, and every surface in this component is a var() onto one.
29
+ * Without these the month cells compute to transparent and "the state did not paint" looks the
30
+ * same as "nothing paints here at all" — which is precisely the confusion these tests exist to
31
+ * rule out. Only the tokens the cell surfaces read.
32
+ */
33
+ const THEME = {
34
+ '--md-sys-color-surface-container-lowest': 'rgb(255, 255, 255)',
35
+ '--md-sys-color-surface-variant': 'rgb(232, 235, 238)',
36
+ '--md-sys-color-surface': 'rgb(240, 242, 244)',
37
+ '--md-sys-color-tertiary-container': 'rgb(200, 220, 255)',
38
+ '--md-sys-color-primary': 'rgb(38, 46, 56)'
39
+ };
40
+ before(() => Object.entries(THEME).forEach(([name, value]) => document.documentElement.style.setProperty(name, value)));
41
+ after(() => Object.keys(THEME).forEach(name => document.documentElement.style.removeProperty(name)));
42
+ async function calendarWith(provider, mode) {
43
+ const el = (await fixture(html `<ox-event-view mode=${mode}></ox-event-view>`));
44
+ if (provider)
45
+ el.eventProvider = provider;
46
+ await el.updateComplete;
47
+ /* The grid is filled in updated(), after the provider has answered. */
48
+ await new Promise(resolve => setTimeout(resolve, 50));
49
+ const view = el.renderRoot.querySelector(mode === 'monthly' ? 'calendar-monthly' : 'calendar-weekly');
50
+ return view.shadowRoot;
51
+ }
52
+ describe('a host can mark the day itself', () => {
53
+ it('paints the marked day and leaves the rest alone', async () => {
54
+ const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly');
55
+ const marked = root.querySelectorAll('li[day-state]');
56
+ expect(marked.length, 'exactly the day the host named').to.equal(1);
57
+ expect(getComputedStyle(marked[0]).backgroundColor).to.equal('rgb(1, 2, 3)');
58
+ expect(marked[0].getAttribute('day-state'), 'the host word reaches the dom').to.equal('non-working');
59
+ });
60
+ it('leaves every cell unmarked when the host does not answer', async () => {
61
+ /* The old EventProvider shape, which must keep working - the method is optional. */
62
+ const root = await calendarWith({ async fetchEventsForCalendar() { return new Map(); } }, 'monthly');
63
+ expect(root.querySelectorAll('li[day-state]').length).to.equal(0);
64
+ });
65
+ it('does not blank a cell when there is no state to draw', async () => {
66
+ /*
67
+ * The failure this guards. `background-color: var(--day-state-color)` with the property
68
+ * unset is invalid at computed-value time, which resolves to transparent - so an attribute
69
+ * written without a colour would erase the month surface underneath instead of adding to
70
+ * it. Unmarked days must keep the surface the month view gave them.
71
+ */
72
+ const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly');
73
+ const plain = root.querySelector('li[current-month]:not([day-state])');
74
+ expect(getComputedStyle(plain).backgroundColor, 'the month surface, untouched').to.equal('rgb(255, 255, 255)');
75
+ });
76
+ it('marks both cells of a day in the week view', async () => {
77
+ /*
78
+ * A day is two cells stacked there - the date band and the events under it. Marking only
79
+ * the band would tint a 37px strip and leave the 600px body untouched.
80
+ */
81
+ const root = await calendarWith(providerMarking(calendar => [calendar[3].date], HOLIDAY), 'weekly');
82
+ const marked = Array.from(root.querySelectorAll('li[day-state]'));
83
+ expect(marked.length).to.equal(2);
84
+ expect(marked.some(li => li.hasAttribute('day-of-week')), 'the date band').to.be.true;
85
+ expect(marked.some(li => !li.hasAttribute('day-of-week')), 'the events under it').to.be.true;
86
+ marked.forEach(li => expect(getComputedStyle(li).backgroundColor).to.equal('rgb(1, 2, 3)'));
87
+ });
88
+ it('lets a selection win over the day state', async () => {
89
+ /*
90
+ * Both rules are (0,1,1), so the order they are written in is what decides. A day you have
91
+ * selected should look selected even if it is a holiday; a holiday you have not touched
92
+ * should look like a holiday. Get the order wrong and dragging across a holiday leaves a
93
+ * hole in the selection.
94
+ */
95
+ const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly');
96
+ const cell = root.querySelector('li[day-state]');
97
+ cell.setAttribute('selected', '');
98
+ expect(getComputedStyle(cell).backgroundColor).to.not.equal('rgb(1, 2, 3)');
99
+ });
100
+ it('keeps today readable on a marked day', async () => {
101
+ /*
102
+ * Today rides on a background-image and an outline, precisely so it survives whatever claims
103
+ * the background colour. A holiday that is also today has to show both.
104
+ */
105
+ const root = await calendarWith(providerMarking(calendar => calendar.filter(one => one.today).map(one => one.date), HOLIDAY), 'monthly');
106
+ const today = root.querySelector('li[today]');
107
+ const style = getComputedStyle(today);
108
+ expect(today.hasAttribute('day-state'), 'today was the day marked').to.be.true;
109
+ expect(style.backgroundColor, 'the holiday surface').to.equal('rgb(1, 2, 3)');
110
+ expect(style.backgroundImage, 'today, still drawn on top').to.not.equal('none');
111
+ expect(style.outlineStyle, 'and the ring, which is an outline so it can sit inset').to.equal('solid');
112
+ expect(parseFloat(style.outlineWidth)).to.be.greaterThan(0);
113
+ });
114
+ });
115
+ //# sourceMappingURL=day-state.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day-state.test.js","sourceRoot":"","sources":["../../test/day-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,yBAAyB,CAAA;AAIhC;;;;;;;GAOG;AAEH,SAAS,eAAe,CAAC,IAAoC,EAAE,KAAe;IAC5E,OAAO;QACL,KAAK,CAAC,sBAAsB;YAC1B,OAAO,IAAI,GAAG,EAAE,CAAA;QAClB,CAAC;QACD,KAAK,CAAC,yBAAyB,CAAC,QAAkB;YAChD;;;;eAIG;YACH,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;QAC3D,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,OAAO,GAAa,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,cAAc,EAAE,CAAA;AAExE;;;;;GAKG;AACH,MAAM,KAAK,GAA2B;IACpC,yCAAyC,EAAE,oBAAoB;IAC/D,gCAAgC,EAAE,oBAAoB;IACtD,wBAAwB,EAAE,oBAAoB;IAC9C,mCAAmC,EAAE,oBAAoB;IACzD,wBAAwB,EAAE,iBAAiB;CAC5C,CAAA;AAED,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;AACvH,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC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AC7E,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD;;;WAGG;QACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAC7B,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAC5F,SAAS,CACV,CAAA;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAgB,CAAA;QAC5D,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;QAC9E,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAC7E,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC/E,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,uDAAuD,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACrG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { html, fixture, expect } from '@open-wc/testing'\n\nimport '../src/ox-event-view.js'\nimport { OxEventView } from '../src/ox-event-view.js'\nimport { CALENDAR, DayState, EventProvider } from '../src/types.js'\n\n/**\n * A host can say something about a day itself, not only about what happened in it.\n *\n * Before this there was no such channel: CALENDAR carried only what the component works out\n * (which month a date is in, whether it is today), so a screen wanting to mark a holiday had to\n * send an event, and it drew as one more 6px dot among the day's actual work. That was the\n * component's shape, not the screen's choice.\n */\n\nfunction providerMarking(pick: (calendar: CALENDAR) => Date[], state: DayState): EventProvider {\n return {\n async fetchEventsForCalendar() {\n return new Map()\n },\n async fetchDayStatesForCalendar(calendar: CALENDAR) {\n /*\n * Key by the very Date objects the component handed over. The component looks the day up\n * by identity, the way it already does for events - a fresh Date with the same instant\n * would not match, and a host that built its own would silently mark nothing.\n */\n return new Map(pick(calendar).map(date => [date, state]))\n }\n }\n}\n\nconst HOLIDAY: DayState = { name: 'non-working', color: 'rgb(1, 2, 3)' }\n\n/*\n * A bare test page carries no theme, and every surface in this component is a var() onto one.\n * Without these the month cells compute to transparent and \"the state did not paint\" looks the\n * same as \"nothing paints here at all\" — which is precisely the confusion these tests exist to\n * rule out. Only the tokens the cell surfaces read.\n */\nconst THEME: Record<string, string> = {\n '--md-sys-color-surface-container-lowest': 'rgb(255, 255, 255)',\n '--md-sys-color-surface-variant': 'rgb(232, 235, 238)',\n '--md-sys-color-surface': 'rgb(240, 242, 244)',\n '--md-sys-color-tertiary-container': 'rgb(200, 220, 255)',\n '--md-sys-color-primary': 'rgb(38, 46, 56)'\n}\n\nbefore(() => Object.entries(THEME).forEach(([name, value]) => document.documentElement.style.setProperty(name, value)))\nafter(() => Object.keys(THEME).forEach(name => document.documentElement.style.removeProperty(name)))\n\nasync function calendarWith(provider: EventProvider | undefined, mode: 'monthly' | 'weekly') {\n const el = (await fixture(html`<ox-event-view mode=${mode}></ox-event-view>`)) as OxEventView\n if (provider) el.eventProvider = provider\n await el.updateComplete\n /* The grid is filled in updated(), after the provider has answered. */\n await new Promise(resolve => setTimeout(resolve, 50))\n\n const view = el.renderRoot.querySelector(mode === 'monthly' ? 'calendar-monthly' : 'calendar-weekly')!\n return view.shadowRoot!\n}\n\ndescribe('a host can mark the day itself', () => {\n it('paints the marked day and leaves the rest alone', async () => {\n const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')\n\n const marked = root.querySelectorAll('li[day-state]')\n expect(marked.length, 'exactly the day the host named').to.equal(1)\n expect(getComputedStyle(marked[0] as HTMLElement).backgroundColor).to.equal('rgb(1, 2, 3)')\n expect(marked[0].getAttribute('day-state'), 'the host word reaches the dom').to.equal('non-working')\n })\n\n it('leaves every cell unmarked when the host does not answer', async () => {\n /* The old EventProvider shape, which must keep working - the method is optional. */\n const root = await calendarWith({ async fetchEventsForCalendar() { return new Map() } }, 'monthly')\n\n expect(root.querySelectorAll('li[day-state]').length).to.equal(0)\n })\n\n it('does not blank a cell when there is no state to draw', async () => {\n /*\n * The failure this guards. `background-color: var(--day-state-color)` with the property\n * unset is invalid at computed-value time, which resolves to transparent - so an attribute\n * written without a colour would erase the month surface underneath instead of adding to\n * it. Unmarked days must keep the surface the month view gave them.\n */\n const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')\n\n const plain = root.querySelector('li[current-month]:not([day-state])') as HTMLElement\n expect(getComputedStyle(plain).backgroundColor, 'the month surface, untouched').to.equal('rgb(255, 255, 255)')\n })\n\n it('marks both cells of a day in the week view', async () => {\n /*\n * A day is two cells stacked there - the date band and the events under it. Marking only\n * the band would tint a 37px strip and leave the 600px body untouched.\n */\n const root = await calendarWith(providerMarking(calendar => [calendar[3].date], HOLIDAY), 'weekly')\n\n const marked = Array.from(root.querySelectorAll('li[day-state]')) as HTMLElement[]\n expect(marked.length).to.equal(2)\n expect(marked.some(li => li.hasAttribute('day-of-week')), 'the date band').to.be.true\n expect(marked.some(li => !li.hasAttribute('day-of-week')), 'the events under it').to.be.true\n marked.forEach(li => expect(getComputedStyle(li).backgroundColor).to.equal('rgb(1, 2, 3)'))\n })\n\n it('lets a selection win over the day state', async () => {\n /*\n * Both rules are (0,1,1), so the order they are written in is what decides. A day you have\n * selected should look selected even if it is a holiday; a holiday you have not touched\n * should look like a holiday. Get the order wrong and dragging across a holiday leaves a\n * hole in the selection.\n */\n const root = await calendarWith(providerMarking(calendar => [calendar[10].date], HOLIDAY), 'monthly')\n const cell = root.querySelector('li[day-state]') as HTMLElement\n\n cell.setAttribute('selected', '')\n\n expect(getComputedStyle(cell).backgroundColor).to.not.equal('rgb(1, 2, 3)')\n })\n\n it('keeps today readable on a marked day', async () => {\n /*\n * Today rides on a background-image and an outline, precisely so it survives whatever claims\n * the background colour. A holiday that is also today has to show both.\n */\n const root = await calendarWith(\n providerMarking(calendar => calendar.filter(one => one.today).map(one => one.date), HOLIDAY),\n 'monthly'\n )\n const today = root.querySelector('li[today]') as HTMLElement\n const style = getComputedStyle(today)\n\n expect(today.hasAttribute('day-state'), 'today was the day marked').to.be.true\n expect(style.backgroundColor, 'the holiday surface').to.equal('rgb(1, 2, 3)')\n expect(style.backgroundImage, 'today, still drawn on top').to.not.equal('none')\n expect(style.outlineStyle, 'and the ring, which is an outline so it can sit inset').to.equal('solid')\n expect(parseFloat(style.outlineWidth)).to.be.greaterThan(0)\n })\n})\n"]}