Commit 97b2ec92 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents bf9c14de 1cc51c95
......@@ -279,7 +279,7 @@ export default {
<div class="pipelines-container">
<div
v-if="shouldRenderTabs || shouldRenderButtons"
class="top-area scrolling-tabs-container inner-page-scroll-tabs"
class="top-area scrolling-tabs-container inner-page-scroll-tabs gl-border-none"
>
<div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div>
<div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div>
......
<script>
import $ from 'jquery';
import { GlBadge, GlTabs, GlTab } from '@gitlab/ui';
/**
* Given an array of tabs, renders non linked bootstrap tabs.
......@@ -23,6 +24,11 @@ import $ from 'jquery';
*/
export default {
name: 'NavigationTabs',
components: {
GlBadge,
GlTabs,
GlTab,
},
props: {
tabs: {
type: Array,
......@@ -50,24 +56,21 @@ export default {
};
</script>
<template>
<ul class="nav-links scrolling-tabs separator">
<li
<gl-tabs class="gl-display-flex gl-w-full" nav-class="gl-border-0!">
<gl-tab
v-for="(tab, i) in tabs"
:key="i"
:class="{
active: tab.isActive,
}"
:title-link-class="`js-${scope}-tab-${tab.scope} gl-display-inline-flex`"
:title-link-attributes="{ 'data-testid': `${scope}-tab-${tab.scope}` }"
:active="tab.isActive"
@click="onTabClick(tab)"
>
<a
:class="`js-${scope}-tab-${tab.scope}`"
:data-testid="`${scope}-tab-${tab.scope}`"
role="button"
@click="onTabClick(tab)"
>
{{ tab.name }}
<span v-if="shouldRenderBadge(tab.count)" class="badge badge-pill"> {{ tab.count }} </span>
</a>
</li>
</ul>
<template #title>
<span class="gl-mr-2"> {{ tab.name }} </span>
<gl-badge v-if="shouldRenderBadge(tab.count)" size="sm" class="gl-tab-counter-badge">{{
tab.count
}}</gl-badge>
</template>
</gl-tab>
</gl-tabs>
</template>
---
title: Convert navigation_tabs.vue to gl-tabs
merge_request: 47841
author:
type: other
......@@ -29,8 +29,8 @@ Docker image with the fuzz engine to run your app.
| GoLang | [go-fuzz (libFuzzer support)](https://github.com/dvyukov/go-fuzz) | [go-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/go-fuzzing-example) |
| Swift | [libfuzzer](https://github.com/apple/swift/blob/master/docs/libFuzzerIntegration.md) | [swift-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/swift-fuzzing-example) |
| Rust | [cargo-fuzz (libFuzzer support)](https://github.com/rust-fuzz/cargo-fuzz) | [rust-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/rust-fuzzing-example) |
| Java | [JQF](https://github.com/rohanpadhye/JQF) | [java-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/java-fuzzing-example) |
| Java | [javafuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/javafuzz) (recommended) | [javafuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/javafuzz-fuzzing-example) |
| Java | [JQF](https://github.com/rohanpadhye/JQF) (not preferred) | [jqf-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/java-fuzzing-example) |
| JavaScript | [jsfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz)| [jsfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/jsfuzz-fuzzing-example) |
| Python | [pythonfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/pythonfuzz)| [pythonfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/pythonfuzz-fuzzing-example) |
......
......@@ -13,7 +13,7 @@ module Geo
end
def handle_after_create_commit
return false unless Gitlab::Geo.enabled?
return false unless Gitlab::Geo.primary?
return unless self.class.enabled?
publish(:created, **created_params)
......
......@@ -125,17 +125,12 @@ module Geo
Geo::VerificationWorker.perform_async(replicable_name, model_record.id)
end
# Calculates checksum and asks the model/registry to update verification
# Calculates checksum and asks the model/registry to manage verification
# state.
def verify
model_record.verification_started! unless model_record.verification_started?
calculation_started_at = Time.current
checksum = model_record.calculate_checksum
model_record.verification_succeeded_with_checksum!(checksum, calculation_started_at)
rescue => e
model_record.verification_failed_with_message!('Error calculating the checksum', e)
model_record.track_checksum_attempt! do
model_record.calculate_checksum
end
end
# Check if given checksum matches known one
......
......@@ -267,14 +267,14 @@ module Gitlab
end
def handle_after_destroy
return false unless Gitlab::Geo.enabled?
return false unless Gitlab::Geo.primary?
return unless self.class.enabled?
publish(:deleted, **deleted_params)
end
def handle_after_update
return false unless Gitlab::Geo.enabled?
return false unless Gitlab::Geo.primary?
return unless self.class.enabled?
publish(:updated, **updated_params)
......
......@@ -177,6 +177,25 @@ module Gitlab
end
end
# Provides a safe and easy way to manage the verification state for a
# synchronous checksum calculation.
#
# @yieldreturn [String] calculated checksum value
def track_checksum_attempt!(&block)
# This line only applies to Geo::VerificationWorker, not
# Geo::VerificationBatchWorker, since the latter sets the whole batch to
# "verification_started" in the same DB query that fetches the batch.
verification_started! unless verification_started?
calculation_started_at = Time.current
checksum = yield
track_checksum_result!(checksum, calculation_started_at)
rescue => e
verification_failed_with_message!('Error during verification', e)
end
# Convenience method to update checksum and transition to success state.
#
# @param [String] checksum value generated by the checksum routine
......@@ -193,23 +212,36 @@ module Gitlab
end
end
def resource_updated_during_checksum?(calculation_started_at)
self.reset.verification_started_at > calculation_started_at
end
# Convenience method to update failure message and transition to failed
# state.
#
# @param [String] message error information
# @param [StandardError] error exception
def verification_failed_with_message!(message, error = nil)
log_error('Error calculating the checksum', error)
log_error(message, error)
self.verification_failure = message
self.verification_failure += ": #{error.message}" if error.respond_to?(:message)
self.verification_failed!
end
private
# Records the calculated checksum result
#
# Overridden by ReplicableRegistry so it can also compare with primary
# checksum.
#
# @param [String] calculated checksum value
# @param [Time] when checksum calculation was started
def track_checksum_result!(checksum, calculation_started_at)
verification_succeeded_with_checksum!(checksum, calculation_started_at)
end
def resource_updated_during_checksum?(calculation_started_at)
self.reset.verification_started_at > calculation_started_at
end
end
end
end
......@@ -157,6 +157,55 @@ RSpec.describe Gitlab::Geo::VerificationState do
end
end
describe '#track_checksum_attempt!' do
context 'when verification was not yet started' do
it 'starts verification' do
expect do
subject.track_checksum_attempt! do
'a_checksum_value'
end
end.to change { subject.verification_started_at }.from(nil)
end
it 'sets verification_succeeded' do
expect do
subject.track_checksum_attempt! do
'a_checksum_value'
end
end.to change { subject.verification_succeeded? }.from(false).to(true)
end
end
context 'when verification was started' do
it 'does not update verification_started_at' do
subject.verification_started!
expected = subject.verification_started_at
subject.track_checksum_attempt! do
'a_checksum_value'
end
expect(subject.verification_started_at).to be_within(1.second).of(expected)
end
end
it 'yields to the checksum calculation' do
expect do |probe|
subject.track_checksum_attempt!(&probe)
end.to yield_with_no_args
end
context 'when an error occurs while yielding' do
it 'sets verification_failed' do
subject.track_checksum_attempt! do
raise 'an error'
end
expect(subject.reload.verification_failed?).to be_truthy
end
end
end
describe '#verification_succeeded_with_checksum!' do
before do
subject.verification_started!
......
......@@ -22,7 +22,7 @@ RSpec.describe Packages::PackageFile, type: :model do
context 'new file' do
it 'calls checksum worker' do
allow(Gitlab::Geo).to receive(:enabled?).and_return(true)
stub_primary_node
allow(Geo::VerificationWorker).to receive(:perform_async)
package_file = create(:conan_package_file, :conan_recipe_file)
......
......@@ -326,30 +326,39 @@ RSpec.shared_examples 'a verifiable replicator' do
end
describe '#verify' do
context 'on a Geo primary' do
it 'wraps the checksum calculation in track_checksum_attempt!' do
tracker = double('tracker', calculate_checksum: 'abc123')
allow(replicator).to receive(:model_record).and_return(tracker)
expect(tracker).to receive(:track_checksum_attempt!).and_yield
replicator.verify
end
end
context 'integration tests' do
before do
model_record.save!
end
context 'on a primary' do
before do
stub_primary_node
end
context 'when the checksum succeeds' do
it 'delegates checksum calculation and the state change to model_record' do
expect(model_record).to receive(:calculate_checksum).and_return('abc123')
expect(model_record).to receive(:verification_succeeded_with_checksum!).with('abc123', kind_of(Time))
replicator.verify
describe 'background backfill' do
it 'verifies model records' do
expect do
Geo::VerificationBatchWorker.new.perform(replicator.replicable_name)
end.to change { model_record.reload.verification_succeeded? }.from(false).to(true)
end
end
context 'when an error is raised during calculate_checksum' do
it 'passes the error message' do
error = StandardError.new('Some exception')
allow(model_record).to receive(:calculate_checksum) do
raise error
end
expect(model_record).to receive(:verification_failed_with_message!).with('Error calculating the checksum', error)
replicator.verify
describe 'triggered by events' do
it 'verifies model records' do
expect do
Geo::VerificationWorker.new.perform(replicator.replicable_name, replicator.model_record_id)
end.to change { model_record.reload.verification_succeeded? }.from(false).to(true)
end
end
end
......
......@@ -35,7 +35,7 @@ describe('Deploy keys app component', () => {
});
const findLoadingIcon = () => wrapper.find('.gl-spinner');
const findKeyPanels = () => wrapper.findAll('.deploy-keys .nav-links li');
const findKeyPanels = () => wrapper.findAll('.deploy-keys .gl-tabs-nav li');
it('renders loading icon while waiting for request', () => {
mock.onGet(TEST_ENDPOINT).reply(() => new Promise());
......@@ -54,17 +54,14 @@ describe('Deploy keys app component', () => {
});
it.each`
selector | label | count
${'.js-deployKeys-tab-enabled_keys'} | ${'Enabled deploy keys'} | ${1}
${'.js-deployKeys-tab-available_project_keys'} | ${'Privately accessible deploy keys'} | ${0}
${'.js-deployKeys-tab-public_keys'} | ${'Publicly accessible deploy keys'} | ${1}
`('$selector title is $label with keys count equal to $count', ({ selector, label, count }) => {
selector
${'.js-deployKeys-tab-enabled_keys'}
${'.js-deployKeys-tab-available_project_keys'}
${'.js-deployKeys-tab-public_keys'}
`('$selector title exists', ({ selector }) => {
return mountComponent().then(() => {
const element = wrapper.find(selector);
expect(element.exists()).toBe(true);
expect(element.text().trim()).toContain(label);
expect(element.find('.badge').text().trim()).toBe(count.toString());
});
});
......
import Vue from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import navigationTabs from '~/vue_shared/components/navigation_tabs.vue';
import { mount } from '@vue/test-utils';
import { GlTab } from '@gitlab/ui';
import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
describe('navigation tabs component', () => {
let vm;
let Component;
let data;
let wrapper;
beforeEach(() => {
data = [
{
name: 'All',
scope: 'all',
count: 1,
isActive: true,
},
{
name: 'Pending',
scope: 'pending',
count: 0,
isActive: false,
},
{
name: 'Running',
scope: 'running',
isActive: false,
const data = [
{
name: 'All',
scope: 'all',
count: 1,
isActive: true,
},
{
name: 'Pending',
scope: 'pending',
count: 0,
isActive: false,
},
{
name: 'Running',
scope: 'running',
isActive: false,
},
];
const createComponent = () => {
wrapper = mount(NavigationTabs, {
propsData: {
tabs: data,
scope: 'pipelines',
},
];
});
};
Component = Vue.extend(navigationTabs);
vm = mountComponent(Component, { tabs: data, scope: 'pipelines' });
beforeEach(() => {
createComponent();
});
afterEach(() => {
vm.$destroy();
wrapper.destroy();
wrapper = null;
});
it('should render tabs', () => {
expect(vm.$el.querySelectorAll('li').length).toEqual(data.length);
expect(wrapper.findAll(GlTab)).toHaveLength(data.length);
});
it('should render active tab', () => {
expect(vm.$el.querySelector('.active .js-pipelines-tab-all')).toBeDefined();
expect(wrapper.find('.js-pipelines-tab-all').classes('active')).toBe(true);
});
it('should render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-all .badge').textContent.trim()).toEqual('1');
expect(vm.$el.querySelector('.js-pipelines-tab-pending .badge').textContent.trim()).toEqual(
'0',
);
expect(wrapper.find('.js-pipelines-tab-all').text()).toContain('1');
expect(wrapper.find('.js-pipelines-tab-pending').text()).toContain('0');
});
it('should not render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-running .badge')).toEqual(null);
expect(wrapper.find('.js-pipelines-tab-running .badge').exists()).toBe(false);
});
it('should trigger onTabClick', () => {
jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.$el.querySelector('.js-pipelines-tab-pending').click();
it('should trigger onTabClick', async () => {
await wrapper.find('.js-pipelines-tab-pending').trigger('click');
expect(vm.$emit).toHaveBeenCalledWith('onChangeTab', 'pending');
expect(wrapper.emitted('onChangeTab')).toEqual([['pending']]);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment