Skip to content

Commit

Permalink
vypnutie odkladu (#784)
Browse files Browse the repository at this point in the history
* vypnutie odkladu po 31.3.

* put now as parameter into PostponeSection

* Make button look in compliance with our UX standard

* vypnutie odkladu po 31.3.

* put now as parameter into PostponeSection

* Make button look in compliance with our UX standard

* Fix failing tests while month is 10-12

* fix tests logic based on their component logic

* identity fix, comments

* identity fix, comments

---------

Co-authored-by: Andrej Nagy <[email protected]>
Co-authored-by: Michal Ormos <[email protected]>
Co-authored-by: Michal Ormos <[email protected]>
Co-authored-by: Marek Vigaš <[email protected]>
Co-authored-by: micorm <[email protected]>
  • Loading branch information
6 people authored Oct 24, 2023
1 parent e88b740 commit a4fd5d3
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 86 deletions.
163 changes: 85 additions & 78 deletions cypress/e2e/postponePages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { postponeHomeRoute, PostponeRoute, Route } from '../../src/lib/routes'
import { foreignIncomeInput } from '../../__tests__/testCases/postpone/foreignIncomeInput'
import { PostponeUserInput } from '../../src/types/PostponeUserInput'

const date = new Date
const month = date.getMonth() + 1;

function getInputPostpone<K extends keyof PostponeUserInput>(
key: K,
suffix = '',
Expand All @@ -28,89 +31,93 @@ const next = () => {
return cy.contains('Pokračovať').click()
}

describe('/odklad/osobne-udaje page', () => {
beforeEach('Navigate to test page', () => {
cy.visit(postponeHomeRoute)

cy.contains('Súhlasím a chcem odložiť daňové priznanie').click()
assertUrl('/odklad/prijmy-zo-zahranicia')
getInputPostpone('prijmy_zo_zahranicia', '-yes').click()

next()
})
it('Back and validation', () => {
assertUrl('/odklad/osobne-udaje')

// Back button should work and be the correct page
cy.get('[data-test=back]').click()
assertUrl('/odklad/prijmy-zo-zahranicia')

// Go back to our page
next()

// Shows error, when presses next without interaction
next()
cy.get('[data-test=error]')
})
it('with autoform', () => {
assertUrl('/odklad/osobne-udaje')

/** With autoform */
typeToInputPostpone('dic', foreignIncomeInput)
getInputPostpone('meno_priezvisko').type('Julius Renc')

cy.contains('Július Renceš').click()

getInputPostpone('meno_priezvisko').should('contain.value', 'Július Renceš')
getInputPostpone('ulica').should('contain.value', 'Benková Potôň')
getInputPostpone('cislo').should('contain.value', '343')
getInputPostpone('psc').should('contain.value', '930 36')
getInputPostpone('obec').should('contain.value', 'Horná Potôň')
cy.get(`[data-test="stat-select"]`).should('contain.value', 'Slovensko')
// button is not usable outside scope of first three months
// when postpone for tax report is availible
if (month >= 1 && month < 4) {
describe('/odklad/osobne-udaje page', () => {
beforeEach('Navigate to test page', () => {
cy.visit(postponeHomeRoute)

cy.contains('Súhlasím a chcem odložiť daňové priznanie').click()
assertUrl('/odklad/prijmy-zo-zahranicia')
getInputPostpone('prijmy_zo_zahranicia', '-yes').click()

next()
})
it('Back and validation', () => {
assertUrl('/odklad/osobne-udaje')

// Back button should work and be the correct page
cy.get('[data-test=back]').click()
assertUrl('/odklad/prijmy-zo-zahranicia')

// Go back to our page
next()

// Shows error, when presses next without interaction
next()
cy.get('[data-test=error]')
})
it('with autoform', () => {
assertUrl('/odklad/osobne-udaje')

/** With autoform */
typeToInputPostpone('dic', foreignIncomeInput)
getInputPostpone('meno_priezvisko').type('Julius Renc')

cy.contains('Július Renceš').click()

getInputPostpone('meno_priezvisko').should('contain.value', 'Július Renceš')
getInputPostpone('ulica').should('contain.value', 'Benková Potôň')
getInputPostpone('cislo').should('contain.value', '343')
getInputPostpone('psc').should('contain.value', '930 36')
getInputPostpone('obec').should('contain.value', 'Horná Potôň')
cy.get(`[data-test="stat-select"]`).should('contain.value', 'Slovensko')
})

it('Manual entry', () => {
assertUrl('/odklad/osobne-udaje')

typeToInputPostpone('dic', foreignIncomeInput)
typeToInputPostpone('meno', foreignIncomeInput)
typeToInputPostpone('priezvisko', foreignIncomeInput)
typeToInputPostpone('ulica', foreignIncomeInput)
typeToInputPostpone('cislo', foreignIncomeInput)
typeToInputPostpone('obec', foreignIncomeInput)
typeToInputPostpone('psc', foreignIncomeInput)
cy.get('[data-test="stat-select"]').select(foreignIncomeInput.stat)
})
it('Errors', () => {
assertUrl('/odklad/osobne-udaje')

getInputPostpone('dic').type('invalid')

next()
cy.get('.govuk-error-summary')
})
})

it('Manual entry', () => {
assertUrl('/odklad/osobne-udaje')

typeToInputPostpone('dic', foreignIncomeInput)
typeToInputPostpone('meno', foreignIncomeInput)
typeToInputPostpone('priezvisko', foreignIncomeInput)
typeToInputPostpone('ulica', foreignIncomeInput)
typeToInputPostpone('cislo', foreignIncomeInput)
typeToInputPostpone('obec', foreignIncomeInput)
typeToInputPostpone('psc', foreignIncomeInput)
cy.get('[data-test="stat-select"]').select(foreignIncomeInput.stat)
})
it('Errors', () => {
assertUrl('/odklad/osobne-udaje')
describe('/odklad/suhrn page', () => {
beforeEach('Navigate to test page', () => {
cy.visit(postponeHomeRoute)

getInputPostpone('dic').type('invalid')

next()
cy.get('.govuk-error-summary')
})
})
cy.contains('Súhlasím a chcem odložiť daňové priznanie').click()
assertUrl('/odklad/prijmy-zo-zahranicia')
getInputPostpone('prijmy_zo_zahranicia', '-yes').click()

describe('/odklad/suhrn page', () => {
beforeEach('Navigate to test page', () => {
cy.visit(postponeHomeRoute)
next()

cy.contains('Súhlasím a chcem odložiť daňové priznanie').click()
assertUrl('/odklad/prijmy-zo-zahranicia')
getInputPostpone('prijmy_zo_zahranicia', '-yes').click()
getInputPostpone('meno_priezvisko').type('Julius Renc')
cy.contains('Július Renceš').click()

next()
next()
})
it('Back', () => {
assertUrl('/odklad/suhrn')

getInputPostpone('meno_priezvisko').type('Julius Renc')
cy.contains('Július Renceš').click()

next()
})
it('Back', () => {
assertUrl('/odklad/suhrn')

// Back button should work and be the correct page
cy.get('[data-test=back]').click()
assertUrl('/odklad/osobne-udaje')
// Back button should work and be the correct page
cy.get('[data-test=back]').click()
assertUrl('/odklad/osobne-udaje')
})
})
})
}
51 changes: 43 additions & 8 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Home = ({ nextRoute, nextPostponeRoute, isDebug, isLive }) => (

<div className="govuk-grid-column-one-third">
<div className={styles.postponeBox}>
<PostponeSection nextPostponeRoute={nextPostponeRoute} />
<PostponeSection nextPostponeRoute={nextPostponeRoute} now={new Date()} />
</div>

<ul className={styles.safeList}>
Expand Down Expand Up @@ -150,16 +150,12 @@ const TaxFormSection = ({ nextRoute, isDebug, isLive }) => {
)
}

const PostponeSection = ({ nextPostponeRoute }) => (
const PostponeSection = ({ nextPostponeRoute, now}) => (
<>
<h2 className="govuk-heading-m govuk-!-margin-top-3">
{`Odklad daňového priznania za rok ${TAX_YEAR}`}
</h2>
<p>
{`Riadny termín pre podanie daňového priznania a zaplatenie dane je
31.3.${TAX_YEAR + 1}`}
</p>
<p>Termín si viete predĺžiť:</p>
<PostponeText now={now}/>
<ul className="govuk-list govuk-list--bullet">
<li>{`do 30.6.${
TAX_YEAR + 1
Expand All @@ -174,12 +170,51 @@ const PostponeSection = ({ nextPostponeRoute }) => (
</p>

<Link href={nextPostponeRoute} legacyBehavior>
<PostponeButton now={now}/>
</Link>
</>
)
const PostponeText = ({ now }) => (
<>
{(now.getMonth() > 2) && (
<>
<p>
{`Riadny termín pre podanie daňového priznania a zaplatenie dane bol do
31.3.${TAX_YEAR + 1}`}
</p>
<p>Termín ste si mohli predĺžiť:</p>
</>)}
{(now.getMonth() < 3) && (
<>
<p>
{`Riadny termín pre podanie daňového priznania a zaplatenie dane je
31.3.${TAX_YEAR + 1}`}
</p>
<p>Termín si viete predĺžiť:</p>
</>)}
</>
)

const PostponeButton = ({ now }) => (
<>
{(now.getMonth() > 2) && (
<>
<button
type="button"
className="btn-secondary govuk-button govuk-button--large govuk-button--disabled"
disabled
>
Termín na podanie odkladu DP vypršal
</button>
</>)}
{(now.getMonth() < 3) && (
<>
<button
type="button"
className="btn-secondary govuk-button govuk-button--large"
>
Súhlasím a chcem odložiť daňové priznanie
</button>
</Link>
</>)}
</>
)

0 comments on commit a4fd5d3

Please sign in to comment.