Skip to content

Commit

Permalink
revert: textinput changes (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWaldschmidt committed Apr 17, 2024
1 parent 535d78e commit 181e27f
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 178 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v2.0.37

- Revert `<TextInput />` changes

## v2.0.36

- Fix `<TextInput />` ref
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lob/ui-components",
"version": "2.0.36",
"version": "2.0.37",
"engines": {
"node": ">=20.2.0",
"npm": ">=10.2.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { RenderResult, render } from '@testing-library/vue';
import { render } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import { translate } from '@/mixins';
import DateInput from '../DateInput.vue';
Expand Down Expand Up @@ -57,24 +57,21 @@ describe('DateInput', () => {

expect(emittedEvent).toHaveProperty('update:open');
const length = emittedEvent['update:open'].length;
// @ts-expect-error No types.
expect(emittedEvent['update:open'][length - 1][0]).toEqual(true); // last event should be an open event
});

describe('selecting a date', () => {
let props;
let component: RenderResult;
let dateToSelect: HTMLButtonElement | null;
let component;
let dateToSelect;
const RealDate = global.Date;

beforeEach(() => {
props = { ...initialProps, open: true };

const oldGlobalDate = global.Date;
// @ts-expect-error Improper way of mocking dates.
global.Date = vi.fn((...args) => {
if (args.length) {
// @ts-expect-error Improper way of mocking dates.
return new RealDate(...args);
}
return new Date(2021, 5, 14);
Expand All @@ -88,30 +85,30 @@ describe('DateInput', () => {
// which ensures the minDate and maxDate default values are set correctly
vi.useRealTimers();
component = renderComponent({ props });
const { getByText } = component;
dateToSelect = getByText(23).closest('button');
const { queryByText } = component;
dateToSelect = queryByText(23).closest('button');
});

it('emits an update:open event with value false', async () => {
const { emitted } = component;

if (dateToSelect) {
await userEvent.click(dateToSelect);
}
await userEvent.click(dateToSelect);
const emittedEvent = emitted();
expect(emittedEvent).toHaveProperty('update:open', [[false]]);
expect(emittedEvent).toHaveProperty('update:open');

expect(emittedEvent['update:open'][0][0]).toEqual(false);
});

it('emits an update:modelValue event', async () => {
const { emitted } = component;

if (dateToSelect) {
await userEvent.click(dateToSelect);
}
await userEvent.click(dateToSelect);
const emittedEvent = emitted();
expect(emittedEvent).toHaveProperty('update:modelValue', [
[new Date(2022, 5, 23)]
]);
expect(emittedEvent).toHaveProperty('update:modelValue');

expect(emittedEvent['update:modelValue'][0][0]).toEqual(
new Date(2022, 5, 23)
);
});
});

Expand All @@ -125,7 +122,7 @@ describe('DateInput', () => {
const { getByText, getByTestId } = renderComponent({ props });

const textInput = getByTestId('input-container');
expect(textInput).toHaveClass('!border-error-dark');
expect(textInput).toHaveClass('!border-red-600');
const errorMessage = getByText('Date no longer valid');
expect(errorMessage).toBeVisible();
});
Expand Down
Loading

0 comments on commit 181e27f

Please sign in to comment.