diff --git a/js/modules/specialShifts.js b/js/modules/specialShifts.js index a376a4c..bac31ba 100644 --- a/js/modules/specialShifts.js +++ b/js/modules/specialShifts.js @@ -229,6 +229,16 @@ async function loadSpecialShifts() { } } +/** + * お知らせ欄に表示する特別シフトの日時文字列を組み立てる + * 日付と時間帯は半角スペース 1 つで区切る(全角だと間が空きすぎて見える) + * @param {{date: string, start_time: string, end_time: string}} shift + * @returns {string} 例: "2026-10-08 12:30-15:30" + */ +function formatSpecialShiftSchedule(shift) { + return `${shift.date} ${shift.start_time}-${shift.end_time}`; +} + /** * 特別シフト募集お知らせを表示する関数(一般ユーザー向け) */ @@ -263,7 +273,7 @@ function displaySpecialShiftAnnouncement() { list.innerHTML = futureShifts.map(shift => { const name = shift.name || '名称未設定'; const dateKey = normalizeShiftDate(shift.date); - return `
  • 「${escapeHtml(name)}」の特別シフトを募集中(${escapeHtml(shift.date)} ${escapeHtml(shift.start_time)}-${escapeHtml(shift.end_time)})
  • `; + return `
  • 「${escapeHtml(name)}」の特別シフトを募集中(${escapeHtml(formatSpecialShiftSchedule(shift))})
  • `; }).join(''); list.querySelectorAll('.announcement-link').forEach(link => { @@ -578,3 +588,10 @@ async function handleDeleteSpecialShiftFromList(event) { button.textContent = originalText; } } + +// テストから実コードを検証できるようにするエクスポートガード +// (ブラウザでは module が未定義のため no-op になる) +// 方針: docs/refactoring/phase-1-test-foundation.md +if (typeof module !== 'undefined' && module.exports) { + module.exports = { formatSpecialShiftSchedule }; +} diff --git a/test/special-shift-announcement-spacing.test.js b/test/special-shift-announcement-spacing.test.js new file mode 100644 index 0000000..f055076 --- /dev/null +++ b/test/special-shift-announcement-spacing.test.js @@ -0,0 +1,24 @@ +/** + * お知らせ欄の特別シフト表示: 日付と時間帯の間隔 + * + * 回帰防止: 日付と時間帯を全角スペースで区切っていたため、 + * 「2026-10-08 12:30-15:30」のように間が空きすぎて見えていた。 + * 半角スペース 1 つで区切る。 + * + * このテストは実コード(js/modules/specialShifts.js)を直接 import して検証する。 + * 方針: docs/refactoring/phase-1-test-foundation.md + */ + +const { formatSpecialShiftSchedule } = require('../js/modules/specialShifts.js'); + +describe('お知らせ欄の特別シフトの日時表示', () => { + const shift = { date: '2026-10-08', start_time: '12:30', end_time: '15:30' }; + + test('日付と時間帯を半角スペース 1 つで区切る', () => { + expect(formatSpecialShiftSchedule(shift)).toBe('2026-10-08 12:30-15:30'); + }); + + test('全角スペースを含まない', () => { + expect(formatSpecialShiftSchedule(shift)).not.toContain(' '); + }); +});