33 */
44
55import { describe , it , expect , vi , beforeEach } from 'vitest' ;
6- import { ISSUE_URL_PATTERN } from './dismiss.js' ;
7-
8- describe ( 'ISSUE_URL_PATTERN' , ( ) => {
9- it . each ( [
10- [ 'https://github.com/owner/repo/issues/123' , 'standard URL' ] ,
11- [ 'https://github.com/my-org/my-repo/issues/1' , 'hyphenated names' ] ,
12- [ 'https://github.com/owner/repo.js/issues/42' , 'dotted repo name' ] ,
13- [ 'https://github.com/my_org/my_repo/issues/7' , 'underscored names' ] ,
14- [ 'https://github.com/owner/repo/issues/99999' , 'large issue number' ] ,
15- ] ) ( 'should match %s (%s)' , ( url ) => {
16- expect ( ISSUE_URL_PATTERN . test ( url ) ) . toBe ( true ) ;
17- } ) ;
18-
19- it . each ( [
20- [ 'https://github.com/owner/repo/pull/123' , 'PR URL' ] ,
21- [ 'https://gitlab.com/owner/repo/issues/1' , 'non-GitHub host' ] ,
22- [ 'http://github.com/owner/repo/issues/1' , 'HTTP (non-HTTPS)' ] ,
23- [ 'https://github.com/owner/repo/issues/123/' , 'trailing slash' ] ,
24- [ 'https://github.com/owner/repo/issues/123?q=test' , 'query parameters' ] ,
25- [ 'https://github.com/owner/repo/issues/123#comment' , 'fragment identifier' ] ,
26- [ 'https://github.com/owner/repo/issues/' , 'missing issue number' ] ,
27- [ 'https://github.com/owner/repo' , 'bare repo URL' ] ,
28- [ '' , 'empty string' ] ,
29- [ 'https://github.com/owner/repo/issues/123/timeline' , 'extra path segments' ] ,
30- ] ) ( 'should reject %s (%s)' , ( url ) => {
31- expect ( ISSUE_URL_PATTERN . test ( url ) ) . toBe ( false ) ;
32- } ) ;
33- } ) ;
6+ // Pattern tests are in validation.test.ts (canonical home for URL patterns)
347
358// Mock getStateManager for command-level tests
369vi . mock ( '../core/index.js' , ( ) => ( {
@@ -43,6 +16,7 @@ import { runDismiss, runUndismiss } from './dismiss.js';
4316const mockGetStateManager = vi . mocked ( getStateManager ) ;
4417
4518const TEST_ISSUE_URL = 'https://github.com/owner/repo/issues/1' ;
19+ const TEST_PR_URL = 'https://github.com/owner/repo/pull/42' ;
4620
4721describe ( 'runDismiss' , ( ) => {
4822 const mockSave = vi . fn ( ) ;
@@ -58,16 +32,25 @@ describe('runDismiss', () => {
5832
5933 it ( 'should dismiss an issue and save state' , async ( ) => {
6034 mockDismissIssue . mockReturnValue ( true ) ;
61- const result = await runDismiss ( { issueUrl : TEST_ISSUE_URL } ) ;
35+ const result = await runDismiss ( { url : TEST_ISSUE_URL } ) ;
6236
6337 expect ( mockDismissIssue ) . toHaveBeenCalledWith ( TEST_ISSUE_URL , expect . any ( String ) ) ;
6438 expect ( mockSave ) . toHaveBeenCalled ( ) ;
6539 expect ( result ) . toEqual ( { dismissed : true , url : TEST_ISSUE_URL } ) ;
6640 } ) ;
6741
42+ it ( 'should dismiss a PR URL and save state (#416)' , async ( ) => {
43+ mockDismissIssue . mockReturnValue ( true ) ;
44+ const result = await runDismiss ( { url : TEST_PR_URL } ) ;
45+
46+ expect ( mockDismissIssue ) . toHaveBeenCalledWith ( TEST_PR_URL , expect . any ( String ) ) ;
47+ expect ( mockSave ) . toHaveBeenCalled ( ) ;
48+ expect ( result ) . toEqual ( { dismissed : true , url : TEST_PR_URL } ) ;
49+ } ) ;
50+
6851 it ( 'should not save state when issue is already dismissed' , async ( ) => {
6952 mockDismissIssue . mockReturnValue ( false ) ;
70- const result = await runDismiss ( { issueUrl : TEST_ISSUE_URL } ) ;
53+ const result = await runDismiss ( { url : TEST_ISSUE_URL } ) ;
7154
7255 expect ( mockSave ) . not . toHaveBeenCalled ( ) ;
7356 expect ( result ) . toEqual ( { dismissed : false , url : TEST_ISSUE_URL } ) ;
@@ -88,16 +71,25 @@ describe('runUndismiss', () => {
8871
8972 it ( 'should undismiss an issue and save state' , async ( ) => {
9073 mockUndismissIssue . mockReturnValue ( true ) ;
91- const result = await runUndismiss ( { issueUrl : TEST_ISSUE_URL } ) ;
74+ const result = await runUndismiss ( { url : TEST_ISSUE_URL } ) ;
9275
9376 expect ( mockUndismissIssue ) . toHaveBeenCalledWith ( TEST_ISSUE_URL ) ;
9477 expect ( mockSave ) . toHaveBeenCalled ( ) ;
9578 expect ( result ) . toEqual ( { undismissed : true , url : TEST_ISSUE_URL } ) ;
9679 } ) ;
9780
81+ it ( 'should undismiss a PR URL and save state (#416)' , async ( ) => {
82+ mockUndismissIssue . mockReturnValue ( true ) ;
83+ const result = await runUndismiss ( { url : TEST_PR_URL } ) ;
84+
85+ expect ( mockUndismissIssue ) . toHaveBeenCalledWith ( TEST_PR_URL ) ;
86+ expect ( mockSave ) . toHaveBeenCalled ( ) ;
87+ expect ( result ) . toEqual ( { undismissed : true , url : TEST_PR_URL } ) ;
88+ } ) ;
89+
9890 it ( 'should not save state when issue was not dismissed' , async ( ) => {
9991 mockUndismissIssue . mockReturnValue ( false ) ;
100- const result = await runUndismiss ( { issueUrl : TEST_ISSUE_URL } ) ;
92+ const result = await runUndismiss ( { url : TEST_ISSUE_URL } ) ;
10193
10294 expect ( mockSave ) . not . toHaveBeenCalled ( ) ;
10395 expect ( result ) . toEqual ( { undismissed : false , url : TEST_ISSUE_URL } ) ;
0 commit comments