Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove autoplay #87

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,29 @@ jobs:
DATABASE_HOST: localhost

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 1

- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: 119.0.6045.105

- name: List Chrome
run: apt list --installed | grep chrome

- name: Remove Chrome
run: sudo apt remove google-chrome-stable

- uses: browser-actions/setup-chrome@v1
with:
chrome-version: 119.0.6045.105

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true

- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: 119.0.6045.105

- uses: actions/setup-node@master
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down
4 changes: 3 additions & 1 deletion app/views/decidim/music/_play.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row column">
<p><%= t("audio.title", scope: "decidim.participatory_processes.participatory_processes.show") %></p>
<audio controls autoplay preload loop id="audio" style="width: 100%;">
<audio controls preload id="audio" style="width: 100%;">
<source src="/music/GETXO_DEMO_5.mp3" type="audio/mpeg">
<%= t("audio.audio_supporting", scope: "decidim.participatory_processes.participatory_processes.show") %>
</audio>
Expand All @@ -10,6 +10,7 @@
</p>
</div>

<% if ENV.fetch("GETXO_AUTOPLAY", nil).to_s.downcase == "true" %>
<script>
const audioElement = document.getElementById("audio");

Expand All @@ -22,3 +23,4 @@

document.addEventListener("click", handleUserGesture);
</script>
<% end %>
21 changes: 17 additions & 4 deletions spec/system/music_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
let(:organization) { create(:organization) }
let!(:process_old) { create(:participatory_process, :active, :promoted, organization: organization, created_at: "31.12.2022".to_date) }
let!(:process_new) { create(:participatory_process, :active, :promoted, organization: organization, created_at: "01.01.2023".to_date) }
let(:autoplay) { "true" }

before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("GETXO_AUTOPLAY", nil).and_return(autoplay)
switch_to_host(organization.host)
visit decidim_participatory_processes.participatory_processes_path
end
Expand All @@ -28,11 +31,21 @@
find("h2.card__title", text: translated(process_new.title)).click
end

audio_element = find("audio#audio")
find("body").click
expect(page.execute_script("return document.getElementById('audio').paused")).to be(false)
end
end

context "when autoplay is disabled" do
let(:autoplay) { "false" }

it "doesn't play the music when the page is loaded" do
within first("#highlighted-processes") do
find("h2.card__title", text: translated(process_new.title)).click
end

sleep 2
expect(audio_element[:paused]).to eq("false")
expect(audio_element[:loop]).to eq("true")
find("body").click
expect(page.execute_script("return document.getElementById('audio').paused")).to be(true)
end
end
end
Expand Down
Loading