Skip to content

Commit 2c39141

Browse files
committed
Tolerate case when no extensions have been added in a month.
1 parent 42341ca commit 2c39141

File tree

2 files changed

+119
-89
lines changed

2 files changed

+119
-89
lines changed

src/templates/extensions-added-list.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ const ExtensionsAddedListTemplate = (
9898
data: {
9999
allExtension, downloadDataDate,
100100
},
101-
pageContext: { nextMonthTimestamp, previousMonthTimestamp },
101+
pageContext: { nextMonthTimestamp, previousMonthTimestamp, sinceMonth },
102102
location,
103103
}) => {
104+
const monthTimestamp = sinceMonth
104105
const downloadData = downloadDataDate
105106

106107
// Convert the data to the same format as what the other list page uses
@@ -138,10 +139,10 @@ const ExtensionsAddedListTemplate = (
138139
</ul>
139140
</nav>)
140141

141-
const monthTimestamp = extensions[0].metadata.maven.sinceMonth
142142
const now = new Date()
143143
const date = new Date(+monthTimestamp)
144144
const verb = now.getUTCMonth() === date.getUTCMonth() && now.getUTCFullYear() === date.getUTCFullYear() ? "have been" : "were"
145+
const formattedMonth = prettyDate(monthTimestamp)
145146

146147
if (extensions && extensions.length > 0) {
147148

@@ -154,9 +155,6 @@ const ExtensionsAddedListTemplate = (
154155
extensions.sort(extensionComparator)
155156
}
156157

157-
const formattedMonth = prettyDate(monthTimestamp)
158-
159-
160158
const countMessage = `${extensionCount} new extensions ${verb} added this month.`
161159

162160

@@ -191,7 +189,7 @@ const ExtensionsAddedListTemplate = (
191189
} else {
192190
return (
193191
<div className="extensions-list" style={{ display: "flex" }}>
194-
No new extensions {verb} added this month.
192+
No new extensions {verb} added in {formattedMonth}.
195193
{nav}
196194
</div>
197195
)

src/templates/extensions-added-list.test.js

Lines changed: 115 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,134 @@ jest.mock("react-use-query-param-string", () => {
1313
})
1414

1515
describe("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(/April 2020/)).toBeTruthy()
109+
})
110+
111+
it("displays a next and previous links", async () => {
112+
expect(screen.getAllByText(/January 1970/)).toBeTruthy()
113+
expect(screen.getAllByText(/June 1985/)).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(/April 2020/)).toBeTruthy()
106-
})
131+
it("displays a brief message explaining there are no extensions", async () => {
132+
expect(screen.getByText(/No new extensions.*/)).toBeTruthy()
133+
})
107134

108-
it("displays a next and previous links", async () => {
109-
expect(screen.getAllByText(/January 1970/)).toBeTruthy()
110-
expect(screen.getAllByText(/June 1985/)).toBeTruthy()
135+
it("displays some text about when the extensions were released", async () => {
136+
expect(screen.getAllByText(/January 2024/)).toBeTruthy()
137+
})
111138

112-
})
139+
it("displays a next and previous links", async () => {
140+
expect(screen.getAllByText(/January 1970/)).toBeTruthy()
141+
expect(screen.getAllByText(/June 1985/)).toBeTruthy()
113142

143+
})
144+
145+
})
114146
})

0 commit comments

Comments
 (0)