@@ -106,21 +106,84 @@ 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 detect closed PR via data-status=pullClosed attribute" , ( ) => {
138+ document . body . innerHTML =
139+ '<span data-status="pullClosed">Closed</span>' ;
140+
141+ expect ( isPullRequestOpen ( ) ) . toBe ( false ) ;
142+ } ) ;
143+
144+ it ( "should detect merged PR via data-status=pullMerged attribute" , ( ) => {
145+ document . body . innerHTML =
146+ '<span data-status="pullMerged">Merged</span>' ;
147+
148+ expect ( isPullRequestOpen ( ) ) . toBe ( false ) ;
149+ } ) ;
150+
151+ it ( "should prefer data-status over legacy span.State" , ( ) => {
152+ document . body . innerHTML =
153+ '<span data-status="pullOpened">Open</span>' +
154+ '<span class="State" title="Status: Closed">Closed</span>' ;
155+
156+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
157+ } ) ;
158+
159+ it ( "should detect closed PR via legacy span.State when no data-status" , ( ) => {
160+ document . body . innerHTML =
161+ '<span class="State" title="Status: Closed">Closed</span>' ;
162+
163+ expect ( isPullRequestOpen ( ) ) . toBe ( false ) ;
164+ } ) ;
165+
166+ it ( "should assume open when no status element is found" , ( ) => {
167+ document . body . innerHTML = "<div>No status here</div>" ;
168+
169+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
170+ } ) ;
171+
172+ it ( "should assume open when legacy span.State has no parseable title" , ( ) => {
173+ const consoleSpy = jest
174+ . spyOn ( console , "warn" )
175+ . mockImplementation ( ( ) => { } ) ;
176+
177+ document . body . innerHTML =
178+ '<span class="State" title="Malformed">Badge</span>' ;
179+
180+ expect ( isPullRequestOpen ( ) ) . toBe ( true ) ;
181+ expect ( consoleSpy ) . toHaveBeenCalledWith (
182+ "Can't find pull request status" ,
183+ ) ;
184+
185+ consoleSpy . mockRestore ( ) ;
186+ } ) ;
124187} ) ;
125188
126189describe ( "isMergifyEnabledOnTheRepo caching behavior" , ( ) => {
0 commit comments