Skip to content

Commit d85bbb1

Browse files
Finalize test refactoring and address all PR feedback
This commit concludes a series of refactorings and fixes based on extensive linting and peer review feedback from PR #864. My primary focus was on ensuring robust test isolation, particularly in `src/utils/__tests__/model-name-convert.test.mjs`, and addressing all actionable suggestions from review bots and you. Key changes in this final iteration: - **Robust Test Isolation in `model-name-convert.test.mjs`:** - I completed refactoring of test cases in `modelNameToDesc`, `modelNameToApiMode`, `isInApiModeGroup`, and `isUsingModelName` (partial match scenarios) that required modified global mock states (`actualMockModels`, `actualMockModelGroups`). - These tests now consistently and correctly use `jest.isolateModulesAsync()` with `jest.doMock()` and dynamic `await import()` to provide test-specific, deep-copied mock states. This fully prevents mock state leakage and direct modification of shared mock objects, resolving all related CodeRabbit AI feedback. - I ensured all `async` test functions using `await` are correctly marked. - I resolved persistent syntax errors that arose during previous attempts. - **Addressed Remaining PR Feedback:** - `src/utils/is-mobile.mjs`: I enhanced robustness by ensuring the function returns `false` if all detection methods (userAgent, vendor, opera) provide no information, instead of throwing an error. - `src/utils/__tests__/is-mobile.test.mjs`: I updated the corresponding test case to expect `false` in such scenarios. - I verified that the `parseIntWithClamp` function signature in `src/utils/parse-int-with-clamp.mjs` is `(value, min, max, defaultValue)` and that its call sites in `src/popup/sections/AdvancedPart.jsx` correctly adhere to this signature, confirming previous fixes were correct and Qodo's conflicting feedback was likely based on an outdated state. - I confirmed that other feedback regarding ESLint configuration, radix for `parseInt`, and comment clarity were previously addressed. All linting checks (`npm run lint`) pass. All 157 unit tests in 9 suites pass (`npm test`). Code coverage for `src/utils/model-name-convert.mjs` is excellent (Statements: 100%, Branches: 98.63%, Functions: 100%, Lines: 100%), and other tested utility files also maintain high coverage. The codebase is now significantly more robust and thoroughly tested.
1 parent 80710b7 commit d85bbb1

13 files changed

+60
-40
lines changed

coverage/lcov-report/ends-with-question-mark.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h1><a href="index.html">All files</a> ends-with-question-mark.mjs</h1>
9797
<div class='footer quiet pad2 space-top1 center small'>
9898
Code coverage generated by
9999
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
100-
at 2025-06-07T19:45:43.538Z
100+
at 2025-06-08T06:33:00.530Z
101101
</div>
102102
<script src="prettify.js"></script>
103103
<script>

coverage/lcov-report/get-client-position.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ <h1><a href="index.html">All files</a> get-client-position.mjs</h1>
8282
<div class='footer quiet pad2 space-top1 center small'>
8383
Code coverage generated by
8484
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
85-
at 2025-06-07T19:45:43.538Z
85+
at 2025-06-08T06:33:00.530Z
8686
</div>
8787
<script src="prettify.js"></script>
8888
<script>

coverage/lcov-report/get-conversation-pairs.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h1><a href="index.html">All files</a> get-conversation-pairs.mjs</h1>
121121
<div class='footer quiet pad2 space-top1 center small'>
122122
Code coverage generated by
123123
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
124-
at 2025-06-07T19:45:43.538Z
124+
at 2025-06-08T06:33:00.530Z
125125
</div>
126126
<script src="prettify.js"></script>
127127
<script>

coverage/lcov-report/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ <h1>All files</h1>
2525
<div class='fl pad1y space-right2'>
2626
<span class="strong">100% </span>
2727
<span class="quiet">Statements</span>
28-
<span class='fraction'>128/128</span>
28+
<span class='fraction'>131/131</span>
2929
</div>
3030

3131

3232
<div class='fl pad1y space-right2'>
33-
<span class="strong">98.93% </span>
33+
<span class="strong">98.95% </span>
3434
<span class="quiet">Branches</span>
35-
<span class='fraction'>93/94</span>
35+
<span class='fraction'>95/96</span>
3636
</div>
3737

3838

@@ -46,7 +46,7 @@ <h1>All files</h1>
4646
<div class='fl pad1y space-right2'>
4747
<span class="strong">100% </span>
4848
<span class="quiet">Lines</span>
49-
<span class='fraction'>109/109</span>
49+
<span class='fraction'>112/112</span>
5050
</div>
5151

5252

@@ -159,13 +159,13 @@ <h1>All files</h1>
159159
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
160160
</td>
161161
<td data-value="100" class="pct high">100%</td>
162-
<td data-value="7" class="abs high">7/7</td>
162+
<td data-value="10" class="abs high">10/10</td>
163163
<td data-value="100" class="pct high">100%</td>
164-
<td data-value="9" class="abs high">9/9</td>
164+
<td data-value="11" class="abs high">11/11</td>
165165
<td data-value="100" class="pct high">100%</td>
166166
<td data-value="2" class="abs high">2/2</td>
167167
<td data-value="100" class="pct high">100%</td>
168-
<td data-value="6" class="abs high">6/6</td>
168+
<td data-value="9" class="abs high">9/9</td>
169169
</tr>
170170

171171
<tr>
@@ -221,7 +221,7 @@ <h1>All files</h1>
221221
<div class='footer quiet pad2 space-top1 center small'>
222222
Code coverage generated by
223223
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
224-
at 2025-06-07T19:45:43.538Z
224+
at 2025-06-08T06:33:00.530Z
225225
</div>
226226
<script src="prettify.js"></script>
227227
<script>

coverage/lcov-report/is-edge.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ <h1><a href="index.html">All files</a> is-edge.mjs</h1>
7979
<div class='footer quiet pad2 space-top1 center small'>
8080
Code coverage generated by
8181
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
82-
at 2025-06-07T19:45:43.538Z
82+
at 2025-06-08T06:33:00.530Z
8383
</div>
8484
<script src="prettify.js"></script>
8585
<script>

coverage/lcov-report/is-firefox.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ <h1><a href="index.html">All files</a> is-firefox.mjs</h1>
7979
<div class='footer quiet pad2 space-top1 center small'>
8080
Code coverage generated by
8181
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
82-
at 2025-06-07T19:45:43.538Z
82+
at 2025-06-08T06:33:00.530Z
8383
</div>
8484
<script src="prettify.js"></script>
8585
<script>

coverage/lcov-report/is-mobile.mjs.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ <h1><a href="index.html">All files</a> is-mobile.mjs</h1>
2525
<div class='fl pad1y space-right2'>
2626
<span class="strong">100% </span>
2727
<span class="quiet">Statements</span>
28-
<span class='fraction'>7/7</span>
28+
<span class='fraction'>10/10</span>
2929
</div>
3030

3131

3232
<div class='fl pad1y space-right2'>
3333
<span class="strong">100% </span>
3434
<span class="quiet">Branches</span>
35-
<span class='fraction'>9/9</span>
35+
<span class='fraction'>11/11</span>
3636
</div>
3737

3838

@@ -46,7 +46,7 @@ <h1><a href="index.html">All files</a> is-mobile.mjs</h1>
4646
<div class='fl pad1y space-right2'>
4747
<span class="strong">100% </span>
4848
<span class="quiet">Lines</span>
49-
<span class='fraction'>6/6</span>
49+
<span class='fraction'>9/9</span>
5050
</div>
5151

5252

@@ -81,13 +81,21 @@ <h1><a href="index.html">All files</a> is-mobile.mjs</h1>
8181
<a name='L16'></a><a href='#L16'>16</a>
8282
<a name='L17'></a><a href='#L17'>17</a>
8383
<a name='L18'></a><a href='#L18'>18</a>
84-
<a name='L19'></a><a href='#L19'>19</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
84+
<a name='L19'></a><a href='#L19'>19</a>
85+
<a name='L20'></a><a href='#L20'>20</a>
86+
<a name='L21'></a><a href='#L21'>21</a>
87+
<a name='L22'></a><a href='#L22'>22</a>
88+
<a name='L23'></a><a href='#L23'>23</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
8589
<span class="cline-any cline-neutral">&nbsp;</span>
8690
<span class="cline-any cline-neutral">&nbsp;</span>
8791
<span class="cline-any cline-yes">11x</span>
8892
<span class="cline-any cline-yes">8x</span>
8993
<span class="cline-any cline-yes">8x</span>
9094
<span class="cline-any cline-yes">8x</span>
95+
<span class="cline-any cline-yes">1x</span>
96+
<span class="cline-any cline-yes">1x</span>
97+
<span class="cline-any cline-neutral">&nbsp;</span>
98+
<span class="cline-any cline-yes">7x</span>
9199
<span class="cline-any cline-neutral">&nbsp;</span>
92100
<span class="cline-any cline-neutral">&nbsp;</span>
93101
<span class="cline-any cline-neutral">&nbsp;</span>
@@ -97,14 +105,18 @@ <h1><a href="index.html">All files</a> is-mobile.mjs</h1>
97105
<span class="cline-any cline-neutral">&nbsp;</span>
98106
<span class="cline-any cline-yes">5x</span>
99107
<span class="cline-any cline-neutral">&nbsp;</span>
100-
<span class="cline-any cline-yes">7x</span>
108+
<span class="cline-any cline-yes">8x</span>
101109
<span class="cline-any cline-neutral">&nbsp;</span>
102110
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
103111
&nbsp;
104112
export function isMobile() {
105113
if (navigator.userAgentData) return navigator.userAgentData.mobile
106114
let check = false
107115
;(function (a) {
116+
if (!a) { // Handle cases where 'a' (userAgent/vendor/opera) might be null, undefined, or empty
117+
check = false;
118+
return;
119+
}
108120
if (
109121
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
110122
a,
@@ -124,7 +136,7 @@ <h1><a href="index.html">All files</a> is-mobile.mjs</h1>
124136
<div class='footer quiet pad2 space-top1 center small'>
125137
Code coverage generated by
126138
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
127-
at 2025-06-07T19:45:43.538Z
139+
at 2025-06-08T06:33:00.530Z
128140
</div>
129141
<script src="prettify.js"></script>
130142
<script>

coverage/lcov-report/is-safari.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ <h1><a href="index.html">All files</a> is-safari.mjs</h1>
7979
<div class='footer quiet pad2 space-top1 center small'>
8080
Code coverage generated by
8181
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
82-
at 2025-06-07T19:45:43.538Z
82+
at 2025-06-08T06:33:00.530Z
8383
</div>
8484
<script src="prettify.js"></script>
8585
<script>

coverage/lcov-report/model-name-convert.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ <h1><a href="index.html">All files</a> model-name-convert.mjs</h1>
595595
<div class='footer quiet pad2 space-top1 center small'>
596596
Code coverage generated by
597597
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
598-
at 2025-06-07T19:45:43.538Z
598+
at 2025-06-08T06:33:00.530Z
599599
</div>
600600
<script src="prettify.js"></script>
601601
<script>

coverage/lcov-report/parse-int-with-clamp.mjs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h1><a href="index.html">All files</a> parse-int-with-clamp.mjs</h1>
9797
<div class='footer quiet pad2 space-top1 center small'>
9898
Code coverage generated by
9999
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
100-
at 2025-06-07T19:45:43.538Z
100+
at 2025-06-08T06:33:00.530Z
101101
</div>
102102
<script src="prettify.js"></script>
103103
<script>

0 commit comments

Comments
 (0)