File size: 3,008 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { forEach } from 'lodash';
import {
	getFixedDomainSearch,
	getDomainSuggestionSearch,
	getDomainProductSlug,
} from 'calypso/lib/domains';

describe( 'index', () => {
	describe( '#getFixedDomainSearch', () => {
		test( 'should return an empty string when searching for generic URL prefixes', () => {
			const searches = [ 'http://', 'https://' ];

			forEach( searches, ( search ) => {
				expect( getFixedDomainSearch( search ) ).toEqual( '' );
			} );
		} );

		test( 'should strip generic URL prefixes from a valid search string', () => {
			const searches = [
				'http://example.com',
				'https://example.com',
				'www.example.com',
				'www1.example.com',
				'http://www.example.com',
				'https://www.example.com',
			];

			forEach( searches, ( search ) => {
				expect( getFixedDomainSearch( search ) ).toEqual( 'example.com' );
			} );
		} );

		test( 'should allow domain names beginning with www or http(s)', () => {
			const searches = [ 'wwwexample.com', 'httpexample.com', 'httpsexample.com' ];

			forEach( searches, ( search ) => {
				expect( getFixedDomainSearch( search ) ).toEqual( search );
			} );
		} );

		test( 'should allow accent characters on domain search', () => {
			const searches = [
				{
					search: 'alimentaçãosaudável.com.br',
					expected: 'alimentaçãosaudável.com.br',
				},
				{
					search: 'meudomínioação.com',
					expected: 'meudomínioação.com',
				},
				{
					// Should still remove & and * characteres
					search: 'meudomínioação&*ê.com',
					expected: 'meudomínioaçãoê.com',
				},
			];

			forEach( searches, ( search ) => {
				expect( getFixedDomainSearch( search.search ) ).toEqual( search.expected );
			} );
		} );
	} );

	describe( '#getDomainSuggestionSearch', () => {
		test( 'should return an empty string when searching for www, http or https', () => {
			const searches = [ 'www', 'http', 'https' ];

			forEach( searches, ( search ) => {
				expect( getDomainSuggestionSearch( search ) ).toEqual( '' );
			} );
		} );

		test( 'should return an empty string when searching for a string shorter than the minimum length', () => {
			const minLength = 3;
			const search = 'zz';
			expect( getDomainSuggestionSearch( search, minLength ) ).toEqual( '' );
		} );

		test( 'should return the original search string if it is long enough and is not one of the ignored strings', () => {
			const search = 'hippos';
			expect( getDomainSuggestionSearch( search ) ).toEqual( search );
		} );
	} );

	describe( '#getDomainProductSlug', () => {
		test( 'should return dotorg_domain for a .org domain', () => {
			expect( getDomainProductSlug( 'test-domain.org' ) ).toEqual( 'dotorg_domain' );
		} );

		test( 'should return dotnet_domain for a .net domain', () => {
			expect( getDomainProductSlug( 'test-domain.net' ) ).toEqual( 'dotnet_domain' );
		} );

		test( 'should return domain_reg for a .com domain', () => {
			expect( getDomainProductSlug( 'test-domain.com' ) ).toEqual( 'domain_reg' );
		} );
	} );
} );