mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
fbbf34e1d0
ref https://linear.app/ghost/issue/DES-1020/create-new-react-app-for-shade Shade is our new design system that follows React best practices and leverages third-party libraries extensively. It's built on ShadCN/UI which is one of the most popular React UI libraries today. This commit adds an (almost) empty React app, set up to be the a starting point of Shade.
69 lines
3.4 KiB
TypeScript
69 lines
3.4 KiB
TypeScript
import * as assert from 'assert/strict';
|
|
import {formatUrl} from '../../../src/utils/formatUrl';
|
|
|
|
describe('formatUrl', function () {
|
|
it('displays empty string if the input is empty and nullable is true', function () {
|
|
const formattedUrl = formatUrl('', undefined, true);
|
|
assert.deepEqual(formattedUrl, {save: null, display: ''});
|
|
});
|
|
|
|
it('displays empty string value if the input has only whitespace', function () {
|
|
const formattedUrl = formatUrl('');
|
|
assert.deepEqual(formattedUrl, {save: '', display: ''});
|
|
});
|
|
|
|
it('displays base value if the input has only whitespace and base url is available', function () {
|
|
const formattedUrl = formatUrl('', 'http://example.com');
|
|
assert.deepEqual(formattedUrl, {save: '/', display: 'http://example.com'});
|
|
});
|
|
|
|
it('displays a mailto address for an email address', function () {
|
|
const formattedUrl = formatUrl('test@example.com');
|
|
assert.deepEqual(formattedUrl, {save: 'mailto:test@example.com', display: 'mailto:test@example.com'});
|
|
});
|
|
|
|
it('displays an anchor link without formatting', function () {
|
|
const formattedUrl = formatUrl('#section');
|
|
assert.deepEqual(formattedUrl, {save: '#section', display: '#section'});
|
|
});
|
|
|
|
it('displays a protocol-relative link without formatting', function () {
|
|
const formattedUrl = formatUrl('//example.com');
|
|
assert.deepEqual(formattedUrl, {save: '//example.com', display: '//example.com'});
|
|
});
|
|
|
|
it('adds https:// automatically', function () {
|
|
const formattedUrl = formatUrl('example.com');
|
|
assert.deepEqual(formattedUrl, {save: 'https://example.com/', display: 'https://example.com/'});
|
|
});
|
|
|
|
it('saves a relative URL if the input is a pathname', function () {
|
|
const formattedUrl = formatUrl('/path', 'http://example.com');
|
|
assert.deepEqual(formattedUrl, {save: '/path/', display: 'http://example.com/path/'});
|
|
});
|
|
|
|
it('saves a relative URL if the input is a pathname, even if the base url has an non-empty pathname', function () {
|
|
const formattedUrl = formatUrl('/path', 'http://example.com/blog');
|
|
assert.deepEqual(formattedUrl, {save: '/path/', display: 'http://example.com/blog/path/'});
|
|
});
|
|
|
|
it('saves a relative URL if the input includes the base url', function () {
|
|
const formattedUrl = formatUrl('http://example.com/path', 'http://example.com');
|
|
assert.deepEqual(formattedUrl, {save: '/path/', display: 'http://example.com/path/'});
|
|
});
|
|
|
|
it('saves a relative URL if the input includes the base url, even if the base url has an non-empty pathname', function () {
|
|
const formattedUrl = formatUrl('http://example.com/blog/path', 'http://example.com/blog');
|
|
assert.deepEqual(formattedUrl, {save: '/path/', display: 'http://example.com/blog/path/'});
|
|
});
|
|
|
|
it('saves an absolute URL if the input has a different pathname to the base url', function () {
|
|
const formattedUrl = formatUrl('http://example.com/path', 'http://example.com/blog');
|
|
assert.deepEqual(formattedUrl, {save: 'http://example.com/path', display: 'http://example.com/path'});
|
|
});
|
|
|
|
it('saves an absolte URL if the input has a different hostname to the base url', function () {
|
|
const formattedUrl = formatUrl('http://another.com/path', 'http://example.com');
|
|
assert.deepEqual(formattedUrl, {save: 'http://another.com/path', display: 'http://another.com/path'});
|
|
});
|
|
});
|