@jsb188/calendar 1.1.11 → 1.1.13

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.
@@ -1,167 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getCalendarDateKey } from '../src/libs/calendar-range.ts';
3
- import {
4
- getCalendarViewSlug,
5
- parseCalendarViewSlug,
6
- readCalendarUrlState,
7
- writeCalendarUrlState,
8
- } from '../src/libs/calendar-url.ts';
9
-
10
- const LA = 'America/Los_Angeles';
11
- // A Wednesday
12
- const NOW = new Date('2026-07-22T19:00:00Z');
13
-
14
- /*
15
- * Render the query string a write produces, for readable assertions.
16
- */
17
-
18
- function write(
19
- current: string,
20
- next: Parameters<typeof writeCalendarUrlState>[1],
21
- ) {
22
- return writeCalendarUrlState(
23
- new URLSearchParams(current),
24
- next,
25
- NOW,
26
- LA,
27
- ).toString();
28
- }
29
-
30
- describe('view slugs', () => {
31
- it('spells views the way a person would read them', () => {
32
- expect(getCalendarViewSlug('FOUR_DAYS')).toBe('4day');
33
- expect(getCalendarViewSlug('WEEK')).toBe('week');
34
- expect(getCalendarViewSlug('AGENDA')).toBe('agenda');
35
- });
36
-
37
- it('round-trips every slug', () => {
38
- for (const view of [
39
- 'DAY',
40
- 'FOUR_DAYS',
41
- 'WEEK',
42
- 'MONTH',
43
- 'YEAR',
44
- 'AGENDA',
45
- ] as const) {
46
- expect(parseCalendarViewSlug(getCalendarViewSlug(view))).toBe(view);
47
- }
48
- });
49
-
50
- it('still accepts the enum spelling from an older link', () => {
51
- expect(parseCalendarViewSlug('FOUR_DAYS')).toBe('FOUR_DAYS');
52
- expect(parseCalendarViewSlug('month')).toBe('MONTH');
53
- });
54
-
55
- it('falls back to the week rather than throwing', () => {
56
- expect(parseCalendarViewSlug('nonsense')).toBe('WEEK');
57
- expect(parseCalendarViewSlug(null)).toBe('WEEK');
58
- });
59
- });
60
-
61
- describe('readCalendarUrlState', () => {
62
- it('reads a bare URL as this week, everything', () => {
63
- const state = readCalendarUrlState(new URLSearchParams(''), NOW, LA);
64
-
65
- expect(state.view).toBe('WEEK');
66
- expect(getCalendarDateKey(state.anchorDate, LA)).toBe('2026-07-22');
67
- expect(state.mineOnly).toBe(false);
68
- expect(state.hiddenCalendarIds).toEqual([]);
69
- });
70
-
71
- it('reads a full URL', () => {
72
- const state = readCalendarUrlState(
73
- new URLSearchParams('v=month&d=2026-03-01&me=1&hide=a,b'),
74
- NOW,
75
- LA,
76
- );
77
-
78
- expect(state.view).toBe('MONTH');
79
- expect(getCalendarDateKey(state.anchorDate, LA)).toBe('2026-03-01');
80
- expect(state.mineOnly).toBe(true);
81
- expect(state.hiddenCalendarIds).toEqual(['a', 'b']);
82
- });
83
-
84
- it('ignores blank entries in the calendar list', () => {
85
- const state = readCalendarUrlState(
86
- new URLSearchParams('hide=a,,b,'),
87
- NOW,
88
- LA,
89
- );
90
-
91
- expect(state.hiddenCalendarIds).toEqual(['a', 'b']);
92
- });
93
- });
94
-
95
- describe('writeCalendarUrlState', () => {
96
- it('writes nothing at all for the defaults', () => {
97
- // The whole point: an untouched calendar has a clean URL
98
- expect(
99
- write('', {
100
- view: 'WEEK',
101
- anchorDate: NOW,
102
- mineOnly: false,
103
- hiddenCalendarIds: [],
104
- }),
105
- ).toBe('');
106
- });
107
-
108
- it('writes only what differs from the default', () => {
109
- expect(write('', { view: 'MONTH' })).toBe('v=month');
110
- expect(write('', { mineOnly: true })).toBe('me=1');
111
- expect(write('', { hiddenCalendarIds: ['a', 'b'] })).toBe('hide=a%2Cb');
112
- });
113
-
114
- it('omits the date when it is today', () => {
115
- expect(write('', { anchorDate: new Date('2026-07-22T23:00:00Z') })).toBe(
116
- '',
117
- );
118
- });
119
-
120
- it('writes the date when it is not today', () => {
121
- expect(write('', { anchorDate: new Date('2026-08-01T12:00:00Z') })).toBe(
122
- 'd=2026-08-01',
123
- );
124
- });
125
-
126
- it('resolves "today" in the calendar zone, not in UTC', () => {
127
- // 2026-07-23T02:00Z is still the 22nd in Los Angeles, so it is today
128
- // and should produce no parameter at all
129
- expect(write('', { anchorDate: new Date('2026-07-23T02:00:00Z') })).toBe(
130
- '',
131
- );
132
- });
133
-
134
- it('clears a parameter when it returns to the default', () => {
135
- expect(write('v=month', { view: 'WEEK' })).toBe('');
136
- expect(write('me=1', { mineOnly: false })).toBe('');
137
- expect(write('hide=a', { hiddenCalendarIds: [] })).toBe('');
138
- expect(write('d=2026-08-01', { anchorDate: NOW })).toBe('');
139
- });
140
-
141
- it('leaves untouched keys alone', () => {
142
- // The calendar does not own the whole query string
143
- expect(write('v=month', { mineOnly: true })).toBe('v=month&me=1');
144
- });
145
-
146
- it('preserves an unrelated parameter somebody else put there', () => {
147
- const result = write('ref=email&v=month', { view: 'WEEK' });
148
-
149
- expect(result).toBe('ref=email');
150
- });
151
-
152
- it('changes nothing for keys it was not asked about', () => {
153
- expect(write('v=month&me=1&d=2026-08-01', {})).toBe(
154
- 'v=month&me=1&d=2026-08-01',
155
- );
156
- });
157
-
158
- it('produces a readable full URL', () => {
159
- expect(
160
- write('', {
161
- view: 'MONTH',
162
- anchorDate: new Date('2026-08-01T12:00:00Z'),
163
- mineOnly: true,
164
- }),
165
- ).toBe('v=month&d=2026-08-01&me=1');
166
- });
167
- });
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "allowImportingTsExtensions": true,
7
- "jsx": "react-jsx",
8
- "noEmit": true,
9
- "strict": true,
10
- "esModuleInterop": true
11
- },
12
- "include": ["src/**/*"]
13
- }
package/vitest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- // Rendering tests live in apps/marketday/tests instead: vitest's jsdom
7
- // environment cannot resolve modules from a directory whose name
8
- // contains a colon, and this package is "@jsb188:calendar"
9
- include: ['tests/**/*.test.ts?(x)'],
10
- },
11
- });