Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Nov 16, 2023
1 parent 3218e61 commit cff0be7
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,13 @@ describe('Transactions', () => {
test('dropdown automatically opens and can be filtered', async () => {
const { container } = renderTransactions();

let categories = categoryGroups.flatMap(group => group.categories);
let input = await editField(container, 'category', 2);
let tooltip = container.querySelector('[data-testid="autocomplete"]');
expect(tooltip).toBeTruthy();
expect(
[...tooltip.querySelectorAll('[data-testid*="category-item"]')].length,
).toBe(9);
).toBe(categoryGroups.length + categories.length);

await userEvent.clear(input);
await userEvent.type(input, 'Gener');
Expand All @@ -452,7 +453,7 @@ describe('Transactions', () => {
await userEvent.clear(input);
await userEvent.type(input, 'Usual Expenses');

items = tooltip.querySelectorAll('[data-testid*="category-item"]');
items = tooltip.querySelectorAll('[data-testid$="category-item"]');
expect(items.length).toBe(0);
});

Expand All @@ -463,13 +464,13 @@ describe('Transactions', () => {
let tooltip = container.querySelector('[data-testid="autocomplete"]');

// No item should be highlighted
let allHighlighted = tooltip.querySelectorAll('[data-highlighted]');
expect(allHighlighted).toHaveLength(0);
let highlighted = tooltip.querySelector('[data-highlighted]');
expect(highlighted).toBeNull();

await userEvent.keyboard('[ArrowDown][ArrowDown][ArrowDown][ArrowDown]');

// The right item should be highlighted
let highlighted = tooltip.querySelector('[data-highlighted]');
highlighted = tooltip.querySelector('[data-highlighted]');
expect(highlighted).not.toBeNull();
expect(highlighted.textContent).toBe('General');

Expand Down Expand Up @@ -503,15 +504,15 @@ describe('Transactions', () => {
let tooltip = container.querySelector('[data-testid="autocomplete"]');

// Make sure none of the items are highlighted
let items = tooltip.querySelectorAll('[data-testid*="category-item"]');
let allHighlighted = tooltip.querySelectorAll('[data-highlighted]');
expect(allHighlighted).toHaveLength(0);
let items = tooltip.querySelectorAll('[data-testid$="category-item"]');
let highlighted = tooltip.querySelector('[data-highlighted]');
expect(highlighted).toBeNull();

// Hover over an item
await userEvent.hover(items[2]);

// Make sure the expected category is highlighted
let highlighted = tooltip.querySelector('[data-highlighted]');
highlighted = tooltip.querySelector('[data-highlighted]');
expect(highlighted).not.toBeNull();
expect(highlighted.textContent).toBe('General');

Expand All @@ -538,7 +539,7 @@ describe('Transactions', () => {
let oldCategory = getTransactions()[2].category;
let tooltip = container.querySelector('[data-testid="autocomplete"]');

let items = tooltip.querySelectorAll('[data-testid*="category-item"]');
let items = tooltip.querySelectorAll('[data-testid$="category-item"]');

// Hover over a few of the items to highlight them
await userEvent.hover(items[2]);
Expand Down

0 comments on commit cff0be7

Please sign in to comment.