Commit 81b4cccb authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '345120-registry-title-component-when-no-metadata-remove-the-empty-line' into 'master'

Registry Title: fix tag and spacing

See merge request gitlab-org/gitlab!74186
parents 5adcf589 25bc2b8a
...@@ -69,20 +69,23 @@ export default { ...@@ -69,20 +69,23 @@ export default {
/> />
<div class="gl-display-flex gl-flex-direction-column"> <div class="gl-display-flex gl-flex-direction-column">
<h1 class="gl-font-size-h1 gl-mt-3 gl-mb-2" data-testid="title"> <h2 class="gl-font-size-h1 gl-mt-3 gl-mb-0" data-testid="title">
<slot name="title">{{ title }}</slot> <slot name="title">{{ title }}</slot>
</h1> </h2>
<div <div
v-if="$slots['sub-header']" v-if="$slots['sub-header']"
class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-1" class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-3"
> >
<slot name="sub-header"></slot> <slot name="sub-header"></slot>
</div> </div>
</div> </div>
</div> </div>
<div class="gl-display-flex gl-flex-wrap gl-align-items-center gl-mt-3"> <div
v-if="metadataSlots.length > 0"
class="gl-display-flex gl-flex-wrap gl-align-items-center gl-mt-3"
>
<template v-if="!metadataLoading"> <template v-if="!metadataLoading">
<div <div
v-for="(row, metadataIndex) in metadataSlots" v-for="(row, metadataIndex) in metadataSlots"
......
...@@ -43,7 +43,7 @@ RSpec.describe 'Infrastructure Registry' do ...@@ -43,7 +43,7 @@ RSpec.describe 'Infrastructure Registry' do
expect(page).to have_current_path(project_infrastructure_registry_path(terraform_module.project, terraform_module)) expect(page).to have_current_path(project_infrastructure_registry_path(terraform_module.project, terraform_module))
expect(page).to have_css('.packages-app h1[data-testid="title"]', text: terraform_module.name) expect(page).to have_css('.packages-app h2[data-testid="title"]', text: terraform_module.name)
expect(page).to have_content('Provision instructions') expect(page).to have_content('Provision instructions')
expect(page).to have_content('Registry setup') expect(page).to have_content('Registry setup')
......
...@@ -19,15 +19,15 @@ exports[`PackageTitle renders with tags 1`] = ` ...@@ -19,15 +19,15 @@ exports[`PackageTitle renders with tags 1`] = `
<div <div
class="gl-display-flex gl-flex-direction-column" class="gl-display-flex gl-flex-direction-column"
> >
<h1 <h2
class="gl-font-size-h1 gl-mt-3 gl-mb-2" class="gl-font-size-h1 gl-mt-3 gl-mb-0"
data-testid="title" data-testid="title"
> >
@gitlab-org/package-15 @gitlab-org/package-15
</h1> </h2>
<div <div
class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-1" class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-3"
> >
<gl-icon-stub <gl-icon-stub
class="gl-mr-3" class="gl-mr-3"
...@@ -117,15 +117,15 @@ exports[`PackageTitle renders without tags 1`] = ` ...@@ -117,15 +117,15 @@ exports[`PackageTitle renders without tags 1`] = `
<div <div
class="gl-display-flex gl-flex-direction-column" class="gl-display-flex gl-flex-direction-column"
> >
<h1 <h2
class="gl-font-size-h1 gl-mt-3 gl-mb-2" class="gl-font-size-h1 gl-mt-3 gl-mb-0"
data-testid="title" data-testid="title"
> >
@gitlab-org/package-15 @gitlab-org/package-15
</h1> </h2>
<div <div
class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-1" class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-3"
> >
<gl-icon-stub <gl-icon-stub
class="gl-mr-3" class="gl-mr-3"
......
import { GlAvatar, GlSprintf, GlLink, GlSkeletonLoader } from '@gitlab/ui'; import { GlAvatar, GlSprintf, GlLink, GlSkeletonLoader } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import component from '~/vue_shared/components/registry/title_area.vue'; import component from '~/vue_shared/components/registry/title_area.vue';
describe('title area', () => { describe('title area', () => {
...@@ -7,18 +8,18 @@ describe('title area', () => { ...@@ -7,18 +8,18 @@ describe('title area', () => {
const DYNAMIC_SLOT = 'metadata-dynamic-slot'; const DYNAMIC_SLOT = 'metadata-dynamic-slot';
const findSubHeaderSlot = () => wrapper.find('[data-testid="sub-header"]'); const findSubHeaderSlot = () => wrapper.findByTestId('sub-header');
const findRightActionsSlot = () => wrapper.find('[data-testid="right-actions"]'); const findRightActionsSlot = () => wrapper.findByTestId('right-actions');
const findMetadataSlot = (name) => wrapper.find(`[data-testid="${name}"]`); const findMetadataSlot = (name) => wrapper.findByTestId(name);
const findTitle = () => wrapper.find('[data-testid="title"]'); const findTitle = () => wrapper.findByTestId('title');
const findAvatar = () => wrapper.find(GlAvatar); const findAvatar = () => wrapper.findComponent(GlAvatar);
const findInfoMessages = () => wrapper.findAll('[data-testid="info-message"]'); const findInfoMessages = () => wrapper.findAllByTestId('info-message');
const findDynamicSlot = () => wrapper.find(`[data-testid="${DYNAMIC_SLOT}`); const findDynamicSlot = () => wrapper.findByTestId(DYNAMIC_SLOT);
const findSlotOrderElements = () => wrapper.findAll('[slot-test]'); const findSlotOrderElements = () => wrapper.findAll('[slot-test]');
const findSkeletonLoader = () => wrapper.find(GlSkeletonLoader); const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
const mountComponent = ({ propsData = { title: 'foo' }, slots } = {}) => { const mountComponent = ({ propsData = { title: 'foo' }, slots } = {}) => {
wrapper = shallowMount(component, { wrapper = shallowMountExtended(component, {
propsData, propsData,
stubs: { GlSprintf }, stubs: { GlSprintf },
slots: { slots: {
...@@ -29,6 +30,12 @@ describe('title area', () => { ...@@ -29,6 +30,12 @@ describe('title area', () => {
}); });
}; };
const generateSlotMocks = (names) =>
names.reduce((acc, current) => {
acc[current] = `<div data-testid="${current}" />`;
return acc;
}, {});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
...@@ -40,6 +47,7 @@ describe('title area', () => { ...@@ -40,6 +47,7 @@ describe('title area', () => {
expect(findTitle().text()).toBe('foo'); expect(findTitle().text()).toBe('foo');
}); });
it('if slot is present uses slot', () => { it('if slot is present uses slot', () => {
mountComponent({ mountComponent({
slots: { slots: {
...@@ -88,24 +96,21 @@ describe('title area', () => { ...@@ -88,24 +96,21 @@ describe('title area', () => {
${['metadata-foo', 'metadata-bar']} ${['metadata-foo', 'metadata-bar']}
${['metadata-foo', 'metadata-bar', 'metadata-baz']} ${['metadata-foo', 'metadata-bar', 'metadata-baz']}
`('$slotNames metadata slots', ({ slotNames }) => { `('$slotNames metadata slots', ({ slotNames }) => {
const slotMocks = slotNames.reduce((acc, current) => { const slots = generateSlotMocks(slotNames);
acc[current] = `<div data-testid="${current}" />`;
return acc;
}, {});
it('exist when the slot is present', async () => { it('exist when the slot is present', async () => {
mountComponent({ slots: slotMocks }); mountComponent({ slots });
await wrapper.vm.$nextTick(); await nextTick();
slotNames.forEach((name) => { slotNames.forEach((name) => {
expect(findMetadataSlot(name).exists()).toBe(true); expect(findMetadataSlot(name).exists()).toBe(true);
}); });
}); });
it('is/are hidden when metadata-loading is true', async () => { it('is/are hidden when metadata-loading is true', async () => {
mountComponent({ slots: slotMocks, propsData: { title: 'foo', metadataLoading: true } }); mountComponent({ slots, propsData: { title: 'foo', metadataLoading: true } });
await wrapper.vm.$nextTick(); await nextTick();
slotNames.forEach((name) => { slotNames.forEach((name) => {
expect(findMetadataSlot(name).exists()).toBe(false); expect(findMetadataSlot(name).exists()).toBe(false);
}); });
...@@ -113,14 +118,20 @@ describe('title area', () => { ...@@ -113,14 +118,20 @@ describe('title area', () => {
}); });
describe('metadata skeleton loader', () => { describe('metadata skeleton loader', () => {
it('is hidden when metadata loading is false', () => { const slots = generateSlotMocks(['metadata-foo']);
mountComponent();
it('is hidden when metadata loading is false', async () => {
mountComponent({ slots });
await nextTick();
expect(findSkeletonLoader().exists()).toBe(false); expect(findSkeletonLoader().exists()).toBe(false);
}); });
it('is shown when metadata loading is true', () => { it('is shown when metadata loading is true', async () => {
mountComponent({ propsData: { metadataLoading: true } }); mountComponent({ propsData: { metadataLoading: true }, slots });
await nextTick();
expect(findSkeletonLoader().exists()).toBe(true); expect(findSkeletonLoader().exists()).toBe(true);
}); });
...@@ -143,7 +154,7 @@ describe('title area', () => { ...@@ -143,7 +154,7 @@ describe('title area', () => {
// updating the slots like we do on line 141 does not cause the updated lifecycle-hook to be triggered // updating the slots like we do on line 141 does not cause the updated lifecycle-hook to be triggered
wrapper.vm.$forceUpdate(); wrapper.vm.$forceUpdate();
await wrapper.vm.$nextTick(); await nextTick();
expect(findDynamicSlot().exists()).toBe(true); expect(findDynamicSlot().exists()).toBe(true);
}); });
...@@ -163,7 +174,7 @@ describe('title area', () => { ...@@ -163,7 +174,7 @@ describe('title area', () => {
// updating the slots like we do on line 159 does not cause the updated lifecycle-hook to be triggered // updating the slots like we do on line 159 does not cause the updated lifecycle-hook to be triggered
wrapper.vm.$forceUpdate(); wrapper.vm.$forceUpdate();
await wrapper.vm.$nextTick(); await nextTick();
expect(findSlotOrderElements().at(0).attributes('data-testid')).toBe(DYNAMIC_SLOT); expect(findSlotOrderElements().at(0).attributes('data-testid')).toBe(DYNAMIC_SLOT);
expect(findSlotOrderElements().at(1).attributes('data-testid')).toBe('metadata-foo'); expect(findSlotOrderElements().at(1).attributes('data-testid')).toBe('metadata-foo');
......
...@@ -28,7 +28,7 @@ RSpec.shared_examples 'package details link' do |property| ...@@ -28,7 +28,7 @@ RSpec.shared_examples 'package details link' do |property|
expect(page).to have_current_path(project_package_path(package.project, package)) expect(page).to have_current_path(project_package_path(package.project, package))
expect(page).to have_css('.packages-app h1[data-testid="title"]', text: package.name) expect(page).to have_css('.packages-app h2[data-testid="title"]', text: package.name)
expect(page).to have_content('Installation') expect(page).to have_content('Installation')
expect(page).to have_content('Registry setup') expect(page).to have_content('Registry setup')
......
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