diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 09:47:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 09:47:21 +0300 |
commit | c20ce49bdab650656be01968381f6ee1a5f96e7c (patch) | |
tree | 808be3d86edf4e29a5f148aae6bb9817ea3ee9be /spec | |
parent | 2dd1c1ab9db62a17d8f7ccaa29cec5a5f437d8de (diff) |
Add latest changes from gitlab-org/gitlab@15-10-stable-ee
Diffstat (limited to 'spec')
3 files changed, 102 insertions, 10 deletions
diff --git a/spec/features/admin/broadcast_messages_spec.rb b/spec/features/admin/broadcast_messages_spec.rb new file mode 100644 index 00000000000..fca4cdb0ff4 --- /dev/null +++ b/spec/features/admin/broadcast_messages_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Admin Broadcast Messages', :js, feature_category: :onboarding do + context 'when creating and editing' do + it 'previews, creates and edits a broadcast message' do + admin = create(:admin) + sign_in(admin) + gitlab_enable_admin_mode_sign_in(admin) + + # create + visit admin_broadcast_messages_path + + fill_in 'Message', with: 'test message' + + wait_for_requests + + page.within(preview_container) do + expect(page).to have_content('test message') + end + + click_button 'Add broadcast message' + + wait_for_requests + + page.within(preview_container) do + expect(page).to have_content('Your message here') + end + + page.within(first_message_container) do + expect(page).to have_content('test message') + end + + # edit + page.within(first_message_container) do + find('[data-testid="edit-message"]').click + end + + wait_for_requests + + expect(find('[data-testid="message-input"]').value).to eq('test message') + + fill_in 'Message', with: 'changed test message' + + wait_for_requests + + page.within(preview_container) do + expect(page).to have_content('changed test message') + end + + click_button 'Update broadcast message' + + wait_for_requests + + page.within(preview_container) do + expect(page).to have_content('Your message here') + end + + page.within(first_message_container) do + expect(page).to have_content('changed test message') + end + end + + def preview_container + find('[data-testid="preview-broadcast-message"]') + end + + def first_message_container + find('[data-testid="message-row"]', match: :first) + end + end +end diff --git a/spec/frontend/admin/broadcast_messages/components/message_form_spec.js b/spec/frontend/admin/broadcast_messages/components/message_form_spec.js index 292575c984b..ba8b9dd1345 100644 --- a/spec/frontend/admin/broadcast_messages/components/message_form_spec.js +++ b/spec/frontend/admin/broadcast_messages/components/message_form_spec.js @@ -5,12 +5,7 @@ import { createAlert } from '~/alert'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_BAD_REQUEST } from '~/lib/utils/http_status'; import MessageForm from '~/admin/broadcast_messages/components/message_form.vue'; -import { - BROADCAST_MESSAGES_PATH, - TYPE_BANNER, - TYPE_NOTIFICATION, - THEMES, -} from '~/admin/broadcast_messages/constants'; +import { TYPE_BANNER, TYPE_NOTIFICATION, THEMES } from '~/admin/broadcast_messages/constants'; import waitForPromises from 'helpers/wait_for_promises'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { MOCK_TARGET_ACCESS_LEVELS } from '../mock_data'; @@ -32,6 +27,8 @@ describe('MessageForm', () => { endsAt: new Date(), }; + const messagesPath = '_messages_path_'; + const findPreview = () => extendedWrapper(wrapper.findComponent(GlBroadcastMessage)); const findThemeSelect = () => wrapper.findComponent('[data-testid=theme-select]'); const findDismissable = () => wrapper.findComponent('[data-testid=dismissable-checkbox]'); @@ -44,6 +41,8 @@ describe('MessageForm', () => { provide: { glFeatures, targetAccessLevelOptions: MOCK_TARGET_ACCESS_LEVELS, + messagesPath, + previewPath: '_preview_path_', }, propsData: { broadcastMessage: { @@ -153,14 +152,14 @@ describe('MessageForm', () => { expect(axiosMock.history.post).toHaveLength(1); expect(axiosMock.history.post[0]).toMatchObject({ - url: BROADCAST_MESSAGES_PATH, + url: messagesPath, data: JSON.stringify(defaultPayload), }); }); it('shows an error alert if the create request fails', async () => { createComponent({ broadcastMessage: { id: undefined } }); - axiosMock.onPost(BROADCAST_MESSAGES_PATH).replyOnce(HTTP_STATUS_BAD_REQUEST); + axiosMock.onPost(messagesPath).replyOnce(HTTP_STATUS_BAD_REQUEST); findForm().vm.$emit('submit', { preventDefault: () => {} }); await waitForPromises(); @@ -179,7 +178,7 @@ describe('MessageForm', () => { expect(axiosMock.history.patch).toHaveLength(1); expect(axiosMock.history.patch[0]).toMatchObject({ - url: `${BROADCAST_MESSAGES_PATH}/${id}`, + url: `${messagesPath}/${id}`, data: JSON.stringify(defaultPayload), }); }); @@ -187,7 +186,7 @@ describe('MessageForm', () => { it('shows an error alert if the update request fails', async () => { const id = 1337; createComponent({ broadcastMessage: { id } }); - axiosMock.onPost(`${BROADCAST_MESSAGES_PATH}/${id}`).replyOnce(HTTP_STATUS_BAD_REQUEST); + axiosMock.onPost(`${messagesPath}/${id}`).replyOnce(HTTP_STATUS_BAD_REQUEST); findForm().vm.$emit('submit', { preventDefault: () => {} }); await waitForPromises(); diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb index e0bdb09f257..8d2245c820f 100644 --- a/spec/helpers/broadcast_messages_helper_spec.rb +++ b/spec/helpers/broadcast_messages_helper_spec.rb @@ -157,4 +157,24 @@ RSpec.describe BroadcastMessagesHelper, feature_category: :onboarding do expect(single_broadcast_message['ends_at']).to eq('2020-01-02T00:00:00Z') end end + + describe '#broadcast_message_data' do + let(:starts_at) { 1.day.ago } + let(:ends_at) { 1.day.from_now } + let(:message) { build(:broadcast_message, id: non_existing_record_id, starts_at: starts_at, ends_at: ends_at) } + + it 'returns the expected message data attributes' do + keys = [ + :id, :message, :broadcast_type, :theme, :dismissable, :target_access_levels, :messages_path, + :preview_path, :target_path, :starts_at, :ends_at, :target_access_level_options + ] + + expect(broadcast_message_data(message).keys).to match(keys) + end + + it 'has the correct iso formatted date', time_travel_to: '2020-01-01 00:00:00 +0000' do + expect(broadcast_message_data(message)[:starts_at]).to eq('2019-12-31T00:00:00Z') + expect(broadcast_message_data(message)[:ends_at]).to eq('2020-01-02T00:00:00Z') + end + end end |