* chore: build pipeline for v2

* chore: run unit tests

* chore: configure sentry build
This commit is contained in:
Carlos Valente
2023-04-01 23:06:42 +02:00
committed by GitHub
parent 9338a615d4
commit 7456205b6e
27 changed files with 680 additions and 425 deletions
@@ -1,89 +0,0 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import TextInput from '../TextInput';
describe('TextInput component', () => {
describe('when given props', () => {
// small hack to reset DOM between tests
beforeEach(() => {
document.getElementsByTagName('html')[0].innerHTML = '';
});
it('renders correctly', () => {
const testField = 'title';
const testText = 'Test 123';
const submitHandler = vi.fn();
render(<TextInput field={testField} initialText={testText} submitHandler={submitHandler} />);
const input = screen.getByTestId('input-textfield');
expect(input).toBeInTheDocument();
expect(input).toHaveValue(testText);
});
it('Handles renders as textarea', () => {
const testField = 'title';
const testText = 'Test 123';
const submitHandler = vi.fn();
render(<TextInput field={testField} initialText={testText} isTextArea submitHandler={submitHandler} />);
const input = screen.getByTestId('input-textarea');
expect(input).toBeInTheDocument();
expect(input).toHaveValue(testText);
});
});
describe('on status change', () => {
// small hack to reset DOM between tests
afterEach(() => {
document.getElementsByTagName('html')[0].innerHTML = '';
});
it('calls submitHandler on new value', async () => {
const testField = 'title';
const testText = 'Test 123';
const myTypedString = '456';
const expectedString = testText + myTypedString;
const submitHandler = vi.fn();
render(<TextInput field={testField} initialText={testText} submitHandler={submitHandler} />);
const input = screen.getByTestId('input-textfield');
// submit without changing value
await userEvent.type(input, '{enter}');
expect(submitHandler).not.toHaveBeenCalled();
// on new value we can submit
await userEvent.type(input, myTypedString);
expect(input).toHaveValue(expectedString);
await userEvent.type(input, '{enter}');
expect(submitHandler).toHaveBeenCalledWith(testField, expectedString);
});
it('cleans value before submitting', async () => {
const testField = 'title';
const myTypedString = ' 456 ';
const expectedString = '456';
const submitHandler = vi.fn();
render(<TextInput field={testField} submitHandler={submitHandler} />);
const input = screen.getByTestId('input-textfield');
// on new value we can submit
await userEvent.type(input, myTypedString);
expect(input).toHaveValue(myTypedString);
await userEvent.type(input, '{enter}');
expect(submitHandler).toHaveBeenCalledWith(testField, expectedString);
});
});
describe('handles edge cases', () => {
it('handles undefined value', () => {
const testField = 'title';
const expected = '';
render(<TextInput field={testField} submitHandler={vi.fn()} />);
const input = screen.getByTestId('input-textfield');
expect(input).toBeInTheDocument();
expect(input).toHaveValue(expected);
});
});
});
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`cx() > ignores falsy values 1`] = `""`;
@@ -54,13 +54,6 @@ describe('test string from formatDisplay function', () => {
});
});
describe('test formatDisplay handles partial secs', () => {
it('test with 1795829', () => {
const t = { val: 1795829, result: '00:29:55' };
expect(formatDisplay(t.val)).toBe(t.result);
});
});
describe('test string from formatDisplay function with hidezero', () => {
it('test with null values', () => {
const t = { val: null, result: '00:00' };