Skip to content

Commit 392a7b7

Browse files
committed
test(e2e): add municipality IBGE reset on UF change spec
Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent fd5f4a1 commit 392a7b7

1 file changed

Lines changed: 109 additions & 2 deletions

File tree

e2e/nfse-settings.spec.ts

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
22
// SPDX-License-Identifier: AGPL-3.0-or-later
33

4-
import { test, expect } from '@playwright/test';
4+
import { test, expect, type Page } from '@playwright/test';
55
import { loginToAkaunting } from './support/auth';
66

77
test.use({ serviceWorkers: 'block' });
88

9-
async function openTab(page, tabId, panelId) {
9+
async function openTab(page: Page, tabId: string, panelId: string) {
1010
const tab = page.locator(tabId);
1111
await expect(tab).toBeVisible();
1212
await expect(tab).toBeEnabled();
@@ -146,6 +146,113 @@ test('vault status summary shows certificate secret checklist row', async ({ pag
146146
await expect(page.locator('text=Segredo do certificado no Vault')).toBeVisible();
147147
});
148148

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+
149256
test('full dependent setup flow covers vault, certificate, fiscal and services steps', async ({ page }, testInfo) => {
150257
await loginToAkaunting(page, testInfo);
151258

0 commit comments

Comments
 (0)