Skip to content

Commit

Permalink
Merge branch 'master' into CI-download-form
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekVigas authored Nov 16, 2024
2 parents 9745e3f + 93c9f2f commit f06843b
Show file tree
Hide file tree
Showing 21 changed files with 458 additions and 450 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ NEXT_PUBLIC_isPostponeLive=true
NEXT_PUBLIC_navodyBaseUrl=https://staging.navody.digital
NEXT_PUBLIC_priznanieStepUrl=/zivotne-situacie/elektronicke-podanie-danoveho-priznania-2022/krok/prihlasit-sa-na-financnu-spravu
NEXT_PUBLIC_odkladStepUrl=/zivotne-situacie/odklad-danoveho-priznania-2023/krok/podat-odklad
NEXT_PUBLIC_informujteMaKedBudeLive=/zivotne-situacie/elektronicke-podanie-danoveho-priznania-2024
RANDOM_TEST_LENGTH=20
139 changes: 8 additions & 131 deletions __tests__/iban.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,157 +4,34 @@ import { TaxForm } from '../src/types/TaxForm'

describe('iban', () => {
describe('#validate', () => {
describe('mozeZiadatVyplatitDanovyBonus', () => {
describe('mozeZiadatVratitPreplatkyBonusyUroky', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitDanovyPreplatok: false,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: { ziadamVyplatitDanovyBonus: undefined },
expected: ['ziadamVyplatitDanovyBonus'],
input: { ziadamVyplatitDanovyBonusUrokPreplatok: undefined },
expected: ['ziadamVyplatitDanovyBonusUrokPreplatok'],
},
{ input: { ziadamVyplatitDanovyBonus: false }, expected: [] },
{
input: { ziadamVyplatitDanovyBonus: true },
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
iban: 'SK6807200002891987426353',
},
expected: [],
},
])
})

describe('mozeZiadatVratitDanovyPreplatok', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: false,
mozeZiadatVratitDanovyPreplatok: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: { ziadamVratitDanovyPreplatok: undefined },
expected: ['ziadamVratitDanovyPreplatok'],
},
{ input: { ziadamVratitDanovyPreplatok: false }, expected: [] },
{
input: { ziadamVratitDanovyPreplatok: true },
expected: ['iban'],
},
{
input: {
ziadamVratitDanovyPreplatok: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVratitDanovyPreplatok: true,
iban: 'SK6807200002891987426353',
},
expected: [],
},
])
})

describe('mozeZiadatVyplatitDanovyBonus && mozeZiadatVratitDanovyPreplatok', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitDanovyPreplatok: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: undefined,
},
expected: [
'ziadamVyplatitDanovyBonus',
'ziadamVratitDanovyPreplatok',
],
},
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: false,
},
expected: ['ziadamVyplatitDanovyBonus'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: undefined,
},
expected: ['ziadamVratitDanovyPreplatok'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: false,
},
input: { ziadamVyplatitDanovyBonusUrokPreplatok: false },
expected: [],
},
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: true,
},
expected: ['ziadamVyplatitDanovyBonus', 'iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: undefined,
},
expected: ['ziadamVratitDanovyPreplatok', 'iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: false,
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: true,
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
},
input: { ziadamVyplatitDanovyBonusUrokPreplatok: true },
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',
},
expected: [],
Expand Down
8 changes: 4 additions & 4 deletions __tests__/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('routes', () => {
it('should return routes with children, with iban', () => {
expect(
getOrderedRoutes({
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm),
).toStrictEqual([
homeRoute,
Expand All @@ -75,7 +75,7 @@ describe('routes', () => {
it('should return routes without children, with iban', () => {
expect(
getOrderedRoutes({
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm),
).toStrictEqual([
homeRoute,
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('routes', () => {

it('should be correct when eligible for refund', () => {
const { nextRoute } = getRoutes('/suhrn', {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm)
expect(nextRoute()).toBe('/iban')
})
Expand All @@ -137,7 +137,7 @@ describe('routes', () => {

it('should be correct when eligible for refund', () => {
const { previousRoute } = getRoutes('/vysledky', {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm)
expect(previousRoute()).toBe('/iban')
})
Expand Down
3 changes: 1 addition & 2 deletions __tests__/testCases/bugReport6Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ export const bugReport6Input: E2eTestUserInput = {
r142_obchMeno: '',
XIIoddiel_suhlasZaslUdaje: false,
iban: 'SK6807200002891987426353',
ziadamVyplatitDanovyBonus: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
datum: '',
partner_spolocna_domacnost: true,
r006_titul_za: '',
ziadamVratitDanovyPreplatok: true,
}
2 changes: 1 addition & 1 deletion __tests__/testCases/withBonusInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const withBonusInput: E2eTestUserInput = {
hasChildren: true,

/** SECTION Danovy bonus */
ziadamVyplatitDanovyBonus: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: false,
Expand Down
3 changes: 1 addition & 2 deletions __tests__/testCases/withEmploymentBonusInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export const withEmploymentBonusInput: E2eTestUserInput = {
},
],
datum: '22.02.2020',
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: false,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/testCases/withTaxReturnInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const withTaxReturnInput: E2eTestUserInput = {
children: [],

/** SECTION Danovy preplatok */
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: true,
Expand Down
46 changes: 12 additions & 34 deletions cypress/e2e/executeCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,54 +351,32 @@ const executeTestCase = (testCase: string) => {

const taxForm = calculate(input)

if (taxForm.mozeZiadatVyplatitDanovyBonus) {
if (taxForm.mozeZiadatVratitPreplatkyBonusyUroky) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains(
'Žiadam o vyplatenie daňového bonusu alebo rozdielu daňového bonusu',
'Chcete požiadať o vyplatenie daňových bonusov alebo preplatkov vo výške',
)
cy.get('[data-test=ineligible-message]').should('not.exist')

if (input.ziadamVyplatitDanovyBonus) {
getInput('ziadamVyplatitDanovyBonus', '-yes').click()
if (input.ziadamVyplatitDanovyBonusUrokPreplatok) {
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVyplatitDanovyBonus', '-no').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click()
}

next()
}

if (taxForm.mozeZiadatVratitDanovyBonusUroky) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains('Žiadam o vyplatenie daňového bonusu na zaplatené úroky')
cy.get('[data-test=ineligible-message]').should('not.exist')

if (input.ziadamVratitDanovyBonusUroky) {
getInput('ziadamVratitDanovyBonusUroky', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVratitDanovyBonusUroky', '-no').click()
if (taxForm.mozeZiadatVyplatitDanovyBonus) {
cy.contains('Daňový bonus: ')
}

next()
}

if (taxForm.mozeZiadatVratitDanovyPreplatok) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains('Žiadam o vrátenie daňového preplatku')
cy.get('[data-test=ineligible-message]').should('not.exist')
if (taxForm.mozeZiadatVratitDanovyBonusUroky) {
cy.contains('Daňový bonus na zaplatené úroky: ')
}

if (input.ziadamVratitDanovyPreplatok) {
getInput('ziadamVratitDanovyPreplatok', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVratitDanovyPreplatok', '-no').click()
if (taxForm.mozeZiadatVratitDanovyPreplatok) {
cy.contains('Daňový preplatok: ')
}

next()
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,15 @@ describe('IBAN page', () => {

getError().should('have.length', 1)

getInput('ziadamVyplatitDanovyBonus', '-no').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click()
next()
getError().should('have.length', 0)

assertUrl('/vysledky')
cy.get('.govuk-back-link').click()
getError().should('have.length', 0)

getInput('ziadamVyplatitDanovyBonus', '-yes').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click()
getInput('iban').should('exist')
next()

Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
navodyBaseUrl: process.env.NEXT_PUBLIC_navodyBaseUrl,
priznanieStepUrl: process.env.NEXT_PUBLIC_priznanieStepUrl,
odkladStepUrl: process.env.NEXT_PUBLIC_odkladStepUrl,
informujteMaKedBudeLive: process.env.NEXT_PUBLIC_informujteMaKedBudeLive,
plausibleDomain: process.env.NEXT_PUBLIC_plausibleDomain,
odkladEmailTemplateId: process.env.NEXT_PUBLIC_odkladEmailTemplateId,
priznanieEmailTemplateId: process.env.NEXT_PUBLIC_priznanieEmailTemplateId,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@typescript-eslint/eslint-plugin": "5.12.0",
"@typescript-eslint/parser": "5.12.0",
"babel-eslint": "10.1.0",
"cypress": "13.6.6",
"cypress": "13.15.2",
"eslint": "8.9.0",
"eslint-config-react-app": "7.0.0",
"eslint-formatter-pretty": "4.1.0",
Expand Down
12 changes: 9 additions & 3 deletions src/lib/calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,13 @@ export function calculate(input: TaxFormUserInput): TaxForm {
get mozeZiadatVratitDanovyBonusUroky() {
return this.r127.gt(0)
},
get mozeZiadatVratitPreplatkyBonusyUroky() {
return (
this.mozeZiadatVyplatitDanovyBonus ||
this.mozeZiadatVratitDanovyPreplatok ||
this.mozeZiadatVratitDanovyBonusUroky
)
},
get r127() {
return round(Decimal.max(this.r126.minus(this.r118), 0))
},
Expand Down Expand Up @@ -849,9 +856,8 @@ export function calculate(input: TaxFormUserInput): TaxForm {
},

/** SECTION Danovy bonus */
ziadamVyplatitDanovyBonus: input?.ziadamVyplatitDanovyBonus ?? false,
ziadamVratitDanovyPreplatok: input?.ziadamVratitDanovyPreplatok ?? false,
ziadamVratitDanovyBonusUroky: input?.ziadamVratitDanovyBonusUroky ?? false,
ziadamVyplatitDanovyBonusUrokPreplatok:
input?.ziadamVyplatitDanovyBonusUrokPreplatok ?? false,
iban: input?.iban ? input?.iban.replace(/\s/g, '') : '',

datum: input.datum,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/initialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const twoPercentInitialValues: TwoPercentUserInput = {

export const taxBonusInitialInput: TaxBonusUserInput = {
iban: '',
ziadamVyplatitDanovyBonus: undefined,
ziadamVyplatitDanovyBonusUrokPreplatok: undefined,
}

export const initTaxFormUserInputValues: TaxFormUserInput = {
Expand Down
5 changes: 1 addition & 4 deletions src/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export type Route =

export const getOrderedRoutes = (taxForm: TaxForm): ReadonlyArray<Route> => {
const getIbanRoute = (): Route[] => {
const isIbanRequired =
taxForm.mozeZiadatVyplatitDanovyBonus ||
taxForm.mozeZiadatVratitDanovyPreplatok ||
taxForm.mozeZiadatVratitDanovyBonusUroky
const isIbanRequired = taxForm.mozeZiadatVratitPreplatkyBonusyUroky
return isIbanRequired ? ['/iban'] : []
}

Expand Down
Loading

0 comments on commit f06843b

Please sign in to comment.