@@ -106,21 +106,70 @@ describe("isPullRequestOpen", () => {
106106 document . body . innerHTML = "" ;
107107 } ) ;
108108
109- it ( "should get opened pull request status " , ( ) => {
109+ it ( "should detect open PR via legacy span.State (fixture) " , ( ) => {
110110 injectFixtureInDOM ( "github_pr_opened" ) ;
111111
112112 const status = isPullRequestOpen ( ) ;
113113
114114 expect ( status ) . toBe ( true ) ;
115115 } ) ;
116116
117- it ( "should get opened pull request status " , ( ) => {
117+ it ( "should detect merged PR via legacy span.State (fixture) " , ( ) => {
118118 injectFixtureInDOM ( "github_pr_merged" ) ;
119119
120120 const status = isPullRequestOpen ( ) ;
121121
122122 expect ( status ) . toBe ( false ) ;
123123 } ) ;
124+
125+ it ( "should detect open PR via data-status=pullOpened attribute" , ( ) => {
126+ document . body . innerHTML = '<span data-status="pullOpened">Open</span>' ;
127+
128+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
129+ } ) ;
130+
131+ it ( "should detect draft PR via data-status=draft attribute" , ( ) => {
132+ document . body . innerHTML = '<span data-status="draft">Draft</span>' ;
133+
134+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
135+ } ) ;
136+
137+ it ( "should prefer data-status over legacy span.State" , ( ) => {
138+ document . body . innerHTML =
139+ '<span data-status="pullOpened">Open</span>' +
140+ '<span class="State" title="Status: Closed">Closed</span>' ;
141+
142+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
143+ } ) ;
144+
145+ it ( "should detect closed PR via legacy span.State when no data-status" , ( ) => {
146+ document . body . innerHTML =
147+ '<span class="State" title="Status: Closed">Closed</span>' ;
148+
149+ expect ( isPullRequestOpen ( ) ) . toBe ( false ) ;
150+ } ) ;
151+
152+ it ( "should assume open when no status element is found" , ( ) => {
153+ document . body . innerHTML = "<div>No status here</div>" ;
154+
155+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
156+ } ) ;
157+
158+ it ( "should assume open when legacy span.State has no parseable title" , ( ) => {
159+ const consoleSpy = jest
160+ . spyOn ( console , "warn" )
161+ . mockImplementation ( ( ) => { } ) ;
162+
163+ document . body . innerHTML =
164+ '<span class="State" title="Malformed">Badge</span>' ;
165+
166+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
167+ expect ( consoleSpy ) . toHaveBeenCalledWith (
168+ "Can't find pull request status" ,
169+ ) ;
170+
171+ consoleSpy . mockRestore ( ) ;
172+ } ) ;
124173} ) ;
125174
126175describe ( "isMergifyEnabledOnTheRepo caching behavior" , ( ) => {
0 commit comments