Skip to content

Commit

Permalink
Add filters tests
Browse files Browse the repository at this point in the history
  • Loading branch information
htdat committed Dec 26, 2024
1 parent 4c02351 commit 8ae551e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/data/transactions/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const formatQueryFilters = ( query ) => ( {
customer_currency_is: query.customerCurrencyIs,
customer_currency_is_not: query.customerCurrencyIsNot,
source_is: query.sourceIs,
source_is_not: query.sourceIsNot, // @todo check why?
source_is_not: query.sourceIsNot,
search: query.search,
user_timezone: getUserTimeZone(),
locale: query.locale,
Expand Down
2 changes: 1 addition & 1 deletion client/transactions/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Transaction } from 'wcpay/data';
interface TransactionsFiltersProps {
storeCurrencies: string[];
customerCurrencies: string[];
transactionSources?: Transaction[ 'source' ][];
transactionSources: Transaction[ 'source' ][];
}

export const TransactionsFilters = ( {
Expand Down
20 changes: 20 additions & 0 deletions client/transactions/filters/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ HTMLOptionsCollection [
]
`;

exports[`Transactions filters when filtering by payment method should render all types 1`] = `
HTMLOptionsCollection [
<option
value="visa"
>
Visa
</option>,
<option
value="mastercard"
>
Mastercard
</option>,
<option
value="sofort"
>
SOFORT
</option>,
]
`;

exports[`Transactions filters when filtering by risk level should render all types 1`] = `
HTMLOptionsCollection [
<option
Expand Down
54 changes: 54 additions & 0 deletions client/transactions/filters/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getQuery, updateQueryString } from '@woocommerce/navigation';
* Internal dependencies
*/
import { TransactionsFilters } from '../';
import { Transaction } from 'wcpay/data';

// TODO: this is a bit of a hack as we're mocking an old version of WC, we should relook at this.
jest.mock( '@woocommerce/settings', () => ( {
Expand All @@ -33,6 +34,11 @@ function addAdvancedFilter( filter: string ) {

const storeCurrencies = [ 'eur', 'usd' ];
const customerCurrencies = [ 'eur', 'usd', 'gbp' ];
const transactionSources: Transaction[ 'source' ][] = [
'visa',
'mastercard',
'sofort',
];

declare const global: {
wcSettings: { countries: Record< string, string > };
Expand Down Expand Up @@ -71,6 +77,7 @@ describe( 'Transactions filters', () => {
<TransactionsFilters
storeCurrencies={ storeCurrencies }
customerCurrencies={ customerCurrencies }
transactionSources={ transactionSources }
/>
);

Expand All @@ -85,6 +92,7 @@ describe( 'Transactions filters', () => {
<TransactionsFilters
storeCurrencies={ storeCurrencies }
customerCurrencies={ customerCurrencies }
transactionSources={ transactionSources }
/>
);
} );
Expand Down Expand Up @@ -250,6 +258,52 @@ describe( 'Transactions filters', () => {
} );
} );

describe( 'when filtering by payment method', () => {
let ruleSelector: HTMLElement;

beforeEach( () => {
addAdvancedFilter( 'Payment method' );
ruleSelector = screen.getByRole( 'combobox', {
name: /payment method filter/i,
} );
} );

test( 'should render all types', () => {
const typeSelect = screen.getByRole( 'combobox', {
name: /payment method$/i,
} ) as HTMLSelectElement;
expect( typeSelect.options ).toMatchSnapshot();
} );

test( 'should filter by is', () => {
user.selectOptions( ruleSelector, 'is' );

user.selectOptions(
screen.getByRole( 'combobox', {
name: /Select a payment method$/i,
} ),
'visa'
);
user.click( screen.getByRole( 'link', { name: /Filter/ } ) );

expect( getQuery().source_is ).toEqual( 'visa' );
} );

test( 'should filter by is_not', () => {
user.selectOptions( ruleSelector, 'is_not' );

user.selectOptions(
screen.getByRole( 'combobox', {
name: /Select a payment method$/i,
} ),
'visa'
);
user.click( screen.getByRole( 'link', { name: /Filter/ } ) );

expect( getQuery().source_is_not ).toEqual( 'visa' );
} );
} );

describe( 'when filtering by source device', () => {
let ruleSelector: HTMLElement;

Expand Down

0 comments on commit 8ae551e

Please sign in to comment.