Skip to content

Commit

Permalink
feat: Add tests for TypeSelector inside record modifying modal
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jan 7, 2024
1 parent 8f79ff3 commit fcdd26d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/components/modals/modify-record/type-selector.test.ts
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);
},
);
});
});

0 comments on commit fcdd26d

Please sign in to comment.