|
1 | 1 | // SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
2 | 2 | // SPDX-License-Identifier: AGPL-3.0-or-later |
3 | 3 |
|
4 | | -import { test, expect } from '@playwright/test'; |
| 4 | +import { test, expect, type Page } from '@playwright/test'; |
5 | 5 | import { loginToAkaunting } from './support/auth'; |
6 | 6 |
|
7 | 7 | test.use({ serviceWorkers: 'block' }); |
8 | 8 |
|
9 | | -async function openTab(page, tabId, panelId) { |
| 9 | +async function openTab(page: Page, tabId: string, panelId: string) { |
10 | 10 | const tab = page.locator(tabId); |
11 | 11 | await expect(tab).toBeVisible(); |
12 | 12 | await expect(tab).toBeEnabled(); |
@@ -146,6 +146,113 @@ test('vault status summary shows certificate secret checklist row', async ({ pag |
146 | 146 | await expect(page.locator('text=Segredo do certificado no Vault')).toBeVisible(); |
147 | 147 | }); |
148 | 148 |
|
| 149 | +test('federal tab visibility matrix matches situacao tributaria and tipo retencao', async ({ page }, testInfo) => { |
| 150 | + await loginToAkaunting(page, testInfo); |
| 151 | + |
| 152 | + await page.goto('/1/nfse/settings?tab=federal', { waitUntil: 'domcontentloaded' }); |
| 153 | + await page.waitForLoadState('networkidle'); |
| 154 | + |
| 155 | + await expect(page.locator('#tab-panel-federal')).toBeVisible(); |
| 156 | + |
| 157 | + const situacaoSelect = page.locator('#federal-piscofins-situacao'); |
| 158 | + const tipoRetencaoSelect = page.locator('#federal-piscofins-tipo-retencao'); |
| 159 | + const piscofinsPanel = page.locator('#federal-piscofins-panel'); |
| 160 | + const csllRow = page.locator('#federal-valor-csll-row'); |
| 161 | + |
| 162 | + // Situacao 0/empty: panel and CSLL row must be hidden regardless of retention type. |
| 163 | + for (const situacao of ['', '0']) { |
| 164 | + await situacaoSelect.selectOption(situacao); |
| 165 | + await expect(piscofinsPanel).toBeHidden(); |
| 166 | + await expect(csllRow).toBeHidden(); |
| 167 | + } |
| 168 | + |
| 169 | + // Situacao with tributacao enabled: panel visible, CSLL controlled by retention type. |
| 170 | + await situacaoSelect.selectOption('1'); |
| 171 | + await expect(piscofinsPanel).toBeVisible(); |
| 172 | + |
| 173 | + const matrix = [ |
| 174 | + { tipoRetencao: '0', shouldShowCsll: false }, |
| 175 | + { tipoRetencao: '3', shouldShowCsll: true }, |
| 176 | + { tipoRetencao: '4', shouldShowCsll: false }, |
| 177 | + { tipoRetencao: '5', shouldShowCsll: false }, |
| 178 | + { tipoRetencao: '6', shouldShowCsll: false }, |
| 179 | + { tipoRetencao: '7', shouldShowCsll: true }, |
| 180 | + { tipoRetencao: '8', shouldShowCsll: true }, |
| 181 | + { tipoRetencao: '9', shouldShowCsll: true }, |
| 182 | + ]; |
| 183 | + |
| 184 | + for (const entry of matrix) { |
| 185 | + await tipoRetencaoSelect.selectOption(entry.tipoRetencao); |
| 186 | + |
| 187 | + if (entry.shouldShowCsll) { |
| 188 | + await expect(csllRow).toBeVisible(); |
| 189 | + } else { |
| 190 | + await expect(csllRow).toBeHidden(); |
| 191 | + } |
| 192 | + } |
| 193 | +}); |
| 194 | + |
| 195 | +test('fiscal tab resets municipality IBGE when UF changes and updates after new selection', async ({ page }, testInfo) => { |
| 196 | + await loginToAkaunting(page, testInfo); |
| 197 | + |
| 198 | + await page.route('**/nfse/ibge/ufs', (route) => { |
| 199 | + route.fulfill({ |
| 200 | + status: 200, |
| 201 | + contentType: 'application/json', |
| 202 | + body: JSON.stringify({ |
| 203 | + data: [ |
| 204 | + { uf: 'SP', name: 'Sao Paulo' }, |
| 205 | + { uf: 'RJ', name: 'Rio de Janeiro' }, |
| 206 | + ], |
| 207 | + }), |
| 208 | + }); |
| 209 | + }); |
| 210 | + |
| 211 | + await page.route('**/nfse/ibge/municipalities/SP', (route) => { |
| 212 | + route.fulfill({ |
| 213 | + status: 200, |
| 214 | + contentType: 'application/json', |
| 215 | + body: JSON.stringify({ |
| 216 | + data: [ |
| 217 | + { ibge_code: '3550308', name: 'Sao Paulo' }, |
| 218 | + { ibge_code: '3509502', name: 'Campinas' }, |
| 219 | + ], |
| 220 | + }), |
| 221 | + }); |
| 222 | + }); |
| 223 | + |
| 224 | + await page.route('**/nfse/ibge/municipalities/RJ', (route) => { |
| 225 | + route.fulfill({ |
| 226 | + status: 200, |
| 227 | + contentType: 'application/json', |
| 228 | + body: JSON.stringify({ |
| 229 | + data: [ |
| 230 | + { ibge_code: '3303302', name: 'Niteroi' }, |
| 231 | + { ibge_code: '3304557', name: 'Rio de Janeiro' }, |
| 232 | + ], |
| 233 | + }), |
| 234 | + }); |
| 235 | + }); |
| 236 | + |
| 237 | + await page.goto('/1/nfse/settings?tab=fiscal', { waitUntil: 'domcontentloaded' }); |
| 238 | + await page.waitForLoadState('networkidle'); |
| 239 | + |
| 240 | + await expect(page.locator('#tab-panel-fiscal')).toBeVisible(); |
| 241 | + |
| 242 | + await page.locator('select[name="nfse[uf]"]').selectOption('SP'); |
| 243 | + await page.locator('select[name="nfse[municipio_nome]"]').selectOption('Sao Paulo'); |
| 244 | + await expect(page.locator('input[name="nfse[municipio_ibge]"]')).toHaveValue('3550308'); |
| 245 | + |
| 246 | + await page.locator('select[name="nfse[uf]"]').selectOption('RJ'); |
| 247 | + |
| 248 | + // Changing UF must clear stale municipality/IBGE until the user selects a city from the new UF. |
| 249 | + await expect(page.locator('select[name="nfse[municipio_nome]"]')).toHaveValue(''); |
| 250 | + await expect(page.locator('input[name="nfse[municipio_ibge]"]')).toHaveValue(''); |
| 251 | + |
| 252 | + await page.locator('select[name="nfse[municipio_nome]"]').selectOption('Niteroi'); |
| 253 | + await expect(page.locator('input[name="nfse[municipio_ibge]"]')).toHaveValue('3303302'); |
| 254 | +}); |
| 255 | + |
149 | 256 | test('full dependent setup flow covers vault, certificate, fiscal and services steps', async ({ page }, testInfo) => { |
150 | 257 | await loginToAkaunting(page, testInfo); |
151 | 258 |
|
|
0 commit comments