Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(j-s): Regression E2E for court's handling of indictment cases #17457

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { test } from '../utils/judicialSystemTest'
import {
randomPoliceCaseNumber,
getDaysFromNow,
uploadDocument,
randomIndictmentCourtCaseNumber,
chooseDocument,
verifyUpload,
} from '../utils/helpers'

test.use({ baseURL: urls.judicialSystemBaseUrl })
Expand All @@ -21,6 +23,8 @@ test.describe.serial('Indictment tests', () => {
const page = prosecutorPage
const today = getDaysFromNow()

const policeCaseNumber = randomPoliceCaseNumber()

// Case list
await page.goto('/krofur')
await page.getByRole('button', { name: 'Nýtt mál' }).click()
Expand All @@ -29,9 +33,10 @@ test.describe.serial('Indictment tests', () => {

// New indictment case
await page.getByTestId('policeCaseNumber0').click()
await page.getByTestId('policeCaseNumber0').fill(randomPoliceCaseNumber())
await page.getByTestId('policeCaseNumber0').fill(policeCaseNumber)

await page.getByText('Sakarefni *Veldu sakarefni').click()
await page.locator('#react-select-case-type-option-0').click()
await page.getByRole('option', { name: 'Umferðarlagabrot' }).click()
await page.getByPlaceholder('Sláðu inn vettvang').click()
await page.getByPlaceholder('Sláðu inn vettvang').fill('Reykjavík')
await page.locator('input[id=arrestDate]').fill(today)
Expand Down Expand Up @@ -70,50 +75,69 @@ test.describe.serial('Indictment tests', () => {
])

// Processing

await Promise.all([
expect(page).toHaveURL(`/akaera/malsmedferd/${caseId}`),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

await Promise.all([
page.getByText('Játar sök').click(),
verifyRequestCompletion(page, '/api/graphql', 'UpdateDefendant'),
])

await Promise.all([
page.getByText('Nei').last().click(),
verifyRequestCompletion(page, '/api/graphql', 'UpdateCase'),
])

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])
// Indictment

// Case files
await expect(page).toHaveURL(`/akaera/domskjol/${caseId}`)
await Promise.all([
expect(page).toHaveURL(`/akaera/akaera/${caseId}`),
verifyRequestCompletion(page, '/api/graphql', 'CreateIndictmentCount'),
])

await uploadDocument(
page,
async () => {
await page
.getByText(
'Ákæra *Dragðu gögn hingað til að hlaða uppVelja gögn til að hlaða upp',
)
.click()
},
'TestAkaera.pdf',
)
await uploadDocument(
page,
async () => {
await page
.getByText(
'SakavottorðDragðu gögn hingað til að hlaða uppVelja gögn til að hlaða upp',
)
.click()
},
'TestSakavottord.pdf',
)
await page.getByText('LÖKE málsnúmer *Veldu málsnú').click()

await Promise.all([
page.getByRole('option', { name: `${policeCaseNumber}` }).click(),
verifyRequestCompletion(page, '/api/graphql', 'UpdateIndictmentCount'),
])

await page.getByPlaceholder('AB123').fill('AB123')

await Promise.all([
page.keyboard.press('Tab'),
verifyRequestCompletion(page, '/api/graphql', 'UpdateIndictmentCount'),
])

await Promise.all([page.getByTestId('continueButton').click()])
await Promise.all([
page.getByText('Brot *Veldu brot').click(),
page.getByRole('option', { name: 'Sviptingarakstur' }).click(),
verifyRequestCompletion(page, '/api/graphql', 'UpdateIndictmentCount'),
])

await Promise.all([
page.getByLabel('Krefjast sviptingarKrefjast').check(),
verifyRequestCompletion(page, '/api/graphql', 'UpdateCase'),
])

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Case files
await expect(page).toHaveURL(`/akaera/domskjol/${caseId}`)
await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Overview
await expect(page).toHaveURL(`/akaera/stadfesta/${caseId}`)
Expand Down Expand Up @@ -145,4 +169,121 @@ test.describe.serial('Indictment tests', () => {
verifyRequestCompletion(page, '/api/graphql', 'TransitionCase'),
])
})

test('judge should receive indictment case', async ({ judgePage }) => {
const page = judgePage
const nextWeek = getDaysFromNow(7)

// Case list
await page.goto('/krofur')
await page.getByText(accusedName).click()

// Indictment Overview
await expect(page).toHaveURL(`domur/akaera/yfirlit/${caseId}`)

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Reception and assignment
await expect(page).toHaveURL(`domur/akaera/mottaka/${caseId}`)

await page
.getByTestId('courtCaseNumber')
.fill(randomIndictmentCourtCaseNumber())
await page.keyboard.press('Tab')

await page.getByText('Veldu dómara/aðstoðarmann').click()
await page
.getByTestId('select-judge')
.getByText('Test Dómari')
.last()
.click()

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])
Comment on lines +172 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error case coverage for judge's workflow.

The happy path is well tested, but consider adding tests for:

  1. Invalid court case number format
  2. Missing judge assignment
  3. Failed API responses

Example test case:

test('should handle invalid court case number', async ({ judgePage }) => {
  await judgePage.getByTestId('courtCaseNumber').fill('invalid');
  await expect(judgePage.getByTestId('error-message')).toBeVisible();
});


// Subpoena
await expect(page).toHaveURL(`domur/akaera/fyrirkall/${caseId}`)

await page
.locator('label')
.filter({ hasText: 'Útivistarfyrirkall' })
.click()

await page.locator('input[id=courtDate]').fill(nextWeek)
await page.keyboard.press('Escape')

await page.getByTestId('courtDate-time').fill('11:00')
await page.getByTestId('courtroom').press('Tab')

await page.getByTestId('courtroom').fill('12')
await page.getByTestId('courtroom').press('Tab')

await page.getByTestId('continueButton').click()
await page.getByTestId('modalPrimaryButton').click()

// Advocates and civil claimants
await expect(page).toHaveURL(`domur/akaera/malflytjendur/${caseId}`)

await page
.locator('label')
.filter({ hasText: 'Ákærði óskar ekki eftir að sé' })
.click()
await page.getByRole('button', { name: 'Staðfesta val' }).click()
await page.getByTestId('modalPrimaryButton').click()

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Conclusion
await expect(page).toHaveURL(`domur/akaera/nidurstada/${caseId}`)

await page.locator('label').filter({ hasText: 'Lokið' }).click()
await page.locator('label').filter({ hasText: 'Dómur' }).click()

await chooseDocument(
page,
async () => {
await page
.getByRole('button', { name: 'Velja gögn til að hlaða upp' })
.nth(1)
.click()
},
'TestThingbok.pdf',
)
await chooseDocument(
page,
async () => {
await page
.getByRole('button', { name: 'Velja gögn til að hlaða upp' })
.nth(2)
.click()
},
'TestDomur.pdf',
)

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Summary
await expect(page).toHaveURL(`domur/akaera/samantekt/${caseId}`)

await page.getByTestId('continueButton').click()
await page.getByTestId('modalPrimaryButton').click()

// Completed case overview
await expect(page).toHaveURL(`domur/akaera/lokid/${caseId}`)

await page.getByText('Birta skal dómfellda dóminn').click()
await page.getByTestId('continueButton').click()
await page.getByTestId('modalPrimaryButton').click()
})
})
10 changes: 8 additions & 2 deletions apps/system-e2e/src/tests/judicial-system/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ export const randomPoliceCaseNumber = () => {
return `007-${new Date().getFullYear()}-${Math.floor(Math.random() * 100000)}`
}

export const randomCourtCaseNumber = () => {
return `R-${Math.floor(Math.random() * 1000)}/${new Date().getFullYear()}`
export const randomCourtCaseNumber = (prefix?: string) => {
return `${prefix ?? 'R'}-${Math.floor(
Math.random() * 1000,
)}/${new Date().getFullYear()}`
}

export const randomIndictmentCourtCaseNumber = () => {
return randomCourtCaseNumber('S')
}

export const randomAppealCaseNumber = () => {
Expand Down
Loading