Commit 9dbdde16 authored by Simon Knox's avatar Simon Knox

Merge branch 'refactor-project-avatar' into 'master'

Deprecate project_avatar component

See merge request gitlab-org/gitlab!65227
parents e7d07087 d647c904
<script> <script>
import ProjectAvatarDefault from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatarDefault from '~/vue_shared/components/deprecated_project_avatar/default.vue';
export default { export default {
components: { components: {
......
...@@ -3,6 +3,7 @@ import Identicon from '../identicon.vue'; ...@@ -3,6 +3,7 @@ import Identicon from '../identicon.vue';
import ProjectAvatarImage from './image.vue'; import ProjectAvatarImage from './image.vue';
export default { export default {
name: 'DeprecatedProjectAvatar',
components: { components: {
Identicon, Identicon,
ProjectAvatarImage, ProjectAvatarImage,
......
import ProjectAvatar from './project_avatar.vue';
export default {
component: ProjectAvatar,
title: 'vue_shared/components/project_avatar',
};
const Template = (args, { argTypes }) => ({
components: { ProjectAvatar },
props: Object.keys(argTypes),
template: '<project-avatar v-bind="$props" />',
});
export const Default = Template.bind({});
Default.args = {
projectAvatarUrl:
'https://gitlab.com/uploads/-/system/project/avatar/278964/logo-extra-whitespace.png?width=64',
projectName: 'GitLab',
};
export const FallbackAvatar = Template.bind({});
FallbackAvatar.args = {
projectName: 'GitLab',
};
export const EmptyAltTag = Template.bind({});
EmptyAltTag.args = {
...Default.args,
alt: '',
};
<script>
import { GlAvatar } from '@gitlab/ui';
export default {
components: {
GlAvatar,
},
props: {
projectName: {
type: String,
required: true,
},
projectAvatarUrl: {
type: String,
required: false,
default: '',
},
size: {
type: Number,
default: 32,
required: false,
},
alt: {
type: String,
required: false,
default: undefined,
},
},
computed: {
avatarAlt() {
return this.alt ?? this.projectName;
},
},
};
</script>
<template>
<gl-avatar
shape="rect"
:entity-name="projectName"
:src="projectAvatarUrl"
:alt="avatarAlt"
:size="size"
/>
</template>
...@@ -4,7 +4,7 @@ import { GlButton, GlIcon } from '@gitlab/ui'; ...@@ -4,7 +4,7 @@ import { GlButton, GlIcon } from '@gitlab/ui';
import { isString } from 'lodash'; import { isString } from 'lodash';
import highlight from '~/lib/utils/highlight'; import highlight from '~/lib/utils/highlight';
import { truncateNamespace } from '~/lib/utils/text_utility'; import { truncateNamespace } from '~/lib/utils/text_utility';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
export default { export default {
name: 'ProjectListItem', name: 'ProjectListItem',
......
<script> <script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import Avatar from '~/vue_shared/components/project_avatar/default.vue'; import Avatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from '../constants'; import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from '../constants';
import HiddenGroupsItem from './hidden_groups_item.vue'; import HiddenGroupsItem from './hidden_groups_item.vue';
......
<script> <script>
import { GlDropdown, GlDropdownItem, GlTooltipDirective, GlLink, GlIcon } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlTooltipDirective, GlLink, GlIcon } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
export default { export default {
components: { components: {
......
<script> <script>
import { GlButton, GlLink, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlLink, GlTooltipDirective } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
export default { export default {
components: { components: {
......
...@@ -3,7 +3,7 @@ import { GlLink, GlIcon } from '@gitlab/ui'; ...@@ -3,7 +3,7 @@ import { GlLink, GlIcon } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { numberToHumanSize, isOdd } from '~/lib/utils/number_utils'; import { numberToHumanSize, isOdd } from '~/lib/utils/number_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import StorageRow from './storage_row.vue'; import StorageRow from './storage_row.vue';
export default { export default {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { GlLink, GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlLink, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { ALERT_THRESHOLD, ERROR_THRESHOLD, WARNING_THRESHOLD } from '../constants'; import { ALERT_THRESHOLD, ERROR_THRESHOLD, WARNING_THRESHOLD } from '../constants';
import { formatUsageSize, usageRatioToThresholdLevel } from '../utils'; import { formatUsageSize, usageRatioToThresholdLevel } from '../utils';
......
...@@ -19,7 +19,7 @@ import { STORAGE_KEY } from '~/frequent_items/constants'; ...@@ -19,7 +19,7 @@ import { STORAGE_KEY } from '~/frequent_items/constants';
import { getTopFrequentItems } from '~/frequent_items/utils'; import { getTopFrequentItems } from '~/frequent_items/utils';
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import { __ } from '~/locale'; import { __ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { SEARCH_DEBOUNCE } from '../constants'; import { SEARCH_DEBOUNCE } from '../constants';
export default { export default {
......
...@@ -4,7 +4,7 @@ import projectsQuery from 'ee/security_dashboard/graphql/queries/instance_projec ...@@ -4,7 +4,7 @@ import projectsQuery from 'ee/security_dashboard/graphql/queries/instance_projec
import { PROJECT_LOADING_ERROR_MESSAGE } from 'ee/security_dashboard/helpers'; import { PROJECT_LOADING_ERROR_MESSAGE } from 'ee/security_dashboard/helpers';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
export default { export default {
i18n: { i18n: {
......
...@@ -3,7 +3,7 @@ import { GlLink, GlIcon } from '@gitlab/ui'; ...@@ -3,7 +3,7 @@ import { GlLink, GlIcon } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { numberToHumanSize, isOdd } from '~/lib/utils/number_utils'; import { numberToHumanSize, isOdd } from '~/lib/utils/number_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import StorageRow from './storage_row.vue'; import StorageRow from './storage_row.vue';
export default { export default {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { GlLink, GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlLink, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { ALERT_THRESHOLD, ERROR_THRESHOLD, WARNING_THRESHOLD } from '../constants'; import { ALERT_THRESHOLD, ERROR_THRESHOLD, WARNING_THRESHOLD } from '../constants';
import { formatUsageSize, usageRatioToThresholdLevel } from '../utils'; import { formatUsageSize, usageRatioToThresholdLevel } from '../utils';
......
...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import ApproversListItem from 'ee/approvals/components/approvers_list_item.vue'; import ApproversListItem from 'ee/approvals/components/approvers_list_item.vue';
import HiddenGroupsItem from 'ee/approvals/components/hidden_groups_item.vue'; import HiddenGroupsItem from 'ee/approvals/components/hidden_groups_item.vue';
import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from 'ee/approvals/constants'; import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from 'ee/approvals/constants';
import Avatar from '~/vue_shared/components/project_avatar/default.vue'; import Avatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
const TEST_USER = { const TEST_USER = {
id: 1, id: 1,
......
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import component from 'ee/environments_dashboard/components/dashboard/project_header.vue'; import component from 'ee/environments_dashboard/components/dashboard/project_header.vue';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
describe('Project Header', () => { describe('Project Header', () => {
let wrapper; let wrapper;
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import ProjectHeader from 'ee/operations/components/dashboard/project_header.vue'; import ProjectHeader from 'ee/operations/components/dashboard/project_header.vue';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { mockOneProject } from '../../mock_data'; import { mockOneProject } from '../../mock_data';
describe('project header component', () => { describe('project header component', () => {
......
...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils';
import Project from 'ee/other_storage_counter/components/project.vue'; import Project from 'ee/other_storage_counter/components/project.vue';
import StorageRow from 'ee/other_storage_counter/components/storage_row.vue'; import StorageRow from 'ee/other_storage_counter/components/storage_row.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { projects } from '../mock_data'; import { projects } from '../mock_data';
let wrapper; let wrapper;
......
...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import ProjectWithExcessStorage from 'ee/other_storage_counter/components/project_with_excess_storage.vue'; import ProjectWithExcessStorage from 'ee/other_storage_counter/components/project_with_excess_storage.vue';
import { formatUsageSize } from 'ee/other_storage_counter/utils'; import { formatUsageSize } from 'ee/other_storage_counter/utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { projects } from '../mock_data'; import { projects } from '../mock_data';
let wrapper; let wrapper;
......
...@@ -13,7 +13,7 @@ import Vuex from 'vuex'; ...@@ -13,7 +13,7 @@ import Vuex from 'vuex';
import CreateIssueForm from 'ee/related_items_tree/components/create_issue_form.vue'; import CreateIssueForm from 'ee/related_items_tree/components/create_issue_form.vue';
import createDefaultStore from 'ee/related_items_tree/store'; import createDefaultStore from 'ee/related_items_tree/store';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { import {
mockInitialConfig, mockInitialConfig,
......
...@@ -5,7 +5,7 @@ import ProjectList from 'ee/security_dashboard/components/instance/project_list. ...@@ -5,7 +5,7 @@ import ProjectList from 'ee/security_dashboard/components/instance/project_list.
import projectsQuery from 'ee/security_dashboard/graphql/queries/instance_projects.query.graphql'; import projectsQuery from 'ee/security_dashboard/graphql/queries/instance_projects.query.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
......
...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils';
import Project from 'ee/storage_counter/components/project.vue'; import Project from 'ee/storage_counter/components/project.vue';
import StorageRow from 'ee/storage_counter/components/storage_row.vue'; import StorageRow from 'ee/storage_counter/components/storage_row.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { projects } from '../mock_data'; import { projects } from '../mock_data';
let wrapper; let wrapper;
......
...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import ProjectWithExcessStorage from 'ee/storage_counter/components/project_with_excess_storage.vue'; import ProjectWithExcessStorage from 'ee/storage_counter/components/project_with_excess_storage.vue';
import { formatUsageSize } from 'ee/storage_counter/utils'; import { formatUsageSize } from 'ee/storage_counter/utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { projects } from '../mock_data'; import { projects } from '../mock_data';
let wrapper; let wrapper;
......
...@@ -3,7 +3,7 @@ import mountComponent from 'helpers/vue_mount_component_helper'; ...@@ -3,7 +3,7 @@ import mountComponent from 'helpers/vue_mount_component_helper';
import { projectData } from 'jest/ide/mock_data'; import { projectData } from 'jest/ide/mock_data';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { getFirstCharacterCapitalized } from '~/lib/utils/text_utility'; import { getFirstCharacterCapitalized } from '~/lib/utils/text_utility';
import ProjectAvatarDefault from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatarDefault from '~/vue_shared/components/deprecated_project_avatar/default.vue';
describe('ProjectAvatarDefault component', () => { describe('ProjectAvatarDefault component', () => {
const Component = Vue.extend(ProjectAvatarDefault); const Component = Vue.extend(ProjectAvatarDefault);
......
import { GlAvatar } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
const defaultProps = {
projectName: 'GitLab',
};
describe('ProjectAvatar', () => {
let wrapper;
const findGlAvatar = () => wrapper.findComponent(GlAvatar);
const createComponent = ({ props, attrs } = {}) => {
wrapper = shallowMount(ProjectAvatar, { propsData: { ...defaultProps, ...props }, attrs });
};
afterEach(() => {
wrapper.destroy();
});
it('renders GlAvatar with correct props', () => {
createComponent();
const avatar = findGlAvatar();
expect(avatar.exists()).toBe(true);
expect(avatar.props()).toMatchObject({
alt: defaultProps.projectName,
entityName: defaultProps.projectName,
size: 32,
src: '',
});
});
describe('with `size` prop', () => {
it('renders GlAvatar with specified `size` prop', () => {
const mockSize = 48;
createComponent({ props: { size: mockSize } });
const avatar = findGlAvatar();
expect(avatar.props('size')).toBe(mockSize);
});
});
describe('with `projectAvatarUrl` prop', () => {
it('renders GlAvatar with specified `src` prop', () => {
const mockProjectAvatarUrl = 'https://gitlab.com';
createComponent({ props: { projectAvatarUrl: mockProjectAvatarUrl } });
const avatar = findGlAvatar();
expect(avatar.props('src')).toBe(mockProjectAvatarUrl);
});
});
describe.each`
alt
${''}
${'custom-alt'}
`('when `alt` prop is "$alt"', ({ alt }) => {
it('renders GlAvatar with specified `alt` attribute', () => {
createComponent({ props: { alt } });
const avatar = findGlAvatar();
expect(avatar.props('alt')).toBe(alt);
});
});
});
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import ProjectAvatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import ProjectListItem from '~/vue_shared/components/project_selector/project_list_item.vue'; import ProjectListItem from '~/vue_shared/components/project_selector/project_list_item.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -53,7 +54,7 @@ describe('ProjectListItem component', () => { ...@@ -53,7 +54,7 @@ describe('ProjectListItem component', () => {
it(`renders the project avatar`, () => { it(`renders the project avatar`, () => {
wrapper = shallowMount(Component, options); wrapper = shallowMount(Component, options);
expect(wrapper.find('.js-project-avatar').exists()).toBe(true); expect(wrapper.findComponent(ProjectAvatar).exists()).toBe(true);
}); });
it(`renders a simple namespace name with a trailing slash`, () => { it(`renders a simple namespace name with a trailing slash`, () => {
......
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