Skip to content

Commit

Permalink
upstream: fix string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
latter-bolden committed Mar 5, 2024
1 parent 07ed803 commit 211f4cb
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions apps/tlon-mobile/src/utils/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,59 @@ import { expect, test } from 'vitest';
import { formatPhoneNumber, transformShipURL } from './string';

test('formats phone number without country code', () => {
expect(formatPhoneNumber('5555555555'), '(555) 555-5555');
expect(formatPhoneNumber('555-555-5555'), '(555) 555-5555');
expect(formatPhoneNumber('5555555555')).toBe('(555) 555-5555');
expect(formatPhoneNumber('555-555-5555')).toBe('(555) 555-5555');
});

test('formats phone number with country code', () => {
expect(formatPhoneNumber('15555555555'), '+1 (555) 555-5555');
expect(formatPhoneNumber('+15555555555'), '+1 (555) 555-5555');
expect(formatPhoneNumber('15555555555')).toBe('+1 (555) 555-5555');
expect(formatPhoneNumber('+15555555555')).toBe('+1 (555) 555-5555');
});

test('skips when given unknown format', () => {
expect(formatPhoneNumber('1234'), '1234');
expect(formatPhoneNumber('1234')).toBe('1234');
});

test('transforms ship url without a protocol', () => {
expect(
transformShipURL('sampel-palnet.tlon.network'),
expect(transformShipURL('sampel-palnet.tlon.network')).toBe(
'https://sampel-palnet.tlon.network'
);
});

test('transforms ship url with a path', () => {
expect(
transformShipURL('sampel-palnet.tlon.network/apps/groups'),
expect(transformShipURL('sampel-palnet.tlon.network/apps/groups')).toBe(
'https://sampel-palnet.tlon.network'
);
});

test('transforms ship url with a protocol and extra whitespace', () => {
expect(
transformShipURL('https://sampel-palnet.tlon.network '),
expect(transformShipURL('https://sampel-palnet.tlon.network ')).toBe(
'https://sampel-palnet.tlon.network'
);
});

test('transforms ship url with trailing slash', () => {
expect(transformShipURL('https://sampel-palnet.tlon.network/')).toBe(
'https://sampel-palnet.tlon.network'
);
});

test('if a ship url is already valid, it is returned as is', () => {
expect(
transformShipURL('https://sampel-palnet.tlon.network'),
expect(transformShipURL('https://sampel-palnet.tlon.network')).toBe(
'https://sampel-palnet.tlon.network'
);
});

test('if a ship url is an ip address with a port, it is returned as is', () => {
expect(
transformShipURL('http://192.168.0.1:8443'),
expect(transformShipURL('http://192.168.0.1:8443')).toBe(
'http://192.168.0.1:8443'
);
});

test('if a ship url is an ip address without a port, it is returned as is', () => {
expect(transformShipURL('http://192.168.0.1'), 'http://192.168.0.1');
expect(transformShipURL('http://192.168.0.1')).toBe('http://192.168.0.1');
});

test('if a ship url is http://localhost, it is returned as is', () => {
expect(transformShipURL('http://localhost'), 'http://localhost');
expect(transformShipURL('http://localhost')).toBe('http://localhost');
});

0 comments on commit 211f4cb

Please sign in to comment.