From ac23ed5677e7ea207ca36eabe7e634f68f16ff0b Mon Sep 17 00:00:00 2001 From: Junya Ishihara Date: Thu, 8 Oct 2026 13:23:51 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E6=8B=AC=E5=89=8A=E9=99=A4=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AE=20UUID=20=E6=8A=BD=E5=87=BA?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=20import=20=E3=81=AB=E5=88=87=E3=82=8A=E6=9B=BF?= =?UTF-8?q?=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test/bulk-delete.test.js の UUID 抽出テストは、カレンダー用と全シフト一覧用の 取り出し処理をテスト内にコピーして検証していた。実コードは collectUuidsByType() に統一され、全シフト一覧の属性も data-shift-uuid から data-uuids に変わったため、コピーは存在しないコードを検証していた。 コピーを削除し、js/modules/shifts.js の collectUuidsByType() を直接 import して検証するようにした。全シフト一覧で特別シフト申請の行が specialUuids に 振り分けられることのテストも追加した。 同じファイルの「削除フロー」のコピー(runBulkDeleteFlow)は、実コードが 無名のイベントハンドラのため import できず、今回は変更していない。 Co-Authored-By: Claude Opus 5.5 --- test/bulk-delete.test.js | 66 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/test/bulk-delete.test.js b/test/bulk-delete.test.js index e6136da..5340efd 100644 --- a/test/bulk-delete.test.js +++ b/test/bulk-delete.test.js @@ -4,6 +4,8 @@ * および削除フローの動作を検証する */ +const { collectUuidsByType } = require('../js/modules/shifts.js'); + // ---- インラインロジック定義(モジュール非依存) ---- function createBulkActionBarHTML(barId, countId, btnId) { @@ -104,43 +106,31 @@ describe('複数選択削除機能テスト', () => { // ------------------------------------------------------------------ describe('UUID抽出ロジック', () => { - describe('カレンダー: data-uuids (カンマ区切り)', () => { - // calendar.js: setupCalendarBulkDelete の UUID 抽出ロジック - function extractCalendarUuids(checkedBoxes) { - const allUuids = []; - checkedBoxes.forEach((cb) => { - const uuidsStr = cb.getAttribute('data-uuids'); - if (uuidsStr) - uuidsStr.split(',').forEach((uuid) => { - if (uuid) allUuids.push(uuid); - }); - }); - return allUuids; - } + // 実コード(js/modules/shifts.js の collectUuidsByType)を直接 import して検証する。 + // カレンダー / 自分のシフト / 全シフト一覧の一括削除はすべてこの関数で UUID を取り出す。 + function checkbox(uuids, type = null) { + const attrs = { 'data-uuids': uuids, 'data-type': type }; + return { getAttribute: (name) => (name in attrs ? attrs[name] : null) }; + } + describe('カレンダー: data-uuids (カンマ区切り)', () => { test('複数チェックボックスの UUID を正しく抽出・フラット化すること', () => { - const boxes = [ - { getAttribute: () => 'uuid-a1,uuid-a2' }, - { getAttribute: () => 'uuid-b1' }, - ]; - expect(extractCalendarUuids(boxes)).toEqual(['uuid-a1', 'uuid-a2', 'uuid-b1']); + const boxes = [checkbox('uuid-a1,uuid-a2'), checkbox('uuid-b1')]; + expect(collectUuidsByType(boxes).regularUuids).toEqual(['uuid-a1', 'uuid-a2', 'uuid-b1']); }); test('空文字列の UUID を除外すること', () => { - const boxes = [{ getAttribute: () => 'uuid-1,,uuid-2' }]; - expect(extractCalendarUuids(boxes)).toEqual(['uuid-1', 'uuid-2']); + const boxes = [checkbox('uuid-1,,uuid-2')]; + expect(collectUuidsByType(boxes).regularUuids).toEqual(['uuid-1', 'uuid-2']); }); test('data-uuids が null のチェックボックスを無視すること', () => { - const boxes = [ - { getAttribute: () => null }, - { getAttribute: () => 'uuid-ok' }, - ]; - expect(extractCalendarUuids(boxes)).toEqual(['uuid-ok']); + const boxes = [checkbox(null), checkbox('uuid-ok')]; + expect(collectUuidsByType(boxes).regularUuids).toEqual(['uuid-ok']); }); test('チェックボックスが空のとき空配列を返すこと', () => { - expect(extractCalendarUuids([])).toEqual([]); + expect(collectUuidsByType([])).toEqual({ regularUuids: [], specialUuids: [] }); }); }); @@ -170,22 +160,18 @@ describe('複数選択削除機能テスト', () => { }); }); - describe('全シフト一覧: data-shift-uuid (単一)', () => { - // allShiftsTable.js: Array.from(checkedBoxes).map(cb => cb.getAttribute('data-shift-uuid')) - function extractAllShiftsUuids(checkedBoxes) { - return Array.from(checkedBoxes).map((cb) => cb.getAttribute('data-shift-uuid')); - } - - test('各チェックボックスの data-shift-uuid を配列として抽出すること', () => { - const boxes = [ - { getAttribute: (attr) => (attr === 'data-shift-uuid' ? 'uuid-x' : null) }, - { getAttribute: (attr) => (attr === 'data-shift-uuid' ? 'uuid-y' : null) }, - ]; - expect(extractAllShiftsUuids(boxes)).toEqual(['uuid-x', 'uuid-y']); + describe('全シフト一覧: data-uuids (単一) + data-type', () => { + test('各チェックボックスの data-uuids を配列として抽出すること', () => { + const boxes = [checkbox('uuid-x', 'regular'), checkbox('uuid-y', 'regular')]; + expect(collectUuidsByType(boxes).regularUuids).toEqual(['uuid-x', 'uuid-y']); }); - test('チェックボックスが空のとき空配列を返すこと', () => { - expect(extractAllShiftsUuids([])).toEqual([]); + test('特別シフト申請の行は specialUuids に振り分けること', () => { + const boxes = [checkbox('uuid-x', 'regular'), checkbox('uuid-s', 'special')]; + expect(collectUuidsByType(boxes)).toEqual({ + regularUuids: ['uuid-x'], + specialUuids: ['uuid-s'], + }); }); }); });