@@ -13,102 +13,134 @@ jest.mock("react-use-query-param-string", () => {
1313} )
1414
1515describe ( "extensions added page" , ( ) => {
16- const category = "jewellery"
17- const otherCategory = "snails"
18-
19- const ruby = {
20- name : "JRuby" ,
21- id : "jruby" ,
22- sortableName : "ruby" ,
23- slug : "jruby-slug" ,
24- metadata : { categories : [ category ] , } ,
25- platforms : [ "bottom of the garden" ] ,
26- }
27- const diamond = {
28- name : "JDiamond" ,
29- id : "jdiamond" ,
30- sortableName : "diamond" ,
31- slug : "jdiamond-slug" ,
32- metadata : { categories : [ category ] } ,
33- platforms : [ "a mine" ] ,
34- }
3516
36- const molluscs = {
37- name : "Molluscs" ,
38- id : "molluscs" ,
39- sortableName : "mollusc" ,
40- slug : "molluscs-slug" ,
41- metadata : { categories : [ otherCategory ] } ,
42- platforms : [ "bottom of the garden" ] ,
43- }
17+ describe ( "when there are are extensions in that time period" , ( ) => {
4418
45- const obsolete = {
46- name : "Obsolete" ,
47- id : "really-old" ,
48- sortableName : "old" ,
49- slug : "old-slug" ,
50- metadata : { categories : [ otherCategory ] } ,
51- platforms : [ "bottom of the garden" ] ,
52- duplicates : [ { relationship : "newer" , groupId : "whatever" } ] ,
53- isSuperseded : true ,
54- }
19+ const category = "jewellery"
20+ const otherCategory = "snails"
5521
56- const maybeObsolete = {
57- name : "Maybebsolete" ,
58- id : "maybe-old" ,
59- artifact : "maybe-old-or-not" ,
60- sortableName : "maybe-old" ,
61- slug : "ambiguous-slug" ,
62- metadata : { categories : [ otherCategory ] } ,
63- platforms : [ "bottom of the garden" ] ,
64- duplicates : [ { relationship : "different" , groupId : "whatever" } ] ,
65- }
22+ const ruby = {
23+ name : "JRuby" ,
24+ id : "jruby" ,
25+ sortableName : "ruby" ,
26+ slug : "jruby-slug" ,
27+ metadata : { categories : [ category ] , } ,
28+ platforms : [ "bottom of the garden" ] ,
29+ }
30+ const diamond = {
31+ name : "JDiamond" ,
32+ id : "jdiamond" ,
33+ sortableName : "diamond" ,
34+ slug : "jdiamond-slug" ,
35+ metadata : { categories : [ category ] } ,
36+ platforms : [ "a mine" ] ,
37+ }
6638
67- const extensions = [ ruby , diamond , molluscs , obsolete , maybeObsolete ]
68- const graphQledExtensions = extensions . map ( e => {
69- e . metadata = { maven : { sinceMonth : "1585720800000" } }
70- return {
71- node : e
39+ const molluscs = {
40+ name : "Molluscs" ,
41+ id : "molluscs" ,
42+ sortableName : "mollusc" ,
43+ slug : "molluscs-slug" ,
44+ metadata : { categories : [ otherCategory ] } ,
45+ platforms : [ "bottom of the garden" ] ,
46+ }
47+
48+ const obsolete = {
49+ name : "Obsolete" ,
50+ id : "really-old" ,
51+ sortableName : "old" ,
52+ slug : "old-slug" ,
53+ metadata : { categories : [ otherCategory ] } ,
54+ platforms : [ "bottom of the garden" ] ,
55+ duplicates : [ { relationship : "newer" , groupId : "whatever" } ] ,
56+ isSuperseded : true ,
7257 }
73- } )
7458
75- beforeEach ( async ( ) => {
59+ const maybeObsolete = {
60+ name : "Maybebsolete" ,
61+ id : "maybe-old" ,
62+ artifact : "maybe-old-or-not" ,
63+ sortableName : "maybe-old" ,
64+ slug : "ambiguous-slug" ,
65+ metadata : { categories : [ otherCategory ] } ,
66+ platforms : [ "bottom of the garden" ] ,
67+ duplicates : [ { relationship : "different" , groupId : "whatever" } ] ,
68+ }
7669
77- render ( < ExtensionsAddedListTemplate data = { {
78- allExtension : { edges : graphQledExtensions }
79- } }
80- pageContext = { {
81- nextMonthTimestamp : "12" ,
82- previousMonthTimestamp : "487592268000"
83- } }
84- location = { "extensions-added-some-date" } /> )
70+ const extensions = [ ruby , diamond , molluscs , obsolete , maybeObsolete ]
71+ const graphQledExtensions = extensions . map ( e => {
72+ e . metadata = { maven : { sinceMonth : "1585720800000" } }
73+ return {
74+ node : e
75+ }
76+ } )
77+
78+ beforeEach ( async ( ) => {
79+ render ( < ExtensionsAddedListTemplate data = { {
80+ allExtension : { edges : graphQledExtensions }
81+ } }
82+ pageContext = { {
83+ nextMonthTimestamp : "12" ,
84+ previousMonthTimestamp : "487592268000" ,
85+ sinceMonth : "1585720800000"
86+ } }
87+ location = { "extensions-added-some-date" } /> )
88+ } )
89+
90+ it ( "renders the extension name" , ( ) => {
91+ expect ( screen . getByText ( extensions [ 0 ] . name ) ) . toBeTruthy ( )
92+ } )
93+
94+ it ( "renders the correct link" , ( ) => {
95+ const links = screen . getAllByRole ( "link" )
96+ const link = links [ links . length - 6 ] // Look at the last one that's not in the footer, because the top of the page will have a menu and the bottom will have footers - this is also testing the sorting
97+ expect ( link ) . toBeTruthy ( )
98+ // Hardcoding the host is a bit risky but this should always be true in test environment
99+ expect ( link . href ) . toBe ( "http://localhost/ambiguous-slug" )
100+ } )
101+
102+ it ( "displays a brief message about how many extensions there are" , async ( ) => {
103+ const num = extensions . length
104+ expect ( screen . getByText ( new RegExp ( `${ num - 1 } new extensions were added` ) ) ) . toBeTruthy ( )
105+ } )
106+
107+ it ( "displays some text about when the extensions were released" , async ( ) => {
108+ expect ( screen . getAllByText ( / A p r i l 2 0 2 0 / ) ) . toBeTruthy ( )
109+ } )
110+
111+ it ( "displays a next and previous links" , async ( ) => {
112+ expect ( screen . getAllByText ( / J a n u a r y 1 9 7 0 / ) ) . toBeTruthy ( )
113+ expect ( screen . getAllByText ( / J u n e 1 9 8 5 / ) ) . toBeTruthy ( )
114+
115+ } )
85116 } )
86117
87- it ( "renders the extension name" , ( ) => {
88- expect ( screen . getByText ( extensions [ 0 ] . name ) ) . toBeTruthy ( )
89- } )
118+ describe ( "when there are no extensions in the time period" , ( ) => {
90119
91- it ( "renders the correct link" , ( ) => {
92- const links = screen . getAllByRole ( "link" )
93- const link = links [ links . length - 6 ] // Look at the last one that's not in the footer, because the top of the page will have a menu and the bottom will have footers - this is also testing the sorting
94- expect ( link ) . toBeTruthy ( )
95- // Hardcoding the host is a bit risky but this should always be true in test environment
96- expect ( link . href ) . toBe ( "http://localhost/ambiguous-slug" )
97- } )
120+ beforeEach ( async ( ) => {
98121
99- it ( "displays a brief message about how many extensions there are" , async ( ) => {
100- const num = extensions . length
101- expect ( screen . getByText ( new RegExp ( `${ num - 1 } new extensions were added` ) ) ) . toBeTruthy ( )
102- } )
122+ render ( < ExtensionsAddedListTemplate data = { { allExtension : { edges : [ ] } } }
123+ pageContext = { {
124+ nextMonthTimestamp : "12" ,
125+ sinceMonth : "1705250589000" ,
126+ previousMonthTimestamp : "487592268000"
127+ } }
128+ location = { "extensions-added-some-date" } /> )
129+ } )
103130
104- it ( "displays some text about when the extensions were released " , async ( ) => {
105- expect ( screen . getAllByText ( / A p r i l 2 0 2 0 / ) ) . toBeTruthy ( )
106- } )
131+ it ( "displays a brief message explaining there are no extensions " , async ( ) => {
132+ expect ( screen . getByText ( / N o n e w e x t e n s i o n s . * / ) ) . toBeTruthy ( )
133+ } )
107134
108- it ( "displays a next and previous links " , async ( ) => {
109- expect ( screen . getAllByText ( / J a n u a r y 1 9 7 0 / ) ) . toBeTruthy ( )
110- expect ( screen . getAllByText ( / J u n e 1 9 8 5 / ) ) . toBeTruthy ( )
135+ it ( "displays some text about when the extensions were released " , async ( ) => {
136+ expect ( screen . getAllByText ( / J a n u a r y 2 0 2 4 / ) ) . toBeTruthy ( )
137+ } )
111138
112- } )
139+ it ( "displays a next and previous links" , async ( ) => {
140+ expect ( screen . getAllByText ( / J a n u a r y 1 9 7 0 / ) ) . toBeTruthy ( )
141+ expect ( screen . getAllByText ( / J u n e 1 9 8 5 / ) ) . toBeTruthy ( )
113142
143+ } )
144+
145+ } )
114146} )
0 commit comments