# Instructions

- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.

# Test info

- Name: 4147/dev/privacy-masking-regression.spec.ts >> [4147][dev] [QA] 개인정보 마스킹 및 원문 조회 역할별 회귀 검증 >> [ADMIN] 정산내역 / 상세 마스킹 및 PIN 원문 조회
- Location: src/qa/scenarios/privacyMaskingRegression.ts:74:9

# Error details

```
Error: ADMIN 정산내역 목록에 데이터가 있지만 상세보기 또는 마스킹 해제 버튼이 없습니다.
```

# Test source

```ts
  130 |                 `기본 Excel 마스킹 문자 수: ${result.maskedStars}`,
  131 |                 `원문 Excel 마스킹 문자 수: ${result.unmaskedStars}`,
  132 |                 "다운로드 파일과 원문 개인정보는 증적에 첨부하지 않았습니다."
  133 |               ]);
  134 |             }, true);
  135 |           });
  136 |         }
  137 |       }
  138 |     }
  139 |   });
  140 | }
  141 |
  142 | async function withRolePage(
  143 |   browser: Browser,
  144 |   runtime: RuntimeQaEnv,
  145 |   callback: (page: Page) => Promise<void>,
  146 |   acceptDownloads = false
  147 | ): Promise<void> {
  148 |   const options = runtime.storageState
  149 |     ? { storageState: runtime.storageState, acceptDownloads }
  150 |     : { acceptDownloads };
  151 |   const context = await browser.newContext(options);
  152 |   const page = await context.newPage();
  153 |   try {
  154 |     await callback(page);
  155 |   } finally {
  156 |     await context.close().catch(() => undefined);
  157 |   }
  158 | }
  159 |
  160 | async function openTargetPage(page: Page, runtime: RuntimeQaEnv, definition: PrivacyPageDefinition): Promise<void> {
  161 |   if (!runtime.baseUrl) blocked(`${runtime.role} baseUrl이 설정되지 않았습니다.`);
  162 |   const url = new URL(definition.path, ensureTrailingSlash(runtime.baseUrl!));
  163 |   if (definition.tenantParam && runtime.tenantId) {
  164 |     url.searchParams.set(definition.tenantParam, runtime.tenantId);
  165 |   }
  166 |
  167 |   await page.goto(url.toString(), { waitUntil: "domcontentloaded", timeout: 30_000 });
  168 |   await settle(page);
  169 |   if (await isLoginPage(page, runtime)) {
  170 |     await loginWithCredentials(page, runtime);
  171 |     await page.goto(url.toString(), { waitUntil: "domcontentloaded", timeout: 30_000 });
  172 |     await settle(page);
  173 |   }
  174 |
  175 |   const root = await interactionRoot(page);
  176 |   const screenText = normalize(await root.innerText({ timeout: 10_000 }).catch(() => ""));
  177 |   const bodyText = normalize(await page.locator("body").innerText({ timeout: 10_000 }).catch(() => ""));
  178 |   if (/cloudflare|sorry, you have been blocked|attention required/i.test(bodyText)) {
  179 |     blocked(`${runtime.role} ${definition.name} 접근이 Cloudflare에서 차단되었습니다.`);
  180 |   }
  181 |   expect(screenText, `${runtime.role} ${definition.name} 화면 접근 권한이 있어야 합니다.`).not.toMatch(PERMISSION_DENIED_TEXT);
  182 |   expect(await isLoginPage(page, runtime), `${runtime.role} ${definition.name} 접근 중 로그인 화면으로 돌아가면 안 됩니다.`).toBe(false);
  183 | }
  184 |
  185 | async function ensureSearchData(page: Page): Promise<void> {
  186 |   await waitForLoading(page);
  187 |   if (await hasActionableRows(page)) return;
  188 |
  189 |   const root = await interactionRoot(page);
  190 |   const visibleInputs = root.locator("input:visible");
  191 |   const count = await visibleInputs.count();
  192 |   const dateInputs: Locator[] = [];
  193 |   const monthInputs: Locator[] = [];
  194 |   for (let index = 0; index < count; index += 1) {
  195 |     const input = visibleInputs.nth(index);
  196 |     const type = (await input.getAttribute("type"))?.toLowerCase();
  197 |     const placeholder = (await input.getAttribute("placeholder")) ?? "";
  198 |     if (type === "date" || /날짜|YYYY-MM-DD/i.test(placeholder)) dateInputs.push(input);
  199 |     if (type === "month" || /YYYY-MM/i.test(placeholder)) monthInputs.push(input);
  200 |   }
  201 |
  202 |   if (dateInputs[0]) await setInputValue(dateInputs[0], FALLBACK_FROM);
  203 |   if (dateInputs[1]) await setInputValue(dateInputs[1], FALLBACK_TO);
  204 |   for (const input of monthInputs) await setInputValue(input, FALLBACK_MONTH);
  205 |
  206 |   const search = await firstVisible(root.locator("button:visible").filter({ hasText: /^(검색|조회)$/ }));
  207 |   if (search) {
  208 |     await domClick(search);
  209 |     await settle(page);
  210 |     await waitForLoading(page);
  211 |   }
  212 | }
  213 |
  214 | async function verifyDetailMasking(
  215 |   page: Page,
  216 |   runtime: RuntimeQaEnv,
  217 |   definition: PrivacyPageDefinition
  218 | ): Promise<DetailResult> {
  219 |   const selector = definition.detailOpenSelector;
  220 |   if (!selector) throw new Error(`${definition.name} 상세 버튼 선택자가 정의되지 않았습니다.`);
  221 |   const opened = await openDetailWithUnmaskButton(page, selector);
  222 |   if (!opened) {
  223 |     const bodyText = normalize(await page.locator("body").innerText());
  224 |     if (EMPTY_TEXT.test(bodyText) || !(await hasActionableRows(page))) {
  225 |       blocked(`${runtime.role} ${definition.name}은 기간 확장 후에도 상세 검증 데이터가 없습니다.`);
  226 |     }
  227 |     if ((await page.locator(selector).count()) > 0) {
  228 |       blocked(`${runtime.role} ${definition.name} 상세 데이터에 마스킹 검증이 가능한 개인정보 값이 없습니다.`);
  229 |     }
> 230 |     throw new Error(`${runtime.role} ${definition.name} 목록에 데이터가 있지만 상세보기 또는 마스킹 해제 버튼이 없습니다.`);
      |           ^ Error: ADMIN 정산내역 목록에 데이터가 있지만 상세보기 또는 마스킹 해제 버튼이 없습니다.
  231 |   }
  232 |
  233 |   const unmaskButton = opened.button;
  234 |   const surface = opened.surface;
  235 |   const before = normalize(await surface.innerText());
  236 |   const maskedCharacters = countMaskCharacters(before);
  237 |   if (maskedCharacters === 0) {
  238 |     await closeSurface(page, surface);
  239 |     blocked(`${runtime.role} ${definition.name} 상세에 마스킹 검증이 가능한 개인정보 값이 없습니다.`);
  240 |   }
  241 |
  242 |   await domClick(unmaskButton);
  243 |   const pinInput = await firstVisible(page.locator("input[placeholder*='PIN'], input[name='pin'], input[type='password']"), 10_000);
  244 |   if (!pinInput) {
  245 |     await closeSurface(page, surface);
  246 |     throw new Error(`${runtime.role} ${definition.name} 마스킹 해제 클릭 후 PIN 인증창이 표시되지 않았습니다.`);
  247 |   }
  248 |   await pinInput.fill(runtime.twoFactorCode ?? "secret-redacted");
  249 |   const authSurface = pinInput.locator("xpath=ancestor::*[@role='dialog'][1]");
  250 |   const confirmRoot = (await authSurface.count()) > 0 ? authSurface : page.locator("body");
  251 |   const confirm = await firstVisible(confirmRoot.locator("button:visible").filter({ hasText: /^(확인|인증)$/ }));
  252 |   if (!confirm) {
  253 |     await closeSurface(page, surface);
  254 |     throw new Error(`${runtime.role} ${definition.name} PIN 인증 확인 버튼을 찾지 못했습니다.`);
  255 |   }
  256 |   await domClick(confirm);
  257 |
  258 |   const unmaskedState = page.getByRole("button", { name: /마스킹 해제됨/ });
  259 |   await expect(unmaskedState, `${runtime.role} ${definition.name} PIN 인증 후 마스킹 해제됨 상태가 표시되어야 합니다.`).toBeVisible({ timeout: 10_000 });
  260 |   const currentDialog = unmaskedState.locator("xpath=ancestor::*[@role='dialog'][1]");
  261 |   const currentSurface = (await currentDialog.count()) > 0 ? currentDialog : page.locator("body");
  262 |   const after = normalize(await currentSurface.innerText({ timeout: 5_000 }));
  263 |   const unmaskedCharacters = countMaskCharacters(after);
  264 |   const result = {
  265 |     maskedCharacters,
  266 |     unmaskedCharacters,
  267 |     beforeLength: before.length,
  268 |     afterLength: after.length
  269 |   };
  270 |
  271 |   await closeSurface(page, currentSurface);
  272 |   expect(result.afterLength, `${runtime.role} ${definition.name} 원문 전환 후 상세 값이 유지되어야 합니다.`).toBeGreaterThan(0);
  273 |   return result;
  274 | }
  275 |
  276 | async function openDetailWithUnmaskButton(
  277 |   page: Page,
  278 |   selector: string
  279 | ): Promise<{ button: Locator; surface: Locator } | undefined> {
  280 |   const root = await interactionRoot(page);
  281 |   const candidates = root.locator(selector);
  282 |   const count = Math.min(await candidates.count(), 12);
  283 |   for (let index = 0; index < count; index += 1) {
  284 |     const candidate = candidates.nth(index);
  285 |     if (!(await candidate.isVisible().catch(() => false))) continue;
  286 |     if (!(await isActiveElement(candidate))) continue;
  287 |     await domClick(candidate);
  288 |     await page.waitForTimeout(700);
  289 |     // Detail dialogs are rendered in a portal outside the keep-alive route.
  290 |     const button = await firstVisible(page.getByRole("button", { name: /^마스킹 해제$/ }));
  291 |     if (button) {
  292 |       const dialog = button.locator("xpath=ancestor::*[@role='dialog'][1]");
  293 |       const surface = (await dialog.count()) > 0 ? dialog : page.locator("body");
  294 |       const detailText = normalize(await surface.innerText().catch(() => ""));
  295 |       if (countMaskCharacters(detailText) > 0) {
  296 |         return { button, surface };
  297 |       }
  298 |       await closeSurface(page, surface);
  299 |       continue;
  300 |     }
  301 |     await page.keyboard.press("Escape").catch(() => undefined);
  302 |   }
  303 |   return undefined;
  304 | }
  305 |
  306 | async function verifyEditMasking(
  307 |   page: Page,
  308 |   definition: PrivacyPageDefinition
  309 | ): Promise<{ maskedInputs: number; editableMaskedInputs: number }> {
  310 |   const opened = await openEditModal(page);
  311 |   if (!opened) {
  312 |     const bodyText = normalize(await page.locator("body").innerText());
  313 |     if (EMPTY_TEXT.test(bodyText) || !(await hasActionableRows(page))) {
  314 |       blocked(`${definition.name}은 기간 확장 후에도 수정 모달 검증 데이터가 없습니다.`);
  315 |     }
  316 |     throw new Error(`${definition.name} 목록에 데이터가 있지만 수정 버튼 또는 수정 모달을 찾지 못했습니다.`);
  317 |   }
  318 |
  319 |   const modalText = normalize(await opened.surface.innerText());
  320 |   expect(modalText, `${definition.name} 수정 모달에 마스킹 해제 기능이 있어야 합니다.`).toMatch(/마스킹 해제/);
  321 |
  322 |   const inputs = opened.surface.locator("input, textarea");
  323 |   const inputCount = await inputs.count();
  324 |   let maskedInputs = 0;
  325 |   let editableMaskedInputs = 0;
  326 |   for (let index = 0; index < inputCount; index += 1) {
  327 |     const input = inputs.nth(index);
  328 |     const value = await input.inputValue().catch(() => "");
  329 |     if (!/[＊*•]/.test(value)) continue;
  330 |     maskedInputs += 1;
```