tkadkghdlf commited on
Commit
e20f8a3
ยท
verified ยท
1 Parent(s): d524b9d

Sync DemoService 71e39200bd7ee6ffe0482536a393bf008d41a645

Browse files
main/app/route/[id]/page.tsx CHANGED
@@ -6,6 +6,7 @@ import { useParams, useRouter, useSearchParams } from "next/navigation";
6
  import {
7
  DEFAULT_MAP_CENTER,
8
  formatRelativeKoreanTime,
 
9
  readCommunityPostsFromStorage,
10
  writeCommunityPostsToStorage,
11
  type CommunityPost,
@@ -19,6 +20,7 @@ import {
19
  import { loadSharedRoutePost, invalidateCommunityRouteData } from "../../_utils/communityRouteData";
20
  import CommunityRouteLoading from "../../_components/CommunityRouteLoading";
21
  import { readRecentRoutePreview } from "../../_utils/recentRoutePreview";
 
22
 
23
  const LeafletMap = dynamic(() => import("../../_components/LeafletMap"), {
24
  ssr: false,
@@ -245,6 +247,30 @@ export default function Page() {
245
  }
246
  };
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  if (loadedRouteId !== routeId) {
249
  return <main className="rts-page"><section className="rts-shell"><CommunityRouteLoading /></section></main>;
250
  }
@@ -455,6 +481,7 @@ export default function Page() {
455
  <>
456
  <button
457
  type="button"
 
458
  className="rts-primary-button h-[44px] px-5"
459
  >
460
  ์ด ๋ฃจํŠธ๋กœ ๋‹ฌ๋ฆฌ๊ธฐ
 
6
  import {
7
  DEFAULT_MAP_CENTER,
8
  formatRelativeKoreanTime,
9
+ parseNumericText,
10
  readCommunityPostsFromStorage,
11
  writeCommunityPostsToStorage,
12
  type CommunityPost,
 
20
  import { loadSharedRoutePost, invalidateCommunityRouteData } from "../../_utils/communityRouteData";
21
  import CommunityRouteLoading from "../../_components/CommunityRouteLoading";
22
  import { readRecentRoutePreview } from "../../_utils/recentRoutePreview";
23
+ import { prepareCoursePreview } from "../../_utils/coursePreview";
24
 
25
  const LeafletMap = dynamic(() => import("../../_components/LeafletMap"), {
26
  ssr: false,
 
247
  }
248
  };
249
 
250
+ const handleStartRoute = () => {
251
+ if (!route) return;
252
+ const coordinates = route.map?.polyline ?? [];
253
+ if (coordinates.length < 2) {
254
+ setActionError("์ด ๋ฃจํŠธ์—๋Š” ๋‹ฌ๋ฆฌ๊ธฐ์— ํ•„์š”ํ•œ ๊ฒฝ๋กœ ์ขŒํ‘œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฃจํŠธ๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.");
255
+ return;
256
+ }
257
+
258
+ setActionError(null);
259
+ try {
260
+ router.push(prepareCoursePreview({
261
+ id: `post-${route.id}`,
262
+ title: route.title || "๊ณต์œ ๋œ ๋Ÿฌ๋‹ ๋ฃจํŠธ",
263
+ place: route.map?.address || route.title,
264
+ distanceKm: parseNumericText(route.stats.distance),
265
+ center: route.map?.center ?? coordinates[0],
266
+ route: coordinates,
267
+ source: "๊ฒŒ์‹œ๋ฌผ ์ฝ”์Šค",
268
+ }));
269
+ } catch {
270
+ setActionError("๋Ÿฌ๋‹ ์ค€๋น„ ํ™”๋ฉด์„ ์—ด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์„ธ์š”.");
271
+ }
272
+ };
273
+
274
  if (loadedRouteId !== routeId) {
275
  return <main className="rts-page"><section className="rts-shell"><CommunityRouteLoading /></section></main>;
276
  }
 
481
  <>
482
  <button
483
  type="button"
484
+ onClick={handleStartRoute}
485
  className="rts-primary-button h-[44px] px-5"
486
  >
487
  ์ด ๋ฃจํŠธ๋กœ ๋‹ฌ๋ฆฌ๊ธฐ
tools/test-shared-route-start.cjs ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Exercise the rendered shared-route button without starting a real workout.
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const vm = require('node:vm');
6
+ const ts = require('../main/node_modules/typescript');
7
+ const root = path.resolve(__dirname, '../main/app');
8
+ const flush = async () => { for (let i = 0; i < 20; i++) await Promise.resolve(); };
9
+
10
+ function findButton(node, label) {
11
+ if (!node || typeof node !== 'object') return null;
12
+ if (node.type === 'button' && node.props.children === label) return node;
13
+ for (const child of [node.props?.children].flat()) {
14
+ const match = findButton(child, label);
15
+ if (match) return match;
16
+ }
17
+ return null;
18
+ }
19
+
20
+ async function fixture(polyline, failStorage = false) {
21
+ const shared = {
22
+ id: 'shared-7', routeId: '7', title: '๊ณต์œ ๋œ ๊ฐ•๋ณ€ ๋ฃจํŠธ', nickname: 'fixture',
23
+ content: 'fixture', createdAt: new Date().toISOString(), comments: [],
24
+ stats: { distance: '4.50km', achievement: '100', pace: '6:00', calories: '200', time: '27:00', bpm: '120' },
25
+ map: { center: [37.5, 127], polyline, mode: 'nearby', address: 'ํ…Œ์ŠคํŠธ ์ง€์—ญ' },
26
+ };
27
+ const values = new Map();
28
+ const storage = { getItem: key => values.get(key) ?? null, setItem(key, value) {
29
+ if (failStorage) throw Error('QuotaExceededError');
30
+ values.set(key, value);
31
+ } };
32
+ const window = new EventTarget();
33
+ Object.assign(window, {
34
+ sessionStorage: storage, localStorage: storage,
35
+ location: { pathname: '/route/shared-7', search: '?source=shared' },
36
+ crypto: { randomUUID: () => 'fixture-course-key' },
37
+ });
38
+ const states = [];
39
+ const effects = [];
40
+ const navigations = [];
41
+ let cursor = 0;
42
+ const react = {
43
+ useState(initial) {
44
+ const key = cursor++;
45
+ if (!(key in states)) states[key] = initial;
46
+ return [states[key], next => { states[key] = typeof next === 'function' ? next(states[key]) : next; }];
47
+ },
48
+ useEffect: effect => effects.push(effect),
49
+ useMemo: value => value(),
50
+ };
51
+ const modules = new Map();
52
+ function load(filename) {
53
+ const absolute = path.resolve(root, filename);
54
+ if (modules.has(absolute)) return modules.get(absolute);
55
+ const exports = {}; modules.set(absolute, exports);
56
+ const requireFixture = name => {
57
+ if (name === 'react') return react;
58
+ if (name === 'react/jsx-runtime') return { jsx: (type, props) => ({ type, props }), jsxs: (type, props) => ({ type, props }), Fragment: 'Fragment' };
59
+ if (name === 'next/dynamic') return { __esModule: true, default: () => 'LeafletMap' };
60
+ if (name === 'next/navigation') return {
61
+ useParams: () => ({ id: shared.id }), useRouter: () => ({ push: url => navigations.push(url) }),
62
+ useSearchParams: () => new URLSearchParams(),
63
+ };
64
+ if (name.endsWith('communityRouteData')) return { loadSharedRoutePost: async () => shared, invalidateCommunityRouteData() {} };
65
+ if (name.endsWith('communityApi')) return { fetchCurrentUserIdFromApi: async () => 1 };
66
+ if (name.endsWith('CommunityRouteLoading')) return { __esModule: true, default: 'Loading' };
67
+ const target = path.resolve(path.dirname(absolute), name);
68
+ return load(path.relative(root, target + (fs.existsSync(target + '.ts') ? '.ts' : '.tsx')));
69
+ };
70
+ const code = ts.transpileModule(fs.readFileSync(absolute, 'utf8'), {
71
+ compilerOptions: { module: ts.ModuleKind.CommonJS, jsx: ts.JsxEmit.ReactJSX, target: ts.ScriptTarget.ES2020, esModuleInterop: true },
72
+ }).outputText;
73
+ vm.runInNewContext(`(function(require,exports){${code}\n})`, {
74
+ window, console, URLSearchParams, process: { env: {} },
75
+ }, { filename: absolute })(requireFixture, exports);
76
+ return exports;
77
+ }
78
+ const component = load('route/[id]/page.tsx').default;
79
+ const render = () => { cursor = 0; return component(); };
80
+ render(); effects.splice(0).forEach(effect => effect()); await flush();
81
+ const tree = render();
82
+ const button = findButton(tree, '์ด ๋ฃจํŠธ๋กœ ๋‹ฌ๋ฆฌ๊ธฐ');
83
+ assert.ok(button, 'loaded shared route exposes a run button');
84
+ assert.equal(typeof button.props.onClick, 'function', 'the visible button must have a click action');
85
+ button.props.onClick(); await flush();
86
+ return { navigations, values, states, load };
87
+ }
88
+
89
+ (async () => {
90
+ const coordinates = [[37.5, 127], [37.501, 127.001], [37.502, 127]];
91
+ const ready = await fixture(coordinates);
92
+ assert.equal(ready.navigations.length, 1);
93
+ const destination = new URL(ready.navigations[0], 'http://fixture.local');
94
+ assert.equal(destination.pathname, '/route-results/post-shared-7');
95
+ const course = ready.load('_utils/coursePreview.ts').readCoursePreview(destination.searchParams.get('courseKey'));
96
+ assert.equal(course.title, '๊ณต์œ ๋œ ๊ฐ•๋ณ€ ๋ฃจํŠธ');
97
+ assert.equal(course.distanceKm, 4.5);
98
+ assert.deepEqual(Array.from(course.route, point => Array.from(point)), coordinates);
99
+ assert.equal(course.backHref, '/route/shared-7?source=shared');
100
+ console.log('PASS shared-route click preserves the selected course and opens run preparation');
101
+
102
+ const missing = await fixture([]);
103
+ assert.equal(missing.navigations.length, 0);
104
+ assert.ok(missing.states.some(value => typeof value === 'string' && value.includes('๊ฒฝ๋กœ ์ขŒํ‘œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค')));
105
+ console.log('PASS missing route geometry gives an explanation instead of a silent click');
106
+
107
+ const unavailable = await fixture(coordinates, true);
108
+ assert.equal(unavailable.navigations.length, 0);
109
+ assert.ok(unavailable.states.some(value => typeof value === 'string' && value.includes('๋Ÿฌ๋‹ ์ค€๋น„ ํ™”๋ฉด์„ ์—ด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค')));
110
+ console.log('PASS storage failure is reported without starting an invalid run');
111
+ })().catch(error => { console.error(error); process.exitCode = 1; });