mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-18 11:04:03 +01:00
fix: misc
This commit is contained in:
@@ -24,7 +24,11 @@ const SelectWithDesc = <T extends string | boolean>({
|
||||
description: string;
|
||||
}) => {
|
||||
const handleChange = (event: SelectChangeEvent<T>) => {
|
||||
onChange(event.target.value as T);
|
||||
const newValue =
|
||||
typeof selected === 'boolean'
|
||||
? event.target.value === 'true'
|
||||
: event.target.value;
|
||||
onChange(newValue as T);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Box, TextField } from '@mui/material';
|
||||
import React, { useContext } from 'react';
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { CustomSnackBarContext } from '../../contexts/CustomSnackBarContext';
|
||||
import InputHeader from '../InputHeader';
|
||||
import ResultFooter from './ResultFooter';
|
||||
import { replaceSpecialCharacters } from '../../utils/string';
|
||||
|
||||
export default function ToolTextResult({
|
||||
title = 'Result',
|
||||
@@ -37,7 +38,7 @@ export default function ToolTextResult({
|
||||
<Box>
|
||||
<InputHeader title={title} />
|
||||
<TextField
|
||||
value={value}
|
||||
value={replaceSpecialCharacters(value)}
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
|
||||
@@ -1,65 +1,105 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import { TopItemsList, SplitOperatorType, SortingMethod, DisplayFormat } from './service';
|
||||
import {
|
||||
TopItemsList,
|
||||
SplitOperatorType,
|
||||
SortingMethod,
|
||||
DisplayFormat
|
||||
} from './service';
|
||||
|
||||
describe('TopItemsList function', () => {
|
||||
it('should handle sorting alphabetically ignoring case', () => {
|
||||
const input = 'Apple,banana,apple,Orange,Banana,apple';
|
||||
const result = TopItemsList('symbol', 'alphabetic', 'count', ',', input, false, true, false);
|
||||
expect(result).toEqual(
|
||||
'apple: 3\n' +
|
||||
'banana: 2\n' +
|
||||
'orange: 1'
|
||||
);
|
||||
});
|
||||
it('should handle sorting alphabetically ignoring case', () => {
|
||||
const input = 'Apple,banana,apple,Orange,Banana,apple';
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
'alphabetic',
|
||||
'count',
|
||||
',',
|
||||
input,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
);
|
||||
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
|
||||
});
|
||||
|
||||
it('should handle sorting by count and not ignoring case', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple,Banana';
|
||||
const result = TopItemsList('symbol', 'count', 'count', ',', input, false, false, false);
|
||||
expect(result).toEqual(
|
||||
'apple: 3\n' +
|
||||
'banana: 2\n' +
|
||||
'orange: 1\n' +
|
||||
'Banana: 1'
|
||||
);
|
||||
});
|
||||
it('should handle sorting by count and not ignoring case', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple,Banana';
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
'count',
|
||||
'count',
|
||||
',',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toEqual(
|
||||
'apple: 3\n' + 'banana: 2\n' + 'orange: 1\n' + 'Banana: 1'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle regex split operator', () => {
|
||||
const input = 'apple123banana456apple789orange012banana345apple678';
|
||||
const result = TopItemsList('regex', 'count', 'count', '\\d+', input, false, false, false);
|
||||
expect(result).toEqual(
|
||||
'apple: 3\n' +
|
||||
'banana: 2\n' +
|
||||
'orange: 1'
|
||||
);
|
||||
});
|
||||
it('should handle regex split operator', () => {
|
||||
const input = 'apple123banana456apple789orange012banana345apple678';
|
||||
const result = TopItemsList(
|
||||
'regex',
|
||||
'count',
|
||||
'count',
|
||||
'\\d+',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
|
||||
});
|
||||
|
||||
it('should handle percentage display format', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple';
|
||||
const result = TopItemsList('symbol', 'count', 'percentage', ',', input, false, false, false);
|
||||
expect(result).toEqual(
|
||||
'apple: 3 (50.00%)\n' +
|
||||
'banana: 2 (33.33%)\n' +
|
||||
'orange: 1 (16.67%)'
|
||||
);
|
||||
});
|
||||
it('should handle percentage display format', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple';
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
'count',
|
||||
'percentage',
|
||||
',',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toEqual(
|
||||
'apple: 3 (50.00%)\n' + 'banana: 2 (33.33%)\n' + 'orange: 1 (16.67%)'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle total display format', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple';
|
||||
const result = TopItemsList('symbol', 'count', 'total', ',', input, false, false, false);
|
||||
expect(result).toEqual(
|
||||
'apple: 3 (3 / 6)\n' +
|
||||
'banana: 2 (2 / 6)\n' +
|
||||
'orange: 1 (1 / 6)'
|
||||
);
|
||||
});
|
||||
it('should handle total display format', () => {
|
||||
const input = 'apple,banana,apple,orange,banana,apple';
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
'count',
|
||||
'total',
|
||||
',',
|
||||
input,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
expect(result).toEqual(
|
||||
'apple: 3 (3 / 6)\n' + 'banana: 2 (2 / 6)\n' + 'orange: 1 (1 / 6)'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle trimming and ignoring empty items', () => {
|
||||
const input = ' apple , banana , apple , orange , banana , apple ';
|
||||
const result = TopItemsList('symbol', 'count', 'count', ',', input, true, false, true);
|
||||
expect(result).toEqual(
|
||||
'apple: 3\n' +
|
||||
'banana: 2\n' +
|
||||
'orange: 1'
|
||||
);
|
||||
});
|
||||
});
|
||||
it('should handle trimming and ignoring empty items', () => {
|
||||
const input = ' apple , banana , apple , orange , banana , apple ';
|
||||
const result = TopItemsList(
|
||||
'symbol',
|
||||
'count',
|
||||
'count',
|
||||
',',
|
||||
input,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,7 +124,9 @@ export default function SplitText() {
|
||||
{ label: 'Increasing order', value: true },
|
||||
{ label: 'Decreasing order', value: false }
|
||||
]}
|
||||
onChange={(value) => updateField('increasing', value)}
|
||||
onChange={(value) => {
|
||||
updateField('increasing', value);
|
||||
}}
|
||||
description={'Select a sorting order.'}
|
||||
/>
|
||||
<CheckboxWithDesc
|
||||
|
||||
@@ -6,3 +6,13 @@ export function capitalizeFirstLetter(string: string | undefined) {
|
||||
export function isNumber(number: any) {
|
||||
return !isNaN(parseFloat(number)) && isFinite(number);
|
||||
}
|
||||
|
||||
export const replaceSpecialCharacters = (str: string) => {
|
||||
return str
|
||||
.replace(/\\n/g, '\n')
|
||||
.replace(/\\t/g, '\t')
|
||||
.replace(/\\r/g, '\r')
|
||||
.replace(/\\b/g, '\b')
|
||||
.replace(/\\f/g, '\f')
|
||||
.replace(/\\v/g, '\v');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user