diff options
Diffstat (limited to 'spec/frontend')
9 files changed, 294 insertions, 22 deletions
diff --git a/spec/frontend/analytics/shared/components/date_ranges_dropdown_spec.js b/spec/frontend/analytics/shared/components/date_ranges_dropdown_spec.js index 63407900be7..3c622983cad 100644 --- a/spec/frontend/analytics/shared/components/date_ranges_dropdown_spec.js +++ b/spec/frontend/analytics/shared/components/date_ranges_dropdown_spec.js @@ -135,6 +135,11 @@ describe('DateRangesDropdown', () => { expect(wrapper.findByText(`${expectedDaysCount} days selected`).exists()).toBe(true); }, ); + + it('should not rendered the indicator if disableSelectedDayCount is set', () => { + createComponent({ props: { disableSelectedDayCount: true, selected: lastWeekValue } }); + expect(findDaysSelectedCount().exists()).toBe(false); + }); }); describe('when the `tooltip` prop is set', () => { diff --git a/spec/frontend/fixtures/namespaces.rb b/spec/frontend/fixtures/namespaces.rb index 9858e3241cb..15d7d304035 100644 --- a/spec/frontend/fixtures/namespaces.rb +++ b/spec/frontend/fixtures/namespaces.rb @@ -2,11 +2,132 @@ require 'spec_helper' -RSpec.describe 'Jobs (JavaScript fixtures)' do +RSpec.describe 'Namespaces (JavaScript fixtures)', feature_category: :groups_and_projects do include ApiHelpers include JavaScriptFixturesHelpers include GraphqlHelpers + runners_token = 'runnerstoken:intabulasreferre' + + let_it_be(:namespace) { create(:namespace, :with_root_storage_statistics, name: 'frontend-fixtures') } + + let_it_be(:project_boilerplate) do + create( + :project, + name: 'Html5 Boilerplate', + path: 'html5-boilerplate', + namespace: namespace, + runners_token: runners_token + ) + end + + let_it_be(:project_twitter) do + create( + :project, + name: 'Twitter', + path: 'twitter', + namespace: namespace, + runners_token: runners_token + ) + end + + let_it_be(:user) { project_boilerplate.owner } + + describe 'Storage', feature_category: :consumables_cost_management do + describe GraphQL::Query, type: :request do + include GraphqlHelpers + base_input_path = 'usage_quotas/storage/queries/' + base_output_path = 'graphql/usage_quotas/storage/' + + context 'for namespace storage statistics query' do + before do + if Gitlab.ee? + namespace.update!( + additional_purchased_storage_size: 10_240 + ) + end + + namespace.root_storage_statistics.update!( + storage_size: 4.gigabytes, + container_registry_size: 1200.megabytes, + registry_size_estimated: false, + dependency_proxy_size: 1300.megabytes, + repository_size: 100.megabytes, + lfs_objects_size: 100.megabytes, + wiki_size: 100.megabytes, + build_artifacts_size: 100.megabytes, + packages_size: 100.megabytes, + snippets_size: 100.megabytes, + pipeline_artifacts_size: 100.megabytes, + uploads_size: 100.megabytes, + notification_level: "warning" + ) + end + + query_name = 'namespace_storage.query.graphql' + + it "#{base_output_path}#{query_name}.json" do + query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?) + + post_graphql( + query, + current_user: user, + variables: { + fullPath: namespace.full_path + } + ) + + expect_graphql_errors_to_be_empty + end + end + + context 'for project storage statistics query' do + before do + project_twitter.update!( + repository_size_limit: 100_000 + ) + project_twitter.statistics.update!( + repository_size: 209_710, + lfs_objects_size: 209_720, + build_artifacts_size: 1_272_375, + pipeline_artifacts_size: 0, + wiki_size: 0, + packages_size: 0 + ) + + project_boilerplate.update!( + repository_size_limit: 100_000 + ) + project_boilerplate.statistics.update!( + repository_size: 0, + lfs_objects_size: 0, + build_artifacts_size: 1_272_375, + pipeline_artifacts_size: 0, + wiki_size: 0, + packages_size: 0 + ) + end + + query_name = 'project_list_storage.query.graphql' + + it "#{base_output_path}#{query_name}.json" do + query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?) + + post_graphql( + query, + current_user: user, + variables: { + fullPath: namespace.full_path, + first: 10 + } + ) + + expect_graphql_errors_to_be_empty + end + end + end + end + describe API::Projects, type: :request do let_it_be(:user) { create(:user) } diff --git a/spec/frontend/fixtures/projects.rb b/spec/frontend/fixtures/projects.rb index 8cd651c5b36..440902ffa81 100644 --- a/spec/frontend/fixtures/projects.rb +++ b/spec/frontend/fixtures/projects.rb @@ -2,16 +2,41 @@ require 'spec_helper' -RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do +RSpec.describe 'Projects (JavaScript fixtures)', type: :controller, feature_category: :groups_and_projects do include ApiHelpers include JavaScriptFixturesHelpers runners_token = 'runnerstoken:intabulasreferre' let(:namespace) { create(:namespace, name: 'frontend-fixtures') } - let(:project) { create(:project, namespace: namespace, path: 'builds-project', runners_token: runners_token, avatar: fixture_file_upload('spec/fixtures/dk.png', 'image/png')) } - let(:project_with_repo) { create(:project, :repository, description: 'Code and stuff', avatar: fixture_file_upload('spec/fixtures/dk.png', 'image/png')) } - let(:project_variable_populated) { create(:project, namespace: namespace, path: 'builds-project2', runners_token: runners_token) } + let(:project) do + create( + :project, + namespace: namespace, + path: 'builds-project', + runners_token: runners_token, + avatar: fixture_file_upload('spec/fixtures/dk.png', 'image/png') + ) + end + + let(:project_with_repo) do + create( + :project, + :repository, + description: 'Code and stuff', + avatar: fixture_file_upload('spec/fixtures/dk.png', 'image/png') + ) + end + + let(:project_variable_populated) do + create( + :project, + namespace: namespace, + path: 'builds-project2', + runners_token: runners_token + ) + end + let(:user) { project.first_owner } render_views @@ -48,7 +73,7 @@ RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do describe GraphQL::Query, type: :request do include GraphqlHelpers - context 'access token projects query' do + context 'for access token projects query' do before do project_variable_populated.add_maintainer(user) end @@ -70,7 +95,7 @@ RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do describe 'Storage', feature_category: :consumables_cost_management do describe GraphQL::Query, type: :request do include GraphqlHelpers - context 'project storage statistics query' do + context 'for project storage statistics query' do before do project.statistics.update!( repository_size: 3_900_000, @@ -89,7 +114,7 @@ RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do query_name = 'project_storage.query.graphql' it "#{base_output_path}#{query_name}.json" do - query = get_graphql_query_as_string("#{base_input_path}#{query_name}") + query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?) post_graphql(query, current_user: user, variables: { fullPath: project.full_path }) diff --git a/spec/frontend/observability/utils_spec.js b/spec/frontend/observability/utils_spec.js new file mode 100644 index 00000000000..38c14ed9ca1 --- /dev/null +++ b/spec/frontend/observability/utils_spec.js @@ -0,0 +1,35 @@ +import { periodToDate } from '~/observability/utils'; + +describe('periodToDate', () => { + const realDateNow = Date.now; + + const MOCK_NOW_DATE = new Date('2023-10-09 15:30:00'); + + beforeEach(() => { + global.Date.now = jest.fn().mockReturnValue(MOCK_NOW_DATE); + }); + + afterEach(() => { + global.Date.now = realDateNow; + }); + it.each` + periodLabel | period | expectedMinDate + ${'minutes (m)'} | ${'30m'} | ${new Date('2023-10-09 15:00:00')} + ${'hours (h)'} | ${'2h'} | ${new Date('2023-10-09 13:30:00')} + ${'days (d)'} | ${'7d'} | ${new Date('2023-10-02 15:30:00')} + `('should return the correct date range for $periodLabel', ({ period, expectedMinDate }) => { + const result = periodToDate(period); + expect(result.min).toEqual(expectedMinDate); + expect(result.max).toEqual(MOCK_NOW_DATE); + }); + + it('should return an empty object if period value is not a positive integer', () => { + expect(periodToDate('')).toEqual({}); + expect(periodToDate('-5d')).toEqual({}); + expect(periodToDate('invalid')).toEqual({}); + }); + + it('should return an empty object if unit is not "m", "h", or "d"', () => { + expect(periodToDate('2w')).toEqual({}); + }); +}); diff --git a/spec/frontend/usage_quotas/components/search_and_sort_bar/search_and_sort_bar_spec.js b/spec/frontend/usage_quotas/components/search_and_sort_bar/search_and_sort_bar_spec.js new file mode 100644 index 00000000000..2b3e04b329a --- /dev/null +++ b/spec/frontend/usage_quotas/components/search_and_sort_bar/search_and_sort_bar_spec.js @@ -0,0 +1,83 @@ +import { shallowMount } from '@vue/test-utils'; +import SearchAndSortBar from '~/usage_quotas/components/search_and_sort_bar/search_and_sort_bar.vue'; +import { FILTERED_SEARCH_TERM } from '~/vue_shared/components/filtered_search_bar/constants'; +import FilteredSortContainerRoot from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue'; + +describe('SearchAndSortBar', () => { + let wrapper; + + const defaultProps = { + namespace: '42', + searchInputPlaceholder: 'Search term', + }; + + const findFilteredSortContainerRoot = () => wrapper.findComponent(FilteredSortContainerRoot); + + const createComponent = (config) => { + const { props = {}, listeners = {} } = config; + + wrapper = shallowMount(SearchAndSortBar, { + propsData: { ...defaultProps, ...props }, + listeners, + }); + }; + + describe('onFilter', () => { + const onFilter = jest.fn(); + + beforeEach(() => { + createComponent({ + listeners: { onFilter }, + }); + }); + + it('parses and propagates emitted search event', () => { + const filteredSortContainerRoot = findFilteredSortContainerRoot(); + filteredSortContainerRoot.vm.$emit('onFilter', [ + { + id: 'token-1', + type: FILTERED_SEARCH_TERM, + value: { + data: 'abc', + }, + }, + { + id: 'token-2', + type: FILTERED_SEARCH_TERM, + value: { + data: 'def', + }, + }, + { + id: 'token-3', + type: FILTERED_SEARCH_TERM, + value: { + data: '123', + }, + }, + ]); + + expect(onFilter).toHaveBeenCalledTimes(1); + expect(onFilter).toHaveBeenCalledWith('abc def 123'); + }); + }); + + describe('onSort', () => { + const onSort = jest.fn(); + + beforeEach(() => { + createComponent({ + listeners: { onSort }, + }); + }); + + it('propagates emitted sorting value', () => { + const SORTING_VALUE = 'name_desc'; + const filteredSortContainerRoot = findFilteredSortContainerRoot(); + filteredSortContainerRoot.vm.$emit('onSort', SORTING_VALUE); + + expect(onSort).toHaveBeenCalledTimes(1); + expect(onSort).toHaveBeenCalledWith(SORTING_VALUE); + }); + }); +}); diff --git a/spec/frontend/usage_quotas/storage/components/namespace_storage_app_spec.js b/spec/frontend/usage_quotas/storage/components/namespace_storage_app_spec.js index 544666ddc5d..f9bc3d4da85 100644 --- a/spec/frontend/usage_quotas/storage/components/namespace_storage_app_spec.js +++ b/spec/frontend/usage_quotas/storage/components/namespace_storage_app_spec.js @@ -4,20 +4,16 @@ import NamespaceStorageApp from '~/usage_quotas/storage/components/namespace_sto import StorageUsageStatistics from '~/usage_quotas/storage/components/storage_usage_statistics.vue'; import DependencyProxyUsage from '~/usage_quotas/storage/components/dependency_proxy_usage.vue'; import ContainerRegistryUsage from '~/usage_quotas/storage/components/container_registry_usage.vue'; -import { defaultNamespaceProvideValues } from '../mock_data'; +import { + defaultNamespaceProvideValues, + mockGetNamespaceStorageGraphQLResponse, +} from '../mock_data'; const defaultProps = { namespaceLoadingError: false, projectsLoadingError: false, isNamespaceStorageStatisticsLoading: false, - // hardcoding object until we move test_fixtures from ee/ to here - namespace: { - rootStorageStatistics: { - storageSize: 1234, - containerRegistrySize: 111, - containerRegistrySizeIsEstimated: false, - }, - }, + namespace: mockGetNamespaceStorageGraphQLResponse.data.namespace, }; describe('NamespaceStorageApp', () => { diff --git a/spec/frontend/usage_quotas/storage/components/storage_usage_overview_card_spec.js b/spec/frontend/usage_quotas/storage/components/storage_usage_overview_card_spec.js index c79b6b94ac1..2dde568b1d2 100644 --- a/spec/frontend/usage_quotas/storage/components/storage_usage_overview_card_spec.js +++ b/spec/frontend/usage_quotas/storage/components/storage_usage_overview_card_spec.js @@ -3,14 +3,14 @@ import { numberToHumanSize } from '~/lib/utils/number_utils'; import StorageUsageOverviewCard from '~/usage_quotas/storage/components/storage_usage_overview_card.vue'; import NumberToHumanSize from '~/vue_shared/components/number_to_human_size/number_to_human_size.vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { mockGetNamespaceStorageGraphQLResponse } from '../mock_data'; describe('StorageUsageOverviewCard', () => { /** @type {import('helpers/vue_test_utils_helper').ExtendedWrapper} */ let wrapper; const defaultProps = { - purchasedStorage: 0, - // hardcoding value until we move test_fixtures from ee/ to here - usedStorage: 1234, + usedStorage: + mockGetNamespaceStorageGraphQLResponse.data.namespace.rootStorageStatistics.storageSize, loading: false, }; diff --git a/spec/frontend/usage_quotas/storage/components/storage_usage_statistics_spec.js b/spec/frontend/usage_quotas/storage/components/storage_usage_statistics_spec.js index 73d02dc273f..bb96a12aaf2 100644 --- a/spec/frontend/usage_quotas/storage/components/storage_usage_statistics_spec.js +++ b/spec/frontend/usage_quotas/storage/components/storage_usage_statistics_spec.js @@ -1,10 +1,11 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import StorageUsageStatistics from '~/usage_quotas/storage/components/storage_usage_statistics.vue'; import StorageUsageOverviewCard from '~/usage_quotas/storage/components/storage_usage_overview_card.vue'; +import { mockGetNamespaceStorageGraphQLResponse } from '../mock_data'; const defaultProps = { - // hardcoding value until we move test_fixtures from ee/ to here - usedStorage: 1234, + usedStorage: + mockGetNamespaceStorageGraphQLResponse.data.namespace.rootStorageStatistics.storageSize, loading: false, }; diff --git a/spec/frontend/usage_quotas/storage/mock_data.js b/spec/frontend/usage_quotas/storage/mock_data.js index 7847ddbe0a4..e7886614575 100644 --- a/spec/frontend/usage_quotas/storage/mock_data.js +++ b/spec/frontend/usage_quotas/storage/mock_data.js @@ -1,6 +1,11 @@ import mockGetProjectStorageStatisticsGraphQLResponse from 'test_fixtures/graphql/usage_quotas/storage/project_storage.query.graphql.json'; +import mockGetNamespaceStorageGraphQLResponse from 'test_fixtures/graphql/usage_quotas/storage/namespace_storage.query.graphql.json'; +import mockGetProjectListStorageGraphQLResponse from 'test_fixtures/graphql/usage_quotas/storage/project_list_storage.query.graphql.json'; export { mockGetProjectStorageStatisticsGraphQLResponse }; +export { mockGetNamespaceStorageGraphQLResponse }; +export { mockGetProjectListStorageGraphQLResponse }; + export const mockEmptyResponse = { data: { project: null } }; export const defaultProjectProvideValues = { @@ -9,4 +14,5 @@ export const defaultProjectProvideValues = { export const defaultNamespaceProvideValues = { userNamespace: false, + namespaceId: '42', }; |