-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add tests for TypeSelector inside record modifying modal
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { INCOME_TRANSACTION, EXPENSE_TRANSACTION } from '@tests/mocks'; | ||
import { ACCOUNT_TYPES } from 'shared-types'; | ||
import TypeSelectorVue from './type-selector.vue'; | ||
import { getFormTypeFromTransaction } from './helpers'; | ||
|
||
describe('Record TypeSelector component', () => { | ||
describe('editing form', () => { | ||
test.each([ | ||
[{ ...EXPENSE_TRANSACTION, accountType: ACCOUNT_TYPES.monobank }, 'Income'], | ||
[{ ...INCOME_TRANSACTION, accountType: ACCOUNT_TYPES.monobank }, 'Expense'], | ||
])( | ||
'correct buttons disabled when editing external transaction', | ||
(transaction, disabledBtnLabel) => { | ||
const wrapper = mount(TypeSelectorVue, { | ||
props: { | ||
selectedTransactionType: getFormTypeFromTransaction(transaction), | ||
isFormCreation: false, | ||
transaction, | ||
}, | ||
}); | ||
|
||
const buttons = wrapper.findAll('button'); | ||
|
||
const desiredButton = buttons.find((item) => item.text().includes(disabledBtnLabel)); | ||
|
||
expect(desiredButton.attributes().disabled !== undefined).toBe(true); | ||
|
||
expect( | ||
buttons.filter((item) => item.attributes().disabled !== undefined) | ||
.length, | ||
).toBeGreaterThanOrEqual(1); | ||
}, | ||
); | ||
|
||
test.each([[EXPENSE_TRANSACTION], [INCOME_TRANSACTION]])( | ||
'nothing is disabled when editing system transaction', | ||
(transaction) => { | ||
const wrapper = mount(TypeSelectorVue, { | ||
props: { | ||
selectedTransactionType: getFormTypeFromTransaction(transaction), | ||
isFormCreation: false, | ||
transaction, | ||
}, | ||
}); | ||
|
||
const buttons = wrapper.findAll('button'); | ||
const disabledButtons = buttons.filter(item => item.attributes().disabled !== undefined); | ||
|
||
expect(disabledButtons.length).toBe(0); | ||
}, | ||
); | ||
}); | ||
}); |