diff options
-rw-r--r-- | app/assets/javascripts/monitoring/stores/utils.js | 15 | ||||
-rw-r--r-- | app/assets/javascripts/vue_shared/components/markdown/toolbar.vue | 57 | ||||
-rw-r--r-- | app/models/concerns/mentionable.rb | 4 | ||||
-rw-r--r-- | app/views/shared/issuable/_sidebar_assignees.html.haml | 11 | ||||
-rw-r--r-- | changelogs/unreleased/cngo-make-markdown-textarea-links-tab-accessible.yml | 5 | ||||
-rw-r--r-- | doc/development/database/index.md | 1 | ||||
-rw-r--r-- | doc/development/database/not_null_constraints.md | 217 | ||||
-rw-r--r-- | doc/development/database/strings_and_the_text_data_type.md | 12 | ||||
-rw-r--r-- | doc/development/migration_style_guide.md | 6 | ||||
-rw-r--r-- | doc/development/what_requires_downtime.md | 34 | ||||
-rw-r--r-- | lib/gitlab/experimentation.rb | 3 | ||||
-rw-r--r-- | locale/gitlab.pot | 9 | ||||
-rw-r--r-- | spec/features/issues/issue_sidebar_spec.rb | 136 | ||||
-rw-r--r-- | spec/features/merge_request/user_edits_assignees_sidebar_spec.rb | 99 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/utils_spec.js | 23 | ||||
-rw-r--r-- | spec/views/projects/merge_requests/show.html.haml_spec.rb | 4 |
16 files changed, 517 insertions, 119 deletions
diff --git a/app/assets/javascripts/monitoring/stores/utils.js b/app/assets/javascripts/monitoring/stores/utils.js index 64cedf8e8f5..82efe83b03c 100644 --- a/app/assets/javascripts/monitoring/stores/utils.js +++ b/app/assets/javascripts/monitoring/stores/utils.js @@ -192,7 +192,7 @@ const mapPanelToViewModel = ({ xAxis, maxValue: max_value, links: links.map(mapLinksToViewModel), - metrics: mapToMetricsViewModel(metrics, yAxis.name), + metrics: mapToMetricsViewModel(metrics), }; }; @@ -232,6 +232,19 @@ export const mapToDashboardViewModel = ({ }; }; +/** + * Processes a single Range vector, part of the result + * of type `matrix` in the form: + * + * { + * "metric": { "<label_name>": "<label_value>", ... }, + * "values": [ [ <unix_time>, "<sample_value>" ], ... ] + * }, + * + * See https://prometheus.io/docs/prometheus/latest/querying/api/#range-vectors + * + * @param {*} timeSeries + */ export const normalizeQueryResult = timeSeries => { let normalizedResult = {}; diff --git a/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue b/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue index 486d4f6b609..a1d652e42a8 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue @@ -1,11 +1,12 @@ <script> -/* eslint-disable @gitlab/vue-require-i18n-strings */ -import { GlLink, GlLoadingIcon } from '@gitlab/ui'; +import { GlButton, GlLink, GlLoadingIcon, GlSprintf } from '@gitlab/ui'; export default { components: { + GlButton, GlLink, GlLoadingIcon, + GlSprintf, }, props: { markdownDocsPath: { @@ -35,25 +36,32 @@ export default { <div class="comment-toolbar clearfix"> <div class="toolbar-text"> <template v-if="!hasQuickActionsDocsPath && markdownDocsPath"> - <gl-link :href="markdownDocsPath" target="_blank" tabindex="-1">{{ + <gl-link :href="markdownDocsPath" target="_blank">{{ __('Markdown is supported') }}</gl-link> </template> <template v-if="hasQuickActionsDocsPath && markdownDocsPath"> - <gl-link :href="markdownDocsPath" target="_blank" tabindex="-1">{{ - __('Markdown') - }}</gl-link> - and - <gl-link :href="quickActionsDocsPath" target="_blank" tabindex="-1">{{ - __('quick actions') - }}</gl-link> - are supported + <gl-sprintf + :message=" + __( + '%{markdownDocsLinkStart}Markdown%{markdownDocsLinkEnd} and %{quickActionsDocsLinkStart}quick actions%{quickActionsDocsLinkEnd} are supported', + ) + " + > + <template #markdownDocsLink="{content}"> + <gl-link :href="markdownDocsPath" target="_blank">{{ content }}</gl-link> + </template> + <template #quickActionsDocsLink="{content}"> + <gl-link :href="quickActionsDocsPath" target="_blank">{{ content }}</gl-link> + </template> + </gl-sprintf> </template> </div> <span v-if="canAttachFile" class="uploading-container"> <span class="uploading-progress-container hide"> <i class="fa fa-file-image-o toolbar-button-icon" aria-hidden="true"></i> <span class="attaching-file-message"></span> + <!-- eslint-disable-next-line @gitlab/vue-require-i18n-strings --> <span class="uploading-progress">0%</span> <gl-loading-icon inline class="align-text-bottom" /> </span> @@ -62,18 +70,29 @@ export default { <i class="fa fa-file-image-o toolbar-button-icon" aria-hidden="true"></i> </span> <span class="uploading-error-message"></span> - <button class="retry-uploading-link" type="button">{{ __('Try again') }}</button> or - <button class="attach-new-file markdown-selector" type="button"> - {{ __('attach a new file') }} - </button> + + <gl-sprintf + :message=" + __( + '%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}', + ) + " + > + <template #retryButton="{content}"> + <button class="retry-uploading-link" type="button">{{ content }}</button> + </template> + <template #newFileButton="{content}"> + <button class="attach-new-file markdown-selector" type="button">{{ content }}</button> + </template> + </gl-sprintf> </span> - <button class="markdown-selector button-attach-file btn-link" tabindex="-1" type="button"> + <gl-button class="markdown-selector button-attach-file" variant="link"> <i class="fa fa-file-image-o toolbar-button-icon" aria-hidden="true"></i ><span class="text-attach-file">{{ __('Attach a file') }}</span> - </button> - <button class="btn btn-default btn-sm hide button-cancel-uploading-files" type="button"> + </gl-button> + <gl-button class="btn btn-default btn-sm hide button-cancel-uploading-files" variant="link"> {{ __('Cancel') }} - </button> + </gl-button> </span> </div> </template> diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index d157404f7bc..7b4485376d4 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -259,8 +259,8 @@ module Mentionable # for the test period. # During the test period the flag should be enabled at the group level. def store_mentioned_users_to_db_enabled? - return Feature.enabled?(:store_mentioned_users_to_db, self.project&.group) if self.respond_to?(:project) - return Feature.enabled?(:store_mentioned_users_to_db, self.group) if self.respond_to?(:group) + return Feature.enabled?(:store_mentioned_users_to_db, self.project&.group, default_enabled: true) if self.respond_to?(:project) + return Feature.enabled?(:store_mentioned_users_to_db, self.group, default_enabled: true) if self.respond_to?(:group) end end diff --git a/app/views/shared/issuable/_sidebar_assignees.html.haml b/app/views/shared/issuable/_sidebar_assignees.html.haml index 4192ecd2238..adf2760329d 100644 --- a/app/views/shared/issuable/_sidebar_assignees.html.haml +++ b/app/views/shared/issuable/_sidebar_assignees.html.haml @@ -40,4 +40,13 @@ - data['max-select'] = dropdown_options[:data][:'max-select'] if dropdown_options[:data][:'max-select'] - options[:data].merge!(data) - = dropdown_tag(title, options: options) + - if experiment_enabled?(:invite_members_version_a) && can_import_members? + - options[:dropdown_class] += ' dropdown-extended-height' + - options[:footer_content] = true + + = dropdown_tag(title, options: options) do + %ul.dropdown-footer-list + %li + = link_to _('Invite Members'), project_project_members_path(@project), title: _('Invite Members'), :"data-is-link" => true + - else + = dropdown_tag(title, options: options) diff --git a/changelogs/unreleased/cngo-make-markdown-textarea-links-tab-accessible.yml b/changelogs/unreleased/cngo-make-markdown-textarea-links-tab-accessible.yml new file mode 100644 index 00000000000..5da2079f9b4 --- /dev/null +++ b/changelogs/unreleased/cngo-make-markdown-textarea-links-tab-accessible.yml @@ -0,0 +1,5 @@ +--- +title: Make markdown textarea links tab-accessible +merge_request: 33518 +author: +type: fixed diff --git a/doc/development/database/index.md b/doc/development/database/index.md index 5c44d4a56ee..665af623059 100644 --- a/doc/development/database/index.md +++ b/doc/development/database/index.md @@ -27,6 +27,7 @@ - [Adding database indexes](../adding_database_indexes.md) - [Foreign keys & associations](../foreign_keys.md) - [Adding a foreign key constraint to an existing column](add_foreign_key_to_existing_column.md) +- [`NOT NULL` constraints](not_null_constraints.md) - [Strings and the Text data type](strings_and_the_text_data_type.md) - [Single table inheritance](../single_table_inheritance.md) - [Polymorphic associations](../polymorphic_associations.md) diff --git a/doc/development/database/not_null_constraints.md b/doc/development/database/not_null_constraints.md new file mode 100644 index 00000000000..e4dec2afa10 --- /dev/null +++ b/doc/development/database/not_null_constraints.md @@ -0,0 +1,217 @@ +# `NOT NULL` constraints + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/38358) in GitLab 13.0. + +All attributes that should not have `NULL` as a value, should be defined as `NOT NULL` +columns in the database. + +Depending on the application logic, `NOT NULL` columns should either have a `presence: true` +validation defined in their Model or have a default value as part of their database definition. +As an example, the latter can be true for boolean attributes that should always have a non-`NULL` +value, but have a well defined default value that the application does not need to enforce each +time (for example, `active=true`). + +## Create a new table with `NOT NULL` columns + +When adding a new table, all `NOT NULL` columns should be defined as such directly inside `create_table`. + +For example, consider a migration that creates a table with two `NOT NULL` columns, +`db/migrate/20200401000001_create_db_guides.rb`: + +```ruby +class CreateDbGuides < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :db_guides do |t| + t.bigint :stars, default: 0, null: false + t.bigint :guide, null: false + end + end +end +``` + +## Add a `NOT NULL` column to an existing table + +With PostgreSQL 11 being the minimum version since GitLab 13.0, adding columns with `NULL` and/or +default values has become much easier and the standard `add_column` helper should be used in all cases. + +For example, consider a migration that adds a new `NOT NULL` column `active` to table `db_guides`, +`db/migrate/20200501000001_add_active_to_db_guides.rb`: + +```ruby +class AddExtendedTitleToSprints < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :db_guides, :active, :boolean, default: true, null: false + end +end +``` + +## Add a `NOT NULL` constraint to an existing column + +Adding `NOT NULL` to existing database columns requires multiple steps split into at least two +different releases: + +1. Release `N.M` (current release) + + - Ensure the constraint is enforced at the application level (i.e. add a model validation). + - Add a post-deployment migration to add the `NOT NULL` constraint with `validate: false`. + - Add a post-deployment migration to fix the existing records. + + NOTE: **Note:** + Depending on the size of the table, a background migration for cleanup could be required in the next release. + See the [`NOT NULL` constraints on large tables](not_null_constraints.md#not-null-constraints-on-large-tables) section for more information. + + - Create an issue for the next milestone to validate the `NOT NULL` constraint. + +1. Release `N.M+1` (next release) + + - Validate the `NOT NULL` constraint using a post-deployment migration. + +### Example + +Considering a given release milestone, such as 13.0, a model validation has been added into `epic.rb` +to require a description: + +```ruby +class Epic < ApplicationRecord + validates :description, presence: true +end +``` + +The same constraint should be added at the database level for consistency purposes. +We only want to enforce the `NOT NULL` constraint without setting a default, as we have decided +that all epics should have a user-generated description. + +After checking our production database, we know that there are `epics` with `NULL` descriptions, +so we can not add and validate the constraint in one step. + +NOTE: **Note:** +Even if we did not have any epic with a `NULL` description, another instance of GitLab could have +such records, so we would follow the same process either way. + +#### Prevent new invalid records (current release) + +We first add the `NOT NULL` constraint with a `NOT VALID` parameter, which enforces consistency +when new records are inserted or current records are updated. + +In the example above, the existing epics with a `NULL` description will not be affected and you'll +still be able to update records in the `epics` table. However, when you try to update or insert +an epic without providing a description, the constraint causes a database error. + +Adding or removing a `NOT NULL` clause requires that any application changes are deployed _first_. +Thus, adding a `NOT NULL` constraint to an existing column should happen in a post-deployment migration. + +Still in our example, for the 13.0 milestone example (current), we add the `NOT NULL` constraint +with `validate: false` in a post-deployment migration, +`db/post_migrate/20200501000001_add_not_null_constraint_to_epics_description.rb`: + +```ruby +class AddNotNullConstraintToEpicsDescription < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + # This will add the `NOT NULL` constraint WITHOUT validating it + add_not_null_constraint :epics, :description, validate: false + end + + def down + # Down is required as `add_not_null_constraint` is not reversible + remove_not_null_constraint :epics, :description + end +end +``` + +#### Data migration to fix existing records (current release) + +The approach here depends on the data volume and the cleanup strategy. The number of records that +must be fixed on GitLab.com is a nice indicator that will help us decide whether to use a +post-deployment migration or a background data migration: + +- If the data volume is less than `1000` records, then the data migration can be executed within the post-migration. +- If the data volume is higher than `1000` records, it's advised to create a background migration. + +When unsure about which option to use, please contact the Database team for advice. + +Back to our example, the epics table is not considerably large nor frequently accessed, +so we are going to add a post-deployment migration for the 13.0 milestone (current), +`db/post_migrate/20200501000002_cleanup_epics_with_null_description.rb`: + +```ruby +class CleanupEpicsWithNullDescription < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + # With BATCH_SIZE=1000 and epics.count=29500 on GitLab.com + # - 30 iterations will be run + # - each requires on average ~150ms + # Expected total run time: ~5 seconds + BATCH_SIZE = 1000 + + disable_ddl_transaction! + + class Epic < ActiveRecord::Base + include EachBatch + + self.table_name = 'epics' + end + + def up + Epic.each_batch(of: BATCH_SIZE) do |relation| + relation. + where('description IS NULL'). + update_all(description: 'No description') + end + end + + def down + # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint + end +end +``` + +#### Validate the text limit (next release) + +Validating the `NOT NULL` constraint will scan the whole table and make sure that each record is correct. + +Still in our example, for the 13.1 milestone (next), we run the `validate_not_null_constraint` +migration helper in a final post-deployment migration, +`db/post_migrate/20200601000001_validate_not_null_constraint_on_epics_description.rb`: + +```ruby +class ValidateNotNullConstraintOnEpicsDescription < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + validate_not_null_constraint :epics, :description + end + + def down + # no-op + end +end +``` + +## `NOT NULL` constraints on large tables + +If you have to clean up a text column for a really [large table](https://gitlab.com/gitlab-org/gitlab/-/blob/master/rubocop/migration_helpers.rb#L12) +(for example, the `artifacts` in `ci_builds`), your background migration will go on for a while and +it will need an additional [background migration cleaning up](../background_migrations.md#cleaning-up) +in the release after adding the data migration. + +In that rare case you will need 3 releases end-to-end: + +1. Release `N.M` - Add the `NOT NULL` constraint and the background-migration to fix the existing records. +1. Release `N.M+1` - Cleanup the background migration. +1. Release `N.M+2` - Validate the `NOT NULL` constraint. + +For these cases, please consult the database team early in the update cycle. The `NOT NULL` +constraint may not be required or other options could exist that do not affect really large +or frequently accessed tables. diff --git a/doc/development/database/strings_and_the_text_data_type.md b/doc/development/database/strings_and_the_text_data_type.md index 67e7f896b61..8038663392f 100644 --- a/doc/development/database/strings_and_the_text_data_type.md +++ b/doc/development/database/strings_and_the_text_data_type.md @@ -34,7 +34,7 @@ When adding a new table, the limits for all text columns should be added in the the table creation. For example, consider a migration that creates a table with two text columns, -**db/migrate/20200401000001_create_db_guides.rb**: +`db/migrate/20200401000001_create_db_guides.rb`: ```ruby class CreateDbGuides < ActiveRecord::Migration[6.0] @@ -80,7 +80,7 @@ frequently accessed table may take minutes in GitLab.com and requires the use of For these reasons, it is advised to add the text limit on a separate migration than the `add_column` one. For example, consider a migration that adds a new text column `extended_title` to table `sprints`, -**db/migrate/20200501000001_add_extended_title_to_sprints.rb**: +`db/migrate/20200501000001_add_extended_title_to_sprints.rb`: ```ruby class AddExtendedTitleToSprints < ActiveRecord::Migration[6.0] @@ -96,7 +96,7 @@ end ``` A second migration should follow the first one with a limit added to `extended_title`, -**db/migrate/20200501000002_add_text_limit_to_sprints_extended_title.rb**: +`db/migrate/20200501000002_add_text_limit_to_sprints_extended_title.rb`: ```ruby class AddTextLimitToSprintsExtendedTitle < ActiveRecord::Migration[6.0] @@ -174,7 +174,7 @@ validates :title_html, length: { maximum: 1024 } We can also update the database in the same milestone by adding the text limit with `validate: false` in a post-deployment migration, -**db/post_migrate/20200501000001_add_text_limit_migration.rb**: +`db/post_migrate/20200501000001_add_text_limit_migration.rb`: ```ruby class AddTextLimitMigration < ActiveRecord::Migration[6.0] @@ -208,7 +208,7 @@ When unsure about which option to use, please contact the Database team for advi Back to our example, the issues table is considerably large and frequently accessed, so we are going to add a background migration for the 13.0 milestone (current), -**db/post_migrate/20200501000002_schedule_cap_title_length_on_issues.rb**: +`db/post_migrate/20200501000002_schedule_cap_title_length_on_issues.rb`: ```ruby class ScheduleCapTitleLengthOnIssues < ActiveRecord::Migration[6.0] @@ -255,7 +255,7 @@ Validating the text limit will scan the whole table and make sure that each reco Still in our example, for the 13.1 milestone (next), we run the `validate_text_limit` migration helper in a final post-deployment migration, -**db/post_migrate/20200601000001_validate_text_limit_migration.rb**: +`db/post_migrate/20200601000001_validate_text_limit_migration.rb`: ```ruby class ValidateTextLimitMigration < ActiveRecord::Migration[6.0] diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index 5f9eaff0df0..74c03ec72b4 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -552,6 +552,12 @@ operations that don't require `disable_ddl_transaction!`. You can read more about adding [foreign key constraints to an existing column](database/add_foreign_key_to_existing_column.md). +## `NOT NULL` constraints + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/38358) in GitLab 13.0. + +See the style guide on [`NOT NULL` constraints](database/not_null_constraints.md) for more information. + ## Adding Columns With Default Values With PostgreSQL 11 being the minimum version since GitLab 13.0, adding columns with default values has become much easier and diff --git a/doc/development/what_requires_downtime.md b/doc/development/what_requires_downtime.md index 8ea9f70fc7a..858de8e7e36 100644 --- a/doc/development/what_requires_downtime.md +++ b/doc/development/what_requires_downtime.md @@ -135,7 +135,7 @@ With [Canary](https://about.gitlab.com/handbook/engineering/infrastructure/libra ## Changing Column Constraints -Adding or removing a NOT NULL clause (or another constraint) can typically be +Adding or removing a `NOT NULL` clause (or another constraint) can typically be done without requiring downtime. However, this does require that any application changes are deployed _first_. Thus, changing the constraints of a column should happen in a post-deployment migration. @@ -143,35 +143,11 @@ happen in a post-deployment migration. NOTE: Avoid using `change_column` as it produces an inefficient query because it re-defines the whole column type. -To add a NOT NULL constraint, use the `add_not_null_constraint` migration helper: +You can check the following guides for each specific use case: -```ruby -# A post-deployment migration in db/post_migrate -class AddNotNull < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - add_not_null_constraint :users, :username - end - - def down - remove_not_null_constraint :users, :username - end -end -``` - -If the column to be updated requires cleaning first (e.g. there are `NULL` values), you should: - -1. Add the `NOT NULL` constraint with `validate: false` - - `add_not_null_constraint :users, :username, validate: false` - -1. Clean up the data with a data migration -1. Validate the `NOT NULL` constraint with a followup migration - - `validate_not_null_constraint :users, :username` +- [Adding foreign-key constraints](migration_style_guide.md#adding-foreign-key-constraints) +- [Adding `NOT NULL` constraints](database/not_null_constraints.md) +- [Adding limits to text columns](database/strings_and_the_text_data_type.md) ## Changing Column Types diff --git a/lib/gitlab/experimentation.rb b/lib/gitlab/experimentation.rb index 62a88db7629..008baf8ae0d 100644 --- a/lib/gitlab/experimentation.rb +++ b/lib/gitlab/experimentation.rb @@ -47,6 +47,9 @@ module Gitlab }, upgrade_link_in_user_menu_a: { tracking_category: 'Growth::Expansion::Experiment::UpgradeLinkInUserMenuA' + }, + invite_members_version_a: { + tracking_category: 'Growth::Expansion::Experiment::InviteMembersVersionA' } }.freeze diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 3c2f34ad09f..03d7a71a90c 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -430,6 +430,9 @@ msgstr "" msgid "%{lock_path} is locked by GitLab User %{lock_user_id}" msgstr "" +msgid "%{markdownDocsLinkStart}Markdown%{markdownDocsLinkEnd} and %{quickActionsDocsLinkStart}quick actions%{quickActionsDocsLinkEnd} are supported" +msgstr "" + msgid "%{mergeLength}/%{usersLength} can merge" msgstr "" @@ -503,6 +506,9 @@ msgid_plural "%{releases} releases" msgstr[0] "" msgstr[1] "" +msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}" +msgstr "" + msgid "%{screenreaderOnlyStart}Keyboard shorcuts%{screenreaderOnlyEnd} Disabled" msgstr "" @@ -12112,6 +12118,9 @@ msgstr "" msgid "Invite \"%{trimmed}\" by email" msgstr "" +msgid "Invite Members" +msgstr "" + msgid "Invite group" msgstr "" diff --git a/spec/features/issues/issue_sidebar_spec.rb b/spec/features/issues/issue_sidebar_spec.rb index e7c675bf6bf..8f52a7541f4 100644 --- a/spec/features/issues/issue_sidebar_spec.rb +++ b/spec/features/issues/issue_sidebar_spec.rb @@ -7,12 +7,13 @@ describe 'Issue Sidebar' do let(:group) { create(:group, :nested) } let(:project) { create(:project, :public, namespace: group) } - let!(:user) { create(:user)} + let!(:user) { create(:user) } let!(:label) { create(:label, project: project, title: 'bug') } let(:issue) { create(:labeled_issue, project: project, labels: [label]) } let!(:xss_label) { create(:label, project: project, title: '<script>alert("xss");</script>') } before do + stub_feature_flags(save_issuable_health_status: false) sign_in(user) end @@ -20,62 +21,123 @@ describe 'Issue Sidebar' do let(:user2) { create(:user) } let(:issue2) { create(:issue, project: project, author: user2) } - before do - project.add_developer(user) - visit_issue(project, issue2) + context 'when invite_members_version_a experiment is enabled' do + before do + stub_experiment_for_user(invite_members_version_a: true) + end - find('.block.assignee .edit-link').click + context 'when user can not see invite members' do + before do + project.add_developer(user) + visit_issue(project, issue2) - wait_for_requests - end + find('.block.assignee .edit-link').click - it 'shows author in assignee dropdown' do - page.within '.dropdown-menu-user' do - expect(page).to have_content(user2.name) + wait_for_requests + end + + it 'does not see link to invite members' do + page.within '.dropdown-menu-user' do + expect(page).not_to have_link('Invite Members') + end + end end - end - it 'shows author when filtering assignee dropdown' do - page.within '.dropdown-menu-user' do - find('.dropdown-input-field').native.send_keys user2.name - sleep 1 # Required to wait for end of input delay + context 'when user can see invite members' do + before do + project.add_maintainer(user) + visit_issue(project, issue2) + + find('.block.assignee .edit-link').click - wait_for_requests + wait_for_requests + end - expect(page).to have_content(user2.name) + it 'sees link to invite members' do + page.within '.dropdown-menu-user' do + expect(page).to have_link('Invite Members', href: project_project_members_path(project)) + end + end end end - it 'assigns yourself' do - find('.block.assignee .dropdown-menu-toggle').click + context 'when invite_members_version_a experiment is not enabled' do + context 'when user is a developer' do + before do + project.add_developer(user) + visit_issue(project, issue2) - click_button 'assign yourself' + find('.block.assignee .edit-link').click - wait_for_requests + wait_for_requests + end - find('.block.assignee .edit-link').click + it 'shows author in assignee dropdown' do + page.within '.dropdown-menu-user' do + expect(page).to have_content(user2.name) + end + end - page.within '.dropdown-menu-user' do - expect(page.find('.dropdown-header')).to be_visible - expect(page.find('.dropdown-menu-user-link.is-active')).to have_content(user.name) - end - end + it 'shows author when filtering assignee dropdown' do + page.within '.dropdown-menu-user' do + find('.dropdown-input-field').native.send_keys user2.name + sleep 1 # Required to wait for end of input delay - it 'keeps your filtered term after filtering and dismissing the dropdown' do - find('.dropdown-input-field').native.send_keys user2.name + wait_for_requests - wait_for_requests + expect(page).to have_content(user2.name) + end + end + + it 'assigns yourself' do + find('.block.assignee .dropdown-menu-toggle').click + + click_button 'assign yourself' + + wait_for_requests + + find('.block.assignee .edit-link').click + + page.within '.dropdown-menu-user' do + expect(page.find('.dropdown-header')).to be_visible + expect(page.find('.dropdown-menu-user-link.is-active')).to have_content(user.name) + end + end + + it 'keeps your filtered term after filtering and dismissing the dropdown' do + find('.dropdown-input-field').native.send_keys user2.name + + wait_for_requests - page.within '.dropdown-menu-user' do - expect(page).not_to have_content 'Unassigned' - click_link user2.name + page.within '.dropdown-menu-user' do + expect(page).not_to have_content 'Unassigned' + click_link user2.name + end + + find('.js-right-sidebar').click + find('.block.assignee .edit-link').click + + expect(page.all('.dropdown-menu-user li').length).to eq(1) + expect(find('.dropdown-input-field').value).to eq(user2.name) + end end - find('.js-right-sidebar').click - find('.block.assignee .edit-link').click + context 'when user is a maintainer' do + before do + project.add_maintainer(user) + visit_issue(project, issue2) + + find('.block.assignee .edit-link').click - expect(page.all('.dropdown-menu-user li').length).to eq(1) - expect(find('.dropdown-input-field').value).to eq(user2.name) + wait_for_requests + end + + it 'shows author in assignee dropdown and no invite link' do + page.within '.dropdown-menu-user' do + expect(page).not_to have_link('Invite Members') + end + end + end end end diff --git a/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb b/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb index e6b77e28281..27b3ff3e085 100644 --- a/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb +++ b/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb @@ -20,49 +20,100 @@ describe 'Merge request > User edits assignees sidebar', :js do let(:sidebar_assignee_dropdown_item) { sidebar_assignee_block.find(".dropdown-menu li[data-user-id=\"#{assignee.id}\"]") } let(:sidebar_assignee_dropdown_tooltip) { sidebar_assignee_dropdown_item.find('a')['data-title'] || '' } - before do - stub_const('Autocomplete::UsersFinder::LIMIT', users_find_limit) + context 'when invite_members_version_a experiment is not enabled' do + before do + stub_const('Autocomplete::UsersFinder::LIMIT', users_find_limit) - sign_in(project.owner) + sign_in(project.owner) - merge_request.assignees << assignee + merge_request.assignees << assignee - visit project_merge_request_path(project, merge_request) + visit project_merge_request_path(project, merge_request) - wait_for_requests - end + wait_for_requests + end + + shared_examples 'when assigned' do |expected_tooltip: ''| + it 'shows assignee name' do + expect(sidebar_assignee_block).to have_text(assignee.name) + end + + it "shows assignee tooltip '#{expected_tooltip}'" do + expect(sidebar_assignee_tooltip).to eql(expected_tooltip) + end + + context 'when edit is clicked' do + before do + sidebar_assignee_block.click_link('Edit') + + wait_for_requests + end + + it "shows assignee tooltip '#{expected_tooltip}" do + expect(sidebar_assignee_dropdown_tooltip).to eql(expected_tooltip) + end + + it 'does not show invite link' do + page.within '.dropdown-menu-user' do + expect(page).not_to have_link('Invite Members') + end + end + end + end + + context 'when assigned to maintainer' do + let(:assignee) { project_maintainers.last } - shared_examples 'when assigned' do |expected_tooltip: ''| - it 'shows assignee name' do - expect(sidebar_assignee_block).to have_text(assignee.name) + it_behaves_like 'when assigned', expected_tooltip: '' end - it "shows assignee tooltip '#{expected_tooltip}'" do - expect(sidebar_assignee_tooltip).to eql(expected_tooltip) + context 'when assigned to developer' do + let(:assignee) { project_developers.last } + + it_behaves_like 'when assigned', expected_tooltip: 'Cannot merge' end + end - context 'when edit is clicked' do + context 'when invite_members_version_a experiment is enabled' do + let_it_be(:user) { create(:user) } + + before do + stub_experiment_for_user(invite_members_version_a: true) + sign_in(user) + end + + context 'when user can not see invite members' do before do - sidebar_assignee_block.click_link('Edit') + project.add_developer(user) + visit project_merge_request_path(project, merge_request) + + find('.block.assignee .edit-link').click wait_for_requests end - it "shows assignee tooltip '#{expected_tooltip}" do - expect(sidebar_assignee_dropdown_tooltip).to eql(expected_tooltip) + it 'does not see link to invite members' do + page.within '.dropdown-menu-user' do + expect(page).not_to have_link('Invite Members') + end end end - end - context 'when assigned to maintainer' do - let(:assignee) { project_maintainers.last } + context 'when user can see invite members' do + before do + project.add_maintainer(user) + visit project_merge_request_path(project, merge_request) - it_behaves_like 'when assigned', expected_tooltip: '' - end + find('.block.assignee .edit-link').click - context 'when assigned to developer' do - let(:assignee) { project_developers.last } + wait_for_requests + end - it_behaves_like 'when assigned', expected_tooltip: 'Cannot merge' + it 'sees link to invite members' do + page.within '.dropdown-menu-user' do + expect(page).to have_link('Invite Members', href: project_project_members_path(project)) + end + end + end end end diff --git a/spec/frontend/monitoring/store/utils_spec.js b/spec/frontend/monitoring/store/utils_spec.js index 02cdd3d7f41..6ba75cd984c 100644 --- a/spec/frontend/monitoring/store/utils_spec.js +++ b/spec/frontend/monitoring/store/utils_spec.js @@ -5,6 +5,7 @@ import { parseAnnotationsResponse, removeLeadingSlash, mapToDashboardViewModel, + normalizeQueryResult, } from '~/monitoring/stores/utils'; import { annotationsData } from '../mock_data'; import { NOT_IN_DB_PREFIX } from '~/monitoring/constants'; @@ -397,6 +398,28 @@ describe('mapToDashboardViewModel', () => { }); }); +describe('normalizeQueryResult', () => { + const testData = { + metric: { + __name__: 'up', + job: 'prometheus', + instance: 'localhost:9090', + }, + values: [[1435781430.781, '1'], [1435781445.781, '1'], [1435781460.781, '1']], + }; + + it('processes a simple matrix result', () => { + expect(normalizeQueryResult(testData)).toEqual({ + metric: { __name__: 'up', job: 'prometheus', instance: 'localhost:9090' }, + values: [ + ['2015-07-01T20:10:30.781Z', 1], + ['2015-07-01T20:10:45.781Z', 1], + ['2015-07-01T20:11:00.781Z', 1], + ], + }); + }); +}); + describe('uniqMetricsId', () => { [ { input: { id: 1 }, expected: `${NOT_IN_DB_PREFIX}_1` }, diff --git a/spec/views/projects/merge_requests/show.html.haml_spec.rb b/spec/views/projects/merge_requests/show.html.haml_spec.rb index 665003d137a..e0acf5d1507 100644 --- a/spec/views/projects/merge_requests/show.html.haml_spec.rb +++ b/spec/views/projects/merge_requests/show.html.haml_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe 'projects/merge_requests/show.html.haml' do + before do + allow(view).to receive(:experiment_enabled?).and_return(false) + end + include_context 'merge request show action' describe 'merge request assignee sidebar' do |