|
1 | 1 | import { MockRequest } from '@/components/dictionaries/helpers' |
2 | 2 |
|
3 | | -export const mockSearchTexts = ['test'] |
4 | | - |
5 | | -const html = ` |
6 | | - <div |
7 | | - class="dictentry" |
8 | | - data-type-block="definition.title.type.cobuild" |
9 | | - data-title-block="definition.title.type.cobuild" |
10 | | - data-num-block="1" |
11 | | - > |
12 | | - <span class="pron"> |
13 | | - <a class="audio_play_button" data-src-mp3="https://example.com/uk.mp3"></a> |
14 | | - </span> |
15 | | - <div class="def">definition</div> |
16 | | - </div> |
17 | | - <div |
18 | | - class="dictentry" |
19 | | - data-type-block="definition.title.type.ced" |
20 | | - data-title-block="" |
21 | | - data-num-block="2" |
22 | | - > |
23 | | - <span class="pron"> |
24 | | - <a class="audio_play_button" data-src-mp3="https://example.com/ced.mp3"></a> |
25 | | - </span> |
26 | | - <div class="def">ced definition</div> |
27 | | - </div> |
28 | | - <div |
29 | | - class="dictentry" |
30 | | - data-type-block="definition.title.type.penguin" |
31 | | - data-title-block="" |
32 | | - data-num-block="3" |
33 | | - > |
34 | | - <div class="def">penguin definition</div> |
35 | | - </div> |
36 | | - <div |
37 | | - class="dictentry" |
38 | | - data-type-block="definition.title.type.examples" |
39 | | - data-title-block="" |
40 | | - data-num-block="" |
41 | | - > |
42 | | - <div class="quote">example sentence</div> |
43 | | - </div> |
44 | | - <div |
45 | | - class="dictentry" |
46 | | - data-type-block="Video pronunciation" |
47 | | - data-title-block="" |
48 | | - data-num-block="" |
49 | | - > |
50 | | - <div class="video">video</div> |
51 | | - </div> |
52 | | - <div |
53 | | - class="dictentry" |
54 | | - data-type-block="Word lists" |
55 | | - data-title-block="" |
56 | | - data-num-block="" |
57 | | - > |
58 | | - <div>word list</div> |
59 | | - </div> |
60 | | - <div |
61 | | - class="dictentry" |
62 | | - data-type-block="definition.title.type.esp_ret" |
63 | | - data-title-block="" |
64 | | - data-num-block="" |
65 | | - > |
66 | | - <div class="def">retail definition</div> |
67 | | - </div> |
68 | | - <div |
69 | | - class="dictentry" |
70 | | - data-type-block="Word usage trends" |
71 | | - data-title-block="" |
72 | | - data-num-block="" |
73 | | - > |
74 | | - <div>trend</div> |
75 | | - </div> |
76 | | - <div |
77 | | - class="dictentry" |
78 | | - data-type-block="Translations of <b>{0}</b>" |
79 | | - data-title-block="" |
80 | | - data-num-block="" |
81 | | - > |
82 | | - <div>translation</div> |
83 | | - </div> |
84 | | - <div class="entry dictionary cB cB-i"> |
85 | | - <div |
86 | | - class="cB-h" |
87 | | - data-type-block="definition.title.type.idioms" |
88 | | - data-title-block="" |
89 | | - data-num-block="" |
90 | | - > |
91 | | - <h2 class="entry_title">More idioms containing <div class="h2_entry">pick</div></h2> |
92 | | - </div> |
93 | | - <div class="asset IdiomList assetlink"> |
94 | | - <a class="xr ref">pick holes in something</a> |
95 | | - </div> |
96 | | - </div> |
97 | | - <div class="entry dictionary cB cB-rel-t"> |
98 | | - <div |
99 | | - class="cB-h" |
100 | | - data-type-block="definition.title.type.collos" |
101 | | - data-title-block="" |
102 | | - data-num-block="" |
103 | | - > |
104 | | - <h2 class="entry_title">COBUILD Collocations <div class="h2_entry">pick</div></h2> |
105 | | - </div> |
106 | | - <div class="asset ColloList assetlink"> |
107 | | - <a class="xr ref">pick a favorite</a> |
108 | | - </div> |
109 | | - </div> |
110 | | -` |
| 3 | +export const mockSearchTexts = ['how', 'love'] |
111 | 4 |
|
112 | 5 | export const mockRequest: MockRequest = mock => { |
113 | | - mock.onGet(/collinsdictionary\.com.*\/verify/).reply(403) |
| 6 | + mock.onGet(/collinsdictionary\.com.*\/verify$/).reply(403) |
114 | 7 |
|
115 | | - mock.onGet(/collinsdictionary\.com\/zh/).reply(200, html) |
| 8 | + mock.onGet(/collinsdictionary/).reply(info => { |
| 9 | + const wordMatch = /[^/]+$/.exec(info.url || '') |
| 10 | + if (!wordMatch) { |
| 11 | + return [404] |
| 12 | + } |
116 | 13 |
|
117 | | - mock.onGet(/collinsdictionary/).reply(200, html) |
| 14 | + return [ |
| 15 | + 200, |
| 16 | + require(`raw-loader!./response/${decodeURIComponent(wordMatch[0])}.html`) |
| 17 | + .default |
| 18 | + ] |
| 19 | + }) |
118 | 20 | } |
0 commit comments