|
| 1 | +import { getTimestamp } from '../support/utils'; |
| 2 | + |
| 3 | +describe('Payroll workflows', () => { |
| 4 | + const suiteTimestamp = getTimestamp(); |
| 5 | + const getDateOffset = (days) => { |
| 6 | + const date = new Date(); |
| 7 | + date.setDate(date.getDate() + days); |
| 8 | + const day = String(date.getDate()).padStart(2, '0'); |
| 9 | + const month = String(date.getMonth() + 1).padStart(2, '0'); |
| 10 | + const year = date.getFullYear(); |
| 11 | + return `${day}-${month}-${year}`; |
| 12 | + }; |
| 13 | + |
| 14 | + // Codes must be ≤ 8 characters (backend limit for program/payment-plan codes). |
| 15 | + const ts = Date.now(); |
| 16 | + const programCode = `PR${ts.toString().slice(-6)}`; |
| 17 | + const programName = `E2E Payroll Program ${suiteTimestamp}`; |
| 18 | + const ppCode = `PP${ts.toString().slice(-6)}`; |
| 19 | + const ppName = `E2E Payroll Plan ${suiteTimestamp}`; |
| 20 | + // Payment cycle codes have no documented 8-char limit; use a longer unique value. |
| 21 | + const cycleCode = `PCY${ts.toString().slice(-5)}`; |
| 22 | + |
| 23 | + const createdPayrolls = new Set(); |
| 24 | + |
| 25 | + const payrollData = (label) => { |
| 26 | + const timestamp = getTimestamp(); |
| 27 | + return { |
| 28 | + name: `E2E Payroll ${label} ${timestamp}`, |
| 29 | + paymentPlanCode: ppCode, |
| 30 | + paymentPlanName: ppName, |
| 31 | + paymentCycleCode: cycleCode, |
| 32 | + dateValidFrom: getDateOffset(0), |
| 33 | + dateValidTo: getDateOffset(30), |
| 34 | + // paymentMethod is omitted → first available method is selected |
| 35 | + }; |
| 36 | + }; |
| 37 | + |
| 38 | + const trackPayroll = (name) => { |
| 39 | + createdPayrolls.add(name); |
| 40 | + }; |
| 41 | + |
| 42 | + before(() => { |
| 43 | + cy.loginAdminInterface(); |
| 44 | + cy.setModuleConfig('fe-core', 'menu-config-sp.json'); |
| 45 | + cy.setModuleConfig('social_protection', 'social-protection-config.json'); |
| 46 | + cy.setModuleConfig('individual', 'individual-config-minimal.json'); |
| 47 | + cy.logoutAdminInterface(); |
| 48 | + |
| 49 | + cy.login(); |
| 50 | + cy.createProgram(programCode, programName, '50', 'INDIVIDUAL'); |
| 51 | + cy.createPaymentPlan({ |
| 52 | + code: ppCode, |
| 53 | + name: ppName, |
| 54 | + benefitPlanName: programName, |
| 55 | + dateValidFrom: getDateOffset(0), |
| 56 | + dateValidTo: getDateOffset(365), |
| 57 | + }); |
| 58 | + // The PaymentCyclePicker in the payroll form searches only ACTIVE cycles. |
| 59 | + // Creating with status ACTIVE triggers a coreAlert dialog; dismiss it below. |
| 60 | + cy.createPaymentCycle({ |
| 61 | + code: cycleCode, |
| 62 | + startDate: getDateOffset(0), |
| 63 | + endDate: getDateOffset(30), |
| 64 | + status: 'ACTIVE', |
| 65 | + }); |
| 66 | + cy.get('body').then(($body) => { |
| 67 | + if ($body.find('[role="dialog"]').length > 0) { |
| 68 | + cy.get('[role="dialog"] .MuiDialogActions-root button').first().click(); |
| 69 | + } |
| 70 | + }); |
| 71 | + cy.logout(); |
| 72 | + }); |
| 73 | + |
| 74 | + after(() => { |
| 75 | + cy.login(); |
| 76 | + // Only PENDING_APPROVAL payrolls have an enabled delete button in the UI. |
| 77 | + // Tests that change the status are responsible for their own cleanup. |
| 78 | + Array.from(createdPayrolls).forEach((name) => { |
| 79 | + cy.deletePayrollFromList(name); |
| 80 | + }); |
| 81 | + cy.deletePaymentPlan(ppName); |
| 82 | + cy.deleteProgram(programName); |
| 83 | + // Payment cycles have no UI delete; cycleCode records accumulate in the DB. |
| 84 | + cy.logout(); |
| 85 | + }); |
| 86 | + |
| 87 | + beforeEach(() => { |
| 88 | + cy.login(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('validates required fields before allowing payroll creation', () => { |
| 92 | + cy.openCreatePayroll(); |
| 93 | + cy.get('[title="Please fill General Information fields first"] button') |
| 94 | + .should('be.disabled'); |
| 95 | + }); |
| 96 | + |
| 97 | + it('creates a payroll successfully', () => { |
| 98 | + const payroll = payrollData('Create'); |
| 99 | + |
| 100 | + cy.createPayroll(payroll); |
| 101 | + trackPayroll(payroll.name); |
| 102 | + |
| 103 | + cy.filterPayrolls({ name: payroll.name }); |
| 104 | + cy.assertPayrollRowVisible({ name: payroll.name }); |
| 105 | + }); |
| 106 | + |
| 107 | + it('searches payrolls by name', () => { |
| 108 | + const targetPayroll = payrollData('Search Target'); |
| 109 | + const otherPayroll = payrollData('Search Other'); |
| 110 | + |
| 111 | + cy.createPayroll(targetPayroll); |
| 112 | + cy.createPayroll(otherPayroll); |
| 113 | + trackPayroll(targetPayroll.name); |
| 114 | + trackPayroll(otherPayroll.name); |
| 115 | + |
| 116 | + cy.filterPayrolls({ name: targetPayroll.name }); |
| 117 | + cy.assertPayrollRowVisible({ name: targetPayroll.name }); |
| 118 | + cy.assertPayrollRowNotVisible({ name: otherPayroll.name }); |
| 119 | + |
| 120 | + cy.filterPayrolls({ name: otherPayroll.name }); |
| 121 | + cy.assertPayrollRowVisible({ name: otherPayroll.name }); |
| 122 | + cy.assertPayrollRowNotVisible({ name: targetPayroll.name }); |
| 123 | + }); |
| 124 | + |
| 125 | + it('views payroll details from the list', () => { |
| 126 | + const payroll = payrollData('View'); |
| 127 | + |
| 128 | + cy.createPayroll(payroll); |
| 129 | + trackPayroll(payroll.name); |
| 130 | + |
| 131 | + cy.openPayrollForViewFromList(payroll.name); |
| 132 | + cy.assertMuiInput('Name', payroll.name); |
| 133 | + }); |
| 134 | + |
| 135 | + it('deletes a PENDING_APPROVAL payroll', () => { |
| 136 | + const payroll = payrollData('Delete'); |
| 137 | + |
| 138 | + cy.createPayroll(payroll); |
| 139 | + // Not tracked: deleted below, so no after() cleanup needed. |
| 140 | + |
| 141 | + cy.deletePayrollFromList(payroll.name); |
| 142 | + cy.filterPayrolls({ name: payroll.name }); |
| 143 | + cy.assertPayrollRowNotVisible({ name: payroll.name }); |
| 144 | + }); |
| 145 | + |
| 146 | + it('shows a newly-created payroll in the pending payrolls list', () => { |
| 147 | + const payroll = payrollData('Pending'); |
| 148 | + |
| 149 | + cy.createPayroll(payroll); |
| 150 | + trackPayroll(payroll.name); |
| 151 | + |
| 152 | + cy.visit('/front/payrollsPending'); |
| 153 | + cy.contains('Payrolls Found'); |
| 154 | + cy.contains('button', 'Search').click(); |
| 155 | + cy.assertPayrollRowVisible({ name: payroll.name }); |
| 156 | + }); |
| 157 | + |
| 158 | + it('opens and closes the reconciliation summary dialog from the pending list', () => { |
| 159 | + const payroll = payrollData('Reconcile Dialog'); |
| 160 | + |
| 161 | + cy.createPayroll(payroll); |
| 162 | + trackPayroll(payroll.name); |
| 163 | + |
| 164 | + cy.openPayrollPendingSummary(payroll.name); |
| 165 | + cy.contains('button', 'Close').click(); |
| 166 | + cy.contains('View Reconciliation Summary:').should('not.exist'); |
| 167 | + }); |
| 168 | +}); |
0 commit comments