Skip to content

Commit 373bcb5

Browse files
committed
Monkey patch inline svg for fixtures
When we added the aria attributes for dark mode svg, we introduced randomness into the ids generated by the helper. We monkey patch inline svg only in the context of the fixtures here to prevent version control churn in the generated fixture html.
1 parent cffa889 commit 373bcb5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/javascript/test/fixtures/views/darkmode/switch.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"
1818
aria-label="Change Color Scheme"
1919
role="button">
20-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" role="img" aria-labelledby="ag3w997dw5cq5gn7nuv7hwxkstr21ubv aorckhcfjwh1g3r379o4h8u2k2ofavda" class="hidden w-5 h-5" data-darkmode-target="darkIcon"><title id="ag3w997dw5cq5gn7nuv7hwxkstr21ubv">Dark mode</title><desc id="aorckhcfjwh1g3r379o4h8u2k2ofavda">Dark mode for the site is enabled</desc>
20+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" role="img" aria-labelledby="a23noh8smnaw6vmjcvjhttpgt5q0qbbs alplzuljme7224cfcwt926yoeqa47ocl" class="hidden w-5 h-5" data-darkmode-target="darkIcon"><title id="a23noh8smnaw6vmjcvjhttpgt5q0qbbs">Dark mode</title><desc id="alplzuljme7224cfcwt926yoeqa47ocl">Dark mode for the site is enabled</desc>
2121
<path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path>
2222
</svg>
2323

24-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" role="img" aria-labelledby="arm0rifmxzbd438oc2v90yj3bl4nbjcj acls4177hemyyhyti9k9ao8g7098fh8d" class="hidden w-5 h-5" data-darkmode-target="lightIcon"><title id="arm0rifmxzbd438oc2v90yj3bl4nbjcj">Light mode</title><desc id="acls4177hemyyhyti9k9ao8g7098fh8d">Light mode for the site is enabled</desc>
24+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" role="img" aria-labelledby="aa5iq8m2a0fc9hgmq0wyw6mvtcfy26t aje69lwf7xl07e68qdo0vi97z71e8sto" class="hidden w-5 h-5" data-darkmode-target="lightIcon"><title id="aa5iq8m2a0fc9hgmq0wyw6mvtcfy26t">Light mode</title><desc id="aje69lwf7xl07e68qdo0vi97z71e8sto">Light mode for the site is enabled</desc>
2525
<path d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" fill-rule="evenodd" clip-rule="evenodd">
2626
</path>
2727
</svg>
2828

29-
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1200 1200" fill="currentColor" role="img" aria-labelledby="a3pr40o3id4sof9ip7s189yeyq9eo0fh ace8l7z40jy3u7f144h70h9rl8byo5ko" class="hidden w-5 h-5" data-darkmode-target="systemIcon"><title id="a3pr40o3id4sof9ip7s189yeyq9eo0fh">System mode</title><desc id="ace8l7z40jy3u7f144h70h9rl8byo5ko">System mode for the site is enabled</desc>
29+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1200 1200" fill="currentColor" role="img" aria-labelledby="allbgiij3zaiv8cms5a26e1471exjjd4 a76ugl234obpt3l141jftf1tbxp4ss25" class="hidden w-5 h-5" data-darkmode-target="systemIcon"><title id="allbgiij3zaiv8cms5a26e1471exjjd4">System mode</title><desc id="a76ugl234obpt3l141jftf1tbxp4ss25">System mode for the site is enabled</desc>
3030
<g>
3131
<path d="m675 1012.5c-9.9453 0-19.484 3.9492-26.516 10.984-7.0352 7.0312-10.984 16.57-10.984 26.516v37.5c0 13.398 7.1484 25.777 18.75 32.477 11.602 6.6992 25.898 6.6992 37.5 0 11.602-6.6992 18.75-19.078 18.75-32.477v-37.5c0-9.9453-3.9492-19.484-10.984-26.516-7.0312-7.0352-16.57-10.984-26.516-10.984z"></path>
3232
<path d="m330.38 891.75-26.625 26.625c-7.9375 6.7969-12.676 16.594-13.078 27.035-0.40625 10.441 3.5664 20.578 10.953 27.965s17.523 11.359 27.965 10.953c10.441-0.40234 20.238-5.1406 27.035-13.078l26.625-26.625c8.2656-9.6523 11.082-22.84 7.4766-35.027-3.6016-12.188-13.137-21.723-25.324-25.324-12.188-3.6055-25.375-0.78906-35.027 7.4766z"></path>

lib/tasks/fixtures/html.rake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
namespace :fixtures do
22
task html: :environment do
3+
if Rails.env.local?
4+
class InlineSvg::IdGenerator::Randomness
5+
class << self
6+
prepend InlineSvgIdGeneratorRandomnessOverrideForFixtures
7+
end
8+
end
9+
end
10+
311
File.write(Rails.root.join("app", "javascript", "test", "fixtures", "views", "darkmode", "switch.html"), ApplicationController.render(partial: "darkmode/switch"))
412
end
513
end
14+
15+
module InlineSvgIdGeneratorRandomnessOverrideForFixtures
16+
def call
17+
"non-random-for-fixtures"
18+
end
19+
end

0 commit comments

Comments
 (0)