from test_est_row_actions import run_js def test_progress_page_preserves_original_indices_and_clamps(): result = run_js("""(() => { const rows = Array.from({length:205}, (_, i) => ({Code:'R'+i, Level:0})); rows.splice(1, 0, {Code:'heading', Level:1}); const state = {progressPage:1}; const second = EstBlockActions.progressPage(state, rows); state.progressPage = 99; const last = EstBlockActions.progressPage(state, rows); return {secondCount:second.rows.length, secondIndex:second.rows[0].index, lastCount:last.rows.length, page:state.progressPage, pages:last.pages}; })()""") assert result == {"secondCount": 100, "secondIndex": 101, "lastCount": 5, "page": 2, "pages": 3} def test_escalation_page_excludes_summary_and_preserves_original_indices(): result = run_js("""(() => { const rows = Array.from({length:201}, (_, i) => ({Code:'R'+i, Level:0})); rows.splice(2, 0, {Name:'소계', LinkIndex:54}); const state = {escalationPage:1}; const page = EstBlockActions.escalationPage(state, rows); return {count:page.rows.length, index:page.rows[0].index, total:page.total, pages:page.pages}; })()""") assert result == {"count": 100, "index": 101, "total": 201, "pages": 3} def test_change_page_includes_deleted_and_new_rows(): result = run_js("""(() => { const rows = Array.from({length:200}, (_, i) => ({Code:'R'+i, status:'unchanged'})); rows.push({Code:'old',status:'deleted'}, {Code:'new',status:'new'}); const state = {changePage:2}; const page = EstBlockActions.changePage(state, rows); return {statuses:page.rows.map(x=>x.row.status), total:page.total, pages:page.pages}; })()""") assert result == {"statuses": ["deleted", "new"], "total": 202, "pages": 3} def test_business_paging_filters_without_changing_original_indices(): result = run_js("""(() => { const rows = [{Code:'A',Name:'첫 항목'}, {Code:'B',Name:'둘째 항목',Size:'특수 규격'}]; const state = {query:'특수', progressPage:2}; const page = EstBlockActions.progressPage(state, rows); return {total:page.total, index:page.rows[0].index, page:state.progressPage}; })()""") assert result == {"total": 1, "index": 1, "page": 0}