@@ -40,34 +40,43 @@ def onebox_html
4040 stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : "[]" )
4141 end
4242
43- it "includes open status" do
44- expect ( onebox_html ) . to include ( "--gh-status-open" )
43+ it "includes open status and shows created_at date" do
44+ html = onebox_html
45+ expect ( html ) . to include ( "--gh-status-open" )
46+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.open" ) )
47+ expect ( html ) . to include ( 'data-date="2013-07-26"' )
4548 end
4649 end
4750
4851 context "when PR is merged" do
4952 before do
5053 resp = open_pr_response
5154 resp [ "merged" ] = true
55+ resp [ "merged_at" ] = "2024-02-15T10:30:00Z"
5256 stub_request ( :get , api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( resp ) )
53- stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : "[]" )
5457 end
5558
56- it "includes merged status" do
57- expect ( onebox_html ) . to include ( "--gh-status-merged" )
59+ it "includes merged status and shows merged_at date" do
60+ html = onebox_html
61+ expect ( html ) . to include ( "--gh-status-merged" )
62+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.merged" ) )
63+ expect ( html ) . to include ( 'data-date="2024-02-15"' )
5864 end
5965 end
6066
6167 context "when PR is closed" do
6268 before do
6369 resp = open_pr_response
6470 resp [ "state" ] = "closed"
71+ resp [ "closed_at" ] = "2024-03-20T14:45:00Z"
6572 stub_request ( :get , api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( resp ) )
66- stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : "[]" )
6773 end
6874
69- it "includes closed status" do
70- expect ( onebox_html ) . to include ( "--gh-status-closed" )
75+ it "includes closed status and shows closed_at date" do
76+ html = onebox_html
77+ expect ( html ) . to include ( "--gh-status-closed" )
78+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.closed" ) )
79+ expect ( html ) . to include ( 'data-date="2024-03-20"' )
7180 end
7281 end
7382
@@ -76,25 +85,36 @@ def onebox_html
7685 resp = open_pr_response
7786 resp [ "draft" ] = true
7887 stub_request ( :get , api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( resp ) )
79- stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : "[]" )
8088 end
8189
82- it "includes draft status" do
83- expect ( onebox_html ) . to include ( "--gh-status-draft" )
90+ it "includes draft status and shows created_at date" do
91+ html = onebox_html
92+ expect ( html ) . to include ( "--gh-status-draft" )
93+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.draft" ) )
94+ expect ( html ) . to include ( 'data-date="2013-07-26"' )
8495 end
8596 end
8697
8798 context "when PR is approved" do
8899 before do
89100 stub_request ( :get , api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( open_pr_response ) )
90101 reviews = [
91- { "user" => { "id" => 1 } , "state" => "APPROVED" , "submitted_at" => Time . now . iso8601 } ,
102+ {
103+ "user" => {
104+ "id" => 1 ,
105+ } ,
106+ "state" => "APPROVED" ,
107+ "submitted_at" => "2024-04-10T09:15:00Z" ,
108+ } ,
92109 ]
93110 stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( reviews ) )
94111 end
95112
96- it "includes approved status" do
97- expect ( onebox_html ) . to include ( "--gh-status-approved" )
113+ it "includes approved status and shows review submitted_at date" do
114+ html = onebox_html
115+ expect ( html ) . to include ( "--gh-status-approved" )
116+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.approved" ) )
117+ expect ( html ) . to include ( 'data-date="2024-04-10"' )
98118 end
99119 end
100120
@@ -107,36 +127,48 @@ def onebox_html
107127 "id" => 1 ,
108128 } ,
109129 "state" => "CHANGES_REQUESTED" ,
110- "submitted_at" => Time . now . iso8601 ,
130+ "submitted_at" => "2024-05-05T16:20:00Z" ,
111131 } ,
112132 ]
113133 stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( reviews ) )
114134 end
115135
116- it "includes changes_requested status" do
117- expect ( onebox_html ) . to include ( "--gh-status-changes_requested" )
136+ it "includes changes_requested status and shows review submitted_at date" do
137+ html = onebox_html
138+ expect ( html ) . to include ( "--gh-status-changes_requested" )
139+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.changes_requested" ) )
140+ expect ( html ) . to include ( 'data-date="2024-05-05"' )
118141 end
119142 end
120143
121144 context "when PR has both approval and changes requested from different reviewers" do
122145 before do
123146 stub_request ( :get , api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( open_pr_response ) )
124147 reviews = [
125- { "user" => { "id" => 1 } , "state" => "APPROVED" , "submitted_at" => Time . now . iso8601 } ,
148+ {
149+ "user" => {
150+ "id" => 1 ,
151+ } ,
152+ "state" => "APPROVED" ,
153+ "submitted_at" => "2024-05-30T12:00:00Z" ,
154+ } ,
126155 {
127156 "user" => {
128157 "id" => 2 ,
129158 } ,
130159 "state" => "CHANGES_REQUESTED" ,
131- "submitted_at" => Time . now . iso8601 ,
160+ "submitted_at" => "2024-06-01T12:00:00Z" ,
132161 } ,
133162 ]
134163 stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( reviews ) )
135164 end
136165
137- it "shows changes_requested (takes priority over approved)" do
138- expect ( onebox_html ) . to include ( "--gh-status-changes_requested" )
139- expect ( onebox_html ) . not_to include ( "--gh-status-approved" )
166+ it "shows changes_requested status with its date (takes priority over approved)" do
167+ html = onebox_html
168+ expect ( html ) . to include ( "--gh-status-changes_requested" )
169+ expect ( html ) . not_to include ( "--gh-status-approved" )
170+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.changes_requested" ) )
171+ expect ( html ) . to include ( 'data-date="2024-06-01"' )
140172 end
141173 end
142174
@@ -162,9 +194,12 @@ def onebox_html
162194 stub_request ( :get , reviews_api_uri ) . to_return ( status : 200 , body : MultiJson . dump ( reviews ) )
163195 end
164196
165- it "shows approved (latest review wins)" do
166- expect ( onebox_html ) . to include ( "--gh-status-approved" )
167- expect ( onebox_html ) . not_to include ( "--gh-status-changes_requested" )
197+ it "shows approved status with latest review date (latest review wins)" do
198+ html = onebox_html
199+ expect ( html ) . to include ( "--gh-status-approved" )
200+ expect ( html ) . not_to include ( "--gh-status-changes_requested" )
201+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.approved" ) )
202+ expect ( html ) . to include ( 'data-date="2024-01-02"' )
168203 end
169204 end
170205
@@ -174,8 +209,11 @@ def onebox_html
174209 stub_request ( :get , reviews_api_uri ) . to_return ( status : 500 , body : "error" )
175210 end
176211
177- it "falls back gracefully without status" do
178- expect ( onebox_html ) . not_to include ( "--gh-status-" )
212+ it "falls back gracefully without status class and shows opened with created_at date" do
213+ html = onebox_html
214+ expect ( html ) . not_to include ( "--gh-status-" )
215+ expect ( html ) . to include ( I18n . t ( "onebox.github.status_date.open" ) )
216+ expect ( html ) . to include ( 'data-date="2013-07-26"' )
179217 end
180218 end
181219 end
0 commit comments