1
+ import { observable } from 'mobx' ;
2
+
3
+ import { expect } from '../../../test-setup' ;
4
+
5
+ import { RawHeaders } from '../../../../src/types' ;
6
+
7
+ import {
8
+ syncUrlToHeaders
9
+ } from '../../../../src/model/http/editable-request-parts' ;
10
+
11
+ describe ( "Editable request header synchronization" , ( ) => {
12
+ describe ( "for hostnames" , ( ) => {
13
+ it ( "doesn't do anything immediately given an empty input" , ( ) => {
14
+ const url = observable . box ( '' ) ;
15
+ const headers : RawHeaders = observable ( [ ] ) ;
16
+
17
+ syncUrlToHeaders (
18
+ ( ) => url . get ( ) ,
19
+ ( ) => headers
20
+ ) ;
21
+
22
+ expect ( headers ) . to . deep . equal ( [ ] ) ;
23
+ } ) ;
24
+
25
+ it ( "doesn't do anything immediately given a plain protocol" , ( ) => {
26
+ const url = observable . box ( '' ) ;
27
+ const headers : RawHeaders = observable ( [ ] ) ;
28
+
29
+ syncUrlToHeaders (
30
+ ( ) => url . get ( ) ,
31
+ ( ) => headers
32
+ ) ;
33
+
34
+ url . set ( 'https://' ) ;
35
+
36
+ expect ( headers ) . to . deep . equal ( [ ] ) ;
37
+ } ) ;
38
+
39
+ it ( "initializes the host header when entering a first character of a URL" , ( ) => {
40
+ const url = observable . box ( '' ) ;
41
+ const headers : RawHeaders = observable ( [ ] ) ;
42
+
43
+ syncUrlToHeaders (
44
+ ( ) => url . get ( ) ,
45
+ ( ) => headers
46
+ ) ;
47
+
48
+ url . set ( 'https://' ) ;
49
+ url . set ( 'https://a' ) ;
50
+
51
+ expect ( headers ) . to . deep . equal ( [
52
+ [ 'host' , 'a' ]
53
+ ] ) ;
54
+ } ) ;
55
+
56
+ it ( "updates an entered matching URL and host header if the URL changes" , ( ) => {
57
+ const url = observable . box ( 'https://example.test:8080' ) ;
58
+ const headers : RawHeaders = observable ( [
59
+ [ 'host' , 'example.test:8080' ]
60
+ ] ) ;
61
+
62
+ syncUrlToHeaders (
63
+ ( ) => url . get ( ) ,
64
+ ( ) => headers
65
+ ) ;
66
+
67
+ url . set ( 'https://example2.test' ) ;
68
+
69
+ expect ( headers ) . to . deep . equal ( [
70
+ [ 'host' , 'example2.test' ]
71
+ ] ) ;
72
+ } ) ;
73
+
74
+ it ( "doesn't modify the host header if the URL changes but they didn't match initially" , ( ) => {
75
+ const url = observable . box ( 'https://example.test' ) ;
76
+ const headers : RawHeaders = observable ( [
77
+ [ 'host' , 'other.test' ]
78
+ ] ) ;
79
+
80
+ syncUrlToHeaders (
81
+ ( ) => url . get ( ) ,
82
+ ( ) => headers
83
+ ) ;
84
+
85
+ url . set ( 'https://example2.test' ) ;
86
+
87
+ expect ( headers ) . to . deep . equal ( [
88
+ [ 'host' , 'other.test' ]
89
+ ] ) ;
90
+ } ) ;
91
+
92
+ it ( "doesn't modify the host header or URL if the host header is modified manually" , ( ) => {
93
+ const url = observable . box ( 'https://example.test' ) ;
94
+ const headers : RawHeaders = observable ( [
95
+ [ 'host' , 'example.test' ]
96
+ ] ) ;
97
+
98
+ syncUrlToHeaders (
99
+ ( ) => url . get ( ) ,
100
+ ( ) => headers
101
+ ) ;
102
+
103
+ headers [ 0 ] [ 1 ] = 'other.test' ;
104
+
105
+ expect ( url . get ( ) ) . to . equal ( 'https://example.test' ) ;
106
+ } ) ;
107
+ } ) ;
108
+ } ) ;
0 commit comments