-<% end %>
-
<%= csrf_meta_tags %>
diff --git a/app/views/admin/shared/_destroy_confirmation_modal.html.erb b/app/views/admin/shared/_destroy_confirmation_modal.html.erb
new file mode 100644
index 000000000..e2813e1a8
--- /dev/null
+++ b/app/views/admin/shared/_destroy_confirmation_modal.html.erb
@@ -0,0 +1,33 @@
+
+
+
+
+
To confirm this update, type in the sentence:
+ My username is @<%= current_user.username %> and this action is 100% safe and appropriate.
+
+ The confirmation text did not match.
+
+
+
+
+
+
+
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb
index efb1116e8..8afc1c0d9 100644
--- a/app/views/layouts/admin.html.erb
+++ b/app/views/layouts/admin.html.erb
@@ -85,10 +85,10 @@
<% end %>
-
+ data-controller="alert"
+ data-action="error:generate@document->alert#generateErrorAlert"
+ data-testid="alertzone">
+
<% if request.path.split("/")[-3] == "admin" %>
diff --git a/cypress/integration/seededFlows/adminFlows/badges/badgeAchievements.spec.js b/cypress/integration/seededFlows/adminFlows/badges/badgeAchievements.spec.js
index 0efbd5b00..0f1c5b4fd 100644
--- a/cypress/integration/seededFlows/adminFlows/badges/badgeAchievements.spec.js
+++ b/cypress/integration/seededFlows/adminFlows/badges/badgeAchievements.spec.js
@@ -72,7 +72,7 @@ describe('Badge Achievements', () => {
cy.findByRole('button', { name: 'Confirm changes' }).click();
});
- cy.findByTestId('errorzone').within(() => {
+ cy.findByTestId('alertzone').within(() => {
cy.findByRole('alert')
.contains('Something went wrong.')
.should('be.visible');
diff --git a/cypress/integration/seededFlows/adminFlows/broadcasts/broadcasts.spec.js b/cypress/integration/seededFlows/adminFlows/broadcasts/broadcasts.spec.js
new file mode 100644
index 000000000..0ccb69c82
--- /dev/null
+++ b/cypress/integration/seededFlows/adminFlows/broadcasts/broadcasts.spec.js
@@ -0,0 +1,94 @@
+describe('Broadcasts', () => {
+ beforeEach(() => {
+ cy.testSetup();
+ cy.fixture('users/adminUser.json').as('user');
+
+ cy.get('@user').then((user) => {
+ cy.loginAndVisit(user, '/admin/advanced/broadcasts');
+
+ cy.findByRole('table').within(() => {
+ cy.findByRole('link', { name: 'Mock Broadcast' }).click();
+ });
+
+ cy.findByRole('button', { name: /Destroy/i }).click();
+ });
+ });
+
+ describe('delete a broadcast', () => {
+ it('should display confirmation modal', () => {
+ cy.findByRole('dialog').contains('Confirm changes').should('be.visible');
+ });
+
+ it('should display warning text if confirmation text does not match', () => {
+ cy.findByRole('dialog').within(() => {
+ cy.get('input').type('Text that does not match.');
+ cy.findByRole('button', { name: 'Confirm changes' }).click();
+
+ cy.get('.crayons-notice')
+ .contains('The confirmation text did not match.')
+ .should('be.visible');
+
+ cy.get('button[aria-label="Close"]').click();
+ });
+
+ cy.findByRole('heading', { level: 2, name: 'Mock Broadcast' }).should(
+ 'be.visible',
+ );
+ });
+
+ it('should delete the broadcast if confirmation text matches', () => {
+ cy.get('@user').then((user) => {
+ cy.findByRole('dialog').within(() => {
+ cy.get('input').type(
+ `My username is @${user.username} and this action is 100% safe and appropriate.`,
+ );
+ cy.findByRole('button', { name: 'Confirm changes' }).click();
+ });
+
+ // testing the redirect after broadcast destroy
+ cy.url().should('include', '/admin/advanced/broadcasts?redirected');
+
+ cy.findByTestId('snackbar').within(() => {
+ cy.findByRole('alert').should(
+ 'have.text',
+ 'Broadcast has been deleted!',
+ );
+ });
+
+ cy.findByRole('table').within(() => {
+ cy.findByRole('link', { name: 'Mock Broadcast' }).should('not.exist');
+ });
+ });
+ });
+
+ it.skip('generates error message when destroy action fails', () => {
+ cy.intercept('DELETE', '/admin/advanced/broadcasts/**', {
+ statusCode: 422,
+ body: {
+ error: 'Something went wrong with deleting the broadcast.',
+ },
+ });
+
+ cy.get('@user').then((user) => {
+ cy.findByRole('dialog').within(() => {
+ cy.get('input').type(
+ `My username is @${user.username} and this action is 100% safe and appropriate.`,
+ );
+ cy.findByRole('button', { name: 'Confirm changes' }).click();
+ });
+
+ cy.findByTestId('alertzone').within(() => {
+ cy.findByRole('alert')
+ .contains('Something went wrong with deleting the broadcast.')
+ .should('be.visible');
+ });
+
+ cy.url().should('not.include', '?redirected');
+
+ cy.findByRole('heading', { level: 2, name: 'Mock Broadcast' }).should(
+ 'be.visible',
+ );
+ });
+ });
+ });
+});
diff --git a/spec/requests/admin/broadcasts_spec.rb b/spec/requests/admin/broadcasts_spec.rb
index d7a24849f..a0309b6e8 100644
--- a/spec/requests/admin/broadcasts_spec.rb
+++ b/spec/requests/admin/broadcasts_spec.rb
@@ -69,7 +69,6 @@ RSpec.describe "/admin/advanced/broadcasts", type: :request do
expect do
delete admin_broadcast_path(broadcast.id)
end.to change { Broadcast.all.count }.by(-1)
- expect(response.body).to redirect_to admin_broadcasts_path
end
end
end
@@ -101,7 +100,6 @@ RSpec.describe "/admin/advanced/broadcasts", type: :request do
expect do
delete admin_broadcast_path(broadcast.id)
end.to change { Broadcast.all.count }.by(-1)
- expect(response.body).to redirect_to admin_broadcasts_path
end
end
end
diff --git a/spec/support/seeds/seeds_e2e.rb b/spec/support/seeds/seeds_e2e.rb
index 33a97aaf9..2de5362a2 100644
--- a/spec/support/seeds/seeds_e2e.rb
+++ b/spec/support/seeds/seeds_e2e.rb
@@ -610,3 +610,15 @@ seeder.create_if_none(FeedbackMessage) do
category: :bug,
)
end
+
+##############################################################################
+
+seeder.create_if_none(Broadcast) do
+ Broadcast.create!(
+ title: "Mock Broadcast",
+ processed_html: "
#{Faker::Hipster.paragraph(sentence_count: 2)}
",
+ type_of: "Welcome",
+ banner_style: "default",
+ active: true,
+ )
+end