Files
tango/packages/helpers/tests/helpers.test.ts
T
Wells ffaa276b5c feat: refactor parse attribute value (#149)
* refactor: update attribute value parsing logic

* fix: refactor toggle setter logic

* fix: enhance basic setters

* fix: move basic value setter to setting-form package

* fix: add setter type

* fix: update

* feat: support toggle formObject to codeSetter

* fix: update invalid setter notice

* fix: update node2value

* fix: trigger onChange for formObject

* docs: update

* chore: up

* feat: improve code2value function and fix related issues

* Revert "chore: up"

This reverts commit a87d8fcce4.

* chore: update npm dependencies to latest versions
2024-05-16 13:03:41 +08:00

86 lines
2.8 KiB
TypeScript

import {
isVariableString,
parseDndTrackId,
getVariableContent,
camelCase,
parseDndId,
isValidUrl,
getCodeBlockFormMarkdown,
upperCamelCase,
} from '../src/helpers';
describe('string', () => {
it('camelCase', () => {
expect(camelCase('foo')).toEqual('foo');
expect(camelCase('foo-bar')).toEqual('fooBar');
expect(camelCase('Button')).toEqual('button');
expect(camelCase('DatePicker')).toEqual('datePicker');
});
it('upperCamelCase', () => {
expect(upperCamelCase('about')).toBe('About');
expect(upperCamelCase('not-found')).toBe('NotFound');
expect(upperCamelCase('@music/input')).toBe('MusicInput');
expect(upperCamelCase('@music/ct-input')).toBe('MusicCtInput');
});
it('isValidUrl', () => {
expect(isValidUrl('www.163.com')).toBeTruthy();
expect(isValidUrl('//www.163.com')).toBeTruthy();
expect(isValidUrl('https://www.163.com')).toBeTruthy();
expect(isValidUrl('http://www.163.com')).toBeTruthy();
expect(isValidUrl('/about')).toBeFalsy();
});
it('isVariableString', () => {
expect(isVariableString('{{this.foo}}')).toBeTruthy();
expect(isVariableString('{{!false}}')).toBeTruthy();
expect(isVariableString('{{[]}}')).toBeTruthy();
expect(isVariableString('{{{ foo: "bar" }}}')).toBeTruthy();
expect(isVariableString('{{[{ foo: "bar" }]}}')).toBeTruthy();
expect(isVariableString('{{123}}')).toBeTruthy();
expect(isVariableString('{{value}}')).toBeTruthy();
expect(isVariableString('{{"hello"}}')).toBeTruthy();
expect(isVariableString('{ foo: "bar" }')).toBeFalsy();
expect(isVariableString('{ type: tango.stores?.homePage?.tabKey }')).toBeFalsy();
expect(isVariableString('{ type: tango.stores.homePage.tabKey }')).toBeFalsy();
expect(isVariableString('{ foo: "bar" }')).toBeFalsy();
});
it('getVariableContent', () => {
expect(getVariableContent('{{!false}}')).toBe('!false');
});
it('parseDndTrackId', () => {
expect(parseDndTrackId('Button:123')).toEqual(['Button', 'Button:123']);
expect(parseDndTrackId('Button.Group:123')).toEqual(['Button.Group', 'Button.Group:123']);
});
it('parseDndId', () => {
expect(parseDndId('123')).toEqual({ id: '123' });
expect(parseDndId('Button:123')).toEqual({
component: 'Button',
id: 'Button:123',
index: '123',
});
expect(parseDndId('Button.Group:123')).toEqual({
component: 'Button.Group',
id: 'Button.Group:123',
index: '123',
});
expect(parseDndId('LocalBlock:Button.Group:123')).toEqual({
filename: 'LocalBlock',
module: 'LocalBlock',
component: 'Button.Group',
id: 'LocalBlock:Button.Group:123',
index: '123',
});
});
it('getCodeBlockFormMarkdown', () => {
expect(getCodeBlockFormMarkdown('```json\n{\n "disabled": true\n}\n```')).toBe(
'\n{\n "disabled": true\n}\n',
);
});
});