test: improve utils coverage (#4230)
* test: improve utils coverage * refactor: review - rename isDefined to isNonNullable, update tests and return statement
This commit is contained in:
@ -1,19 +0,0 @@
|
||||
import { assertNotNull } from '~/utils/assert';
|
||||
|
||||
describe('assert', () => {
|
||||
it('should return true for a NonNullable value', () => {
|
||||
expect(assertNotNull(1)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true for a NonNullable value', () => {
|
||||
expect(assertNotNull('')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false for a null value', () => {
|
||||
expect(assertNotNull(null)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return false for an undefined value', () => {
|
||||
expect(assertNotNull(undefined)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
describe('isDefined', () => {
|
||||
it('should return true for a NonNullable value', () => {
|
||||
expect(isDefined(1)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for a NonNullable value', () => {
|
||||
expect(isDefined('')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for a null value', () => {
|
||||
expect(isDefined(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for an undefined value', () => {
|
||||
expect(isDefined(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
describe('isNonNullable', () => {
|
||||
it('returns true if value is not undefined nor null', () => {
|
||||
expect(isNonNullable('')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if value is null', () => {
|
||||
expect(isNonNullable(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if value is undefined', () => {
|
||||
expect(isNonNullable(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { parseApolloStoreFieldName } from '../parseApolloStoreFieldName';
|
||||
|
||||
describe('parseApolloStoreFieldName', () => {
|
||||
it('returns an empty object if string is not a valid store field name', () => {
|
||||
const result = parseApolloStoreFieldName('////');
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it('returns the field name and parsed variables if they exist', () => {
|
||||
const result = parseApolloStoreFieldName('fieldName({"key":"value"})');
|
||||
expect(result).toEqual({
|
||||
fieldName: 'fieldName',
|
||||
fieldVariables: { key: 'value' },
|
||||
});
|
||||
});
|
||||
|
||||
it('returns only the field name if the variables cannot be parsed', () => {
|
||||
const result = parseApolloStoreFieldName('fieldName(notJson)');
|
||||
expect(result).toEqual({
|
||||
fieldName: 'fieldName',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns only the field name if there are no variables', () => {
|
||||
const result = parseApolloStoreFieldName('fieldName');
|
||||
expect(result).toEqual({
|
||||
fieldName: 'fieldName',
|
||||
});
|
||||
});
|
||||
});
|
||||
35
packages/twenty-front/src/utils/__tests__/sort.test.ts
Normal file
35
packages/twenty-front/src/utils/__tests__/sort.test.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { sortAsc, sortDesc, sortNullsFirst, sortNullsLast } from '../sort';
|
||||
|
||||
describe('sort', () => {
|
||||
describe('sortNullsFirst', () => {
|
||||
it('should sort nulls first', () => {
|
||||
expect(sortNullsFirst(null, 'a')).toBe(-1);
|
||||
expect(sortNullsFirst('a', null)).toBe(1);
|
||||
expect(sortNullsFirst('a', 'a')).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortNullsLast', () => {
|
||||
it('should sort nulls last', () => {
|
||||
expect(sortNullsLast(null, 'a')).toBe(1);
|
||||
expect(sortNullsLast('a', null)).toBe(-1);
|
||||
expect(sortNullsLast('a', 'a')).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortAsc', () => {
|
||||
it('should sort in ascending order', () => {
|
||||
expect(sortAsc('a', 'b')).toBe(-1);
|
||||
expect(sortAsc('b', 'a')).toBe(1);
|
||||
expect(sortAsc('a', 'a')).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortDesc', () => {
|
||||
it('should sort in descending order', () => {
|
||||
expect(sortDesc('a', 'b')).toBe(1);
|
||||
expect(sortDesc('b', 'a')).toBe(-1);
|
||||
expect(sortDesc('a', 'a')).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user