Skip to content

Commit dfd6afc

Browse files
tyb-talksjancernik
authored andcommitted
DEV: raise error on deprecated icon name caught on JS in system and qunit tests (discourse#30942)
This PR raises an error on any deprecated icon names being converted by `icon-library.js`, which will result in any deprecated icons introduced in JS-land to fail qunit/system tests. We'll do the same for `svg_sprite.rb` once I've resolved pre-existing deprecated icons in core/plugins that's caught by the same exception logic.
1 parent fe5c036 commit dfd6afc

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

app/assets/javascripts/discourse/app/lib/icon-library.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { h } from "virtual-dom";
22
import attributeHook from "discourse/lib/attribute-hook";
33
import deprecated from "discourse/lib/deprecated";
4-
import { isDevelopment } from "discourse/lib/environment";
4+
import {
5+
isDevelopment,
6+
isRailsTesting,
7+
isTesting,
8+
} from "discourse/lib/environment";
59
import escape from "discourse/lib/escape";
610
import { i18n } from "discourse-i18n";
711

@@ -147,6 +151,7 @@ function handleDeprecatedIcon(id) {
147151
{
148152
id: "discourse.fontawesome-6-upgrade",
149153
url: "https://meta.discourse.org/t/325349",
154+
raiseError: isTesting() || isRailsTesting(),
150155
}
151156
);
152157
}
@@ -189,12 +194,12 @@ registerIconRenderer({
189194
}
190195
html += ` xmlns="${SVG_NAMESPACE}"><use href="#${id}" /></svg>`;
191196
if (params.label) {
192-
html += `<span class='sr-only'>${escape(params.label)}</span>`;
197+
html += `<span class="sr-only">${escape(params.label)}</span>`;
193198
}
194199
if (params.title) {
195-
html = `<span class="svg-icon-title" title='${escape(
200+
html = `<span class="svg-icon-title" title="${escape(
196201
i18n(params.title)
197-
)}'>${html}</span>`;
202+
)}">${html}</span>`;
198203
}
199204

200205
if (params.translatedtitle) {
@@ -207,9 +212,9 @@ registerIconRenderer({
207212
}
208213

209214
if (params.translatedTitle) {
210-
html = `<span class="svg-icon-title" title='${escape(
215+
html = `<span class="svg-icon-title" title="${escape(
211216
params.translatedTitle
212-
)}'>${html}</span>`;
217+
)}">${html}</span>`;
213218
}
214219
return html;
215220
},

app/assets/javascripts/discourse/tests/unit/lib/icon-library-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
iconHTML,
77
iconNode,
88
} from "discourse/lib/icon-library";
9+
import {
10+
disableRaiseOnDeprecation,
11+
enableRaiseOnDeprecation,
12+
} from "discourse/tests/helpers/raise-on-deprecation";
913

1014
module("Unit | Utility | icon-library", function (hooks) {
1115
setupTest(hooks);
@@ -67,4 +71,24 @@ module("Unit | Utility | icon-library", function (hooks) {
6771
);
6872
});
6973
});
74+
75+
test("fa5 remaps throws error", function (assert) {
76+
disableRaiseOnDeprecation();
77+
assert.throws(
78+
() => {
79+
iconHTML("adjust");
80+
},
81+
/Deprecation notice: The icon name "adjust" has been updated to "circle-half-stroke".*\[deprecation id: discourse\.fontawesome-6-upgrade\]/,
82+
"throws an error if icon name is deprecated"
83+
);
84+
85+
assert.throws(
86+
() => {
87+
iconHTML("far-dot-circle");
88+
},
89+
/Deprecation notice: The icon name "far-dot-circle" has been updated to "far-circle-dot".*\[deprecation id: discourse\.fontawesome-6-upgrade\]/,
90+
"throws an error if icon name is deprecated"
91+
);
92+
enableRaiseOnDeprecation();
93+
});
7094
});

db/fixtures/006_badges.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
Badge.seed do |b|
174174
b.id = Badge::FirstShare
175175
b.name = "First Share"
176-
b.default_icon = "share-alt"
176+
b.default_icon = "share-nodes"
177177
b.badge_type_id = BadgeType::Bronze
178178
b.multiple_grant = false
179179
b.target_posts = true
@@ -193,7 +193,7 @@
193193
Badge.seed do |b|
194194
b.id = id
195195
b.name = name
196-
b.default_icon = "share-alt"
196+
b.default_icon = "share-nodes"
197197
b.badge_type_id = level
198198
b.multiple_grant = true
199199
b.target_posts = true
@@ -402,7 +402,7 @@
402402
Badge.seed do |b|
403403
b.id = Badge::FirstEmoji
404404
b.name = "First Emoji"
405-
b.default_icon = "smile"
405+
b.default_icon = "face-smile"
406406
b.badge_type_id = BadgeType::Bronze
407407
b.multiple_grant = false
408408
b.target_posts = true

0 commit comments

Comments
 (0)