Skip to main content

Worker Registration

Revision 1.1 (2025-12-31) - Updated blacklist location, added save-training endpoint

Feature Summary

Worker Registration (ทะเบียนผู้ปฏิบัติงาน) allows management of workers associated with contractors. The feature supports CRUD operations, training status management, and blacklist functionality.

Key Capabilities:

  • View, create, edit, and delete workers
  • Manage worker training status (pass/fail/expiry)
  • Toggle blacklist status with reason tracking
  • Role-based access control

Role Matrix

Revision 1.1 (2025-12-31) - Added "Edit training status" row

ActionAdminPurchasingWork OwnerSafety OfficerWorkspace OwnerContractor
View all workersOwn only
Create worker
Edit worker (general info)Own only
Edit training status
Delete workerOwn only
Toggle blacklist

Legend:

  • ✅ = Full access
  • ❌ = No access
  • Own only = Access restricted to workers belonging to contractor's company

Backend Test Report

Location: backend/tests/http/workers/ Tested: 2025-12-30

API Endpoints

MethodEndpointDescriptionTested
POST/api/workers/searchSearch workers
POST/api/workers/createCreate new worker
GET/api/workers/get/{id}Get worker details
POST/api/workers/saveSave worker (Contractor only)
POST/api/workers/save-trainingSave training data (Safety Officer only)
POST/api/workers/removeDelete worker
POST/api/workers/toggleBlacklistToggle blacklist status

Test Results by Role

Test SectionAdminSafety OfficerContractor
Search (TC-1.x)✅ (filtered)
Create (TC-2.x)403403
Get (TC-3.x)✅ (own)
Save (TC-4.x)403403✅ (own)
Save Training (TC-5.x)403403
Blacklist (TC-6.x)403403
Remove (TC-7.x)403403✅ (own)

Total: All critical test cases passed

Frontend Test Report

Location: frontend/e2e/workers.spec.ts Tested: 2025-12-30

E2E Test Results

Test IDDescriptionResult
TC-WRK-1Contractor can view worker list✅ Pass
TC-WRK-2Safety Officer can view all workers✅ Pass
TC-WRK-3Admin can view all workers✅ Pass
TC-WRK-4Contractor can create new worker✅ Pass
TC-WRK-5Safety Officer cannot create worker✅ Pass
TC-WRK-6Contractor can edit own worker✅ Pass
TC-WRK-7Safety Officer views worker readonly✅ Pass
TC-WRK-8Safety Officer can access training tab✅ Pass
TC-WRK-9Contractor views training tab readonly✅ Pass
TC-WRK-10Safety Officer can open blacklist dialog✅ Pass
TC-WRK-11Contractor blacklist attempt returns error✅ Pass
TC-WRK-12Contractor can delete worker✅ Pass

Summary: 12 passed, 0 failed (50.5s)

Components Tested

  • worker-setting.component.ts - Main container component
  • worker-setting-list.component.ts - Worker list table
  • worker-setting-list-toolbar.component.ts - Toolbar with search/filters
  • worker-setting-form.component.ts - Edit form with tabs
  • worker-setting-form-general.component.ts - General info tab
  • worker-setting-form-training.component.ts - Training status tab
  • dialog-blacklist.component.ts - Blacklist dialog

Manual Test Cases

Prerequisites

  • Backend server running on http://localhost:5000
  • Frontend running on http://localhost:4200
  • Test accounts available (see Test Data section)
  • Modern browser (Chrome recommended)
  • At least one worker exists in the system

Test Data

Test Users

RoleEmailPasswordAccess Level
Admintn@thaiscada.comTest1234*View all workers, no edit
Safety Officersafety-supervisor@outlook.comTest1234*View all, training approval, blacklist
Contractorsafety-contractor1-0@outlook.comTest1234*CRUD own workers only

Test Data for Creating Workers

FieldValue
ชื่อ (First Name)ทดสอบ
สกุล (Last Name)ผู้ปฏิบัติงาน
เลขบัตรประชาชน (ID Card)1234567890123
โทรศัพท์ (Phone)0812345678
Emailtest-worker@example.com

All Roles: เครื่องมือ (Tools) → ทะเบียนผู้ปฏิบัติงาน (Worker Registration) URL: /tools/settings/worker

Test Summary

CategoryTotal
1. Navigation & Access4
2. View Worker List3
3. Create Worker4
4. Edit Worker4
5. Training Status3
6. Blacklist4
7. Delete Worker3
Total25

1. Navigation & Access Tests

TC-WRK-M001: Contractor can access worker management

Precondition: User is logged in as Contractor

StepActionExpected Result
1Click "เครื่องมือ" (Tools) menu in headerTools dropdown menu opens
2Locate "ทะเบียนผู้ปฏิบัติงาน" menu itemMenu item visible
3Click "ทะเบียนผู้ปฏิบัติงาน"Page loads
4Verify URLURL is /tools/settings/worker
5Verify page contentWorker list table displayed
6Verify "เพิ่มผู้ปฏิบัติงาน" button visibleAdd button present

TC-WRK-M002: Safety Officer can access worker management

Precondition: User is logged in as Safety Officer

StepActionExpected Result
1Login as Safety Officer: safety-supervisor@outlook.comLogin successful
2Navigate to เครื่องมือ → ทะเบียนผู้ปฏิบัติงานWorker management page loads
3Verify URLURL is /tools/settings/worker
4Verify worker list displayedTable with workers visible
5Verify "เพิ่มผู้ปฏิบัติงาน" button NOT visibleAdd button NOT present
6Verify contractor filter dropdown visibleFilter dropdown present

Safety Officer can view all workers but cannot create new ones.


TC-WRK-M003: Admin can access worker management

Precondition: User is logged in as Admin

StepActionExpected Result
1Login as Admin: tn@thaiscada.comLogin successful
2Navigate to เครื่องมือ → ทะเบียนผู้ปฏิบัติงานWorker management page loads
3Verify worker list displayedTable with workers visible
4Verify "เพิ่มผู้ปฏิบัติงาน" button NOT visibleAdd button NOT present
5Verify contractor filter dropdown visibleFilter dropdown present

Admin can view all workers but cannot create/edit.


TC-WRK-M004: Purchasing user cannot access worker management

Precondition: User is logged in as Purchasing role

StepActionExpected Result
1Login as Purchasing: safety-purchasing@outlook.comLogin successful
2Check if "ทะเบียนผู้ปฏิบัติงาน" menu item existsMenu item NOT visible or access denied
3Try direct URL navigation to /tools/settings/workerRedirected or access denied

Purchasing role does NOT have access to worker management.


2. View Worker List Tests

TC-WRK-M005: View worker list with table columns

Precondition: Logged in as Contractor, on Worker Management page

StepActionExpected Result
1Navigate to Worker Management pagePage loads with worker list
2Verify table headersColumns: ชื่อ-สกุล, เลขบัตรประชาชน, ประเภท, สถานะอบรม, Actions
3Verify worker rowsEach row shows worker name, ID card, type, training status
4Verify row actionsEach row has "แก้ไข" button and options menu (⌄) with "ลบ" option

Contractor view does NOT show "บริษัท" column (filtered to own company). Options menu (⌄) is only visible for Contractors (Admin/SO do not see it).


TC-WRK-M006: Safety Officer sees company column

Precondition: Logged in as Safety Officer

StepActionExpected Result
1Navigate to Worker Management pagePage loads
2Verify table has "บริษัท" (Company) columnColumn visible between ประเภท and สถานะอบรม
3Verify company names displayedEach row shows contractor company name
4Verify no options menu (⌄)Only "แก้ไข" button visible, no dropdown menu

Admin also sees company column. Neither Admin nor Safety Officer sees the options menu (⌄).


TC-WRK-M007: Search workers by keyword

Precondition: On Worker Management page with workers listed

StepActionExpected Result
1Locate search barSearch input visible in toolbar
2Enter worker name in searchText entered
3Press Enter or wait for searchList filtered
4Verify filtered resultsOnly matching workers displayed
5Clear searchAll workers displayed again

Search works on name, ID card, phone, email.


3. Create Worker Tests

TC-WRK-M008: Click add button opens form

Precondition: Logged in as Contractor, on Worker Management page

StepActionExpected Result
1Click "เพิ่มผู้ปฏิบัติงาน" buttonForm opens
2Verify form tabs displayed3 tabs: ข้อมูลส่วนบุคคล, เอกสารแนบ, สถานะการอบรม
3Verify general tab is activeFirst tab selected by default
4Verify "บันทึก" and "ยกเลิก" buttonsBoth buttons visible

TC-WRK-M009: Verify all form fields present

Precondition: Worker create form is open

StepActionExpected Result
1Verify worker type radio buttonsประเภท: พนักงาน, 3rd Party (Specialist)
2Verify contractor dropdownบริษัทผู้รับเหมา* field present
3Verify ID card fieldเลขบัตรประชาชน* field present
4Verify name fieldsชื่อ* and สกุล* fields present
5Verify phone fieldโทรศัพท์* field present
6Verify email fieldEmail field present (optional)

Fields marked with * are required.


TC-WRK-M010: Create worker with valid data

Precondition: Worker create form is open

StepActionExpected Result
1Select worker type: พนักงานRadio selected
2Enter ID card: 1234567890123Field populated
3Enter first name: ทดสอบField populated
4Enter last name: ผู้ปฏิบัติงานField populated
5Enter phone: 0812345678Field populated
6Click "บันทึก" buttonSave triggered
7Verify success snackbar"บันทึกสำเร็จ" message appears
8Verify returned to listWorker list displayed
9Verify new worker in listNew worker visible in table

TC-WRK-M011: Cancel create discards changes

Precondition: Worker create form is open with data entered

StepActionExpected Result
1Enter some data in formFields populated
2Click "ยกเลิก" buttonCancel triggered
3Verify returned to listWorker list displayed
4Verify worker NOT createdNew worker not in list

4. Edit Worker Tests

TC-WRK-M012: Click edit button opens form with data

Precondition: Logged in as Contractor, workers exist in list

StepActionExpected Result
1Locate a worker rowRow visible
2Click "แก้ไข" buttonEdit form opens
3Verify form populatedAll fields show current worker data
4Verify "บันทึก" button visibleSave button present

TC-WRK-M013: Edit worker name

Precondition: Worker edit form is open

StepActionExpected Result
1Note current first nameRecord existing value
2Clear first name fieldField is empty
3Enter new name: แก้ไขแล้วThai characters accepted
4Click "บันทึก" buttonSave triggered
5Verify success snackbar"บันทึกสำเร็จ" message appears
6Verify updated name in listNew name shown in table

Remember to restore original value after test.


TC-WRK-M014: Safety Officer views worker in readonly mode

Precondition: Logged in as Safety Officer

StepActionExpected Result
1Navigate to Worker ManagementWorker list displayed
2Click "แก้ไข" on any workerForm opens
3Verify "บันทึก" button NOT visibleSave button hidden
4Verify "กลับ" button visibleBack button present instead of Cancel
5Verify form fields are readonlyCannot edit general info

Safety Officer can only edit training status, not general info.


TC-WRK-M015: Cancel edit discards changes

Precondition: Worker edit form is open with changes made

StepActionExpected Result
1Make changes to worker formValues modified
2Click "ยกเลิก" buttonCancel triggered
3Click "แก้ไข" on same workerEdit form opens
4Verify original valuesChanges were NOT saved

5. Training Status Tests

TC-WRK-M016: Navigate to training tab

Precondition: Worker edit form is open

StepActionExpected Result
1Locate "สถานะการอบรม" tabTab visible
2Click "สถานะการอบรม" tabTab content displayed
3Verify training status fieldStatus dropdown or display visible

TC-WRK-M017: Safety Officer can update training status

Precondition: Logged in as Safety Officer, on training tab

StepActionExpected Result
1Navigate to training tabTraining content displayed
2Verify training controls editableCan modify training status
3Update training statusStatus changed
4Click save (if applicable)Changes saved

Only Safety Officer can edit training status.


TC-WRK-M018: Contractor cannot edit training status

Precondition: Logged in as Contractor, on training tab

StepActionExpected Result
1Navigate to training tabTraining content displayed
2Verify training controls are readonlyCannot modify training status

Contractor can view training status but cannot edit.


6. Blacklist Tests

Note: Blacklist controls are now located in the Training tab form (moved from context menu in v1.1)

TC-WRK-M019: Access blacklist controls in Training tab

Precondition: Logged in as Safety Officer, worker edit form open

StepActionExpected Result
1Click "สถานะการอบรม" tabTraining tab content displayed
2Scroll to "สถานะ Blacklist" sectionBlacklist section visible
3Verify current status shown"ไม่ได้ถูกติด Blacklist" with green checkmark
4Verify "ติด Blacklist" buttonRed button visible

TC-WRK-M020: Add worker to blacklist

Precondition: On Training tab, worker not blacklisted

StepActionExpected Result
1Click "ติด Blacklist" button (red)Blacklist dialog opens
2Verify dialog fieldsReason field present
3Enter reason: ทดสอบ BlacklistReason entered
4Click confirm buttonDialog closes
5Verify success snackbarSuccess message appears
6Verify Training tab updatesShows "ถูกติด Blacklist" with reason
7Return to list and verifyWorker row highlighted red with block icon

TC-WRK-M021: Remove worker from blacklist

Precondition: Worker is blacklisted, on Training tab

StepActionExpected Result
1Verify blacklist status shown"ถูกติด Blacklist" with reason displayed
2Click "ปลด Blacklist" buttonConfirmation dialog appears
3Confirm removalDialog closes
4Verify success snackbarSuccess message appears
5Verify Training tab updatesShows "ไม่ได้ถูกติด Blacklist"
6Return to list and verifyRow no longer red, no block icon

TC-WRK-M022: Contractor cannot access blacklist controls

Precondition: Logged in as Contractor, on worker edit form

StepActionExpected Result
1Navigate to Training tabTraining content displayed
2Scroll to Blacklist sectionSection visible
3Verify no blacklist button"ติด Blacklist" button NOT visible
4Verify status is read-onlyCannot modify blacklist status

Contractors can only view blacklist status, not toggle it.


7. Delete Worker Tests

TC-WRK-M023: Open delete confirmation dialog

Precondition: Logged in as Contractor, own worker exists

StepActionExpected Result
1Click options menu (⌄) on worker rowDropdown opens
2Verify delete option"ลบ" (Delete) visible
3Click "ลบ"Confirmation dialog appears
4Verify dialog textDialog shows worker name and confirms delete
5Verify dialog buttons"ตกลง" and "ยกเลิก" buttons visible

TC-WRK-M024: Cancel delete keeps worker

Precondition: Delete confirmation dialog is showing

StepActionExpected Result
1Click "ยกเลิก" buttonDialog closes
2Verify worker still in listWorker NOT deleted

TC-WRK-M025: Confirm delete removes worker

Precondition: Delete confirmation dialog is showing

StepActionExpected Result
1Click "ตกลง" buttonDelete triggered
2Verify success snackbar"ลบสำเร็จ" message appears
3Verify worker removed from listWorker no longer in table

Create a test worker before this test to avoid deleting real data.


Labels verified against:

  • worker-setting-list.component.ts (table headers, menu actions)
  • worker-setting-form-general.component.ts (form field labels)
  • worker-setting-list-toolbar.component.ts (toolbar buttons)
  • dialog-blacklist.component.ts (dialog text)