Commit f822f197 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Luke Duncalfe

Move DA test data to fixtures

In this commit we create a graphql
fixture for the DevOps Adoption enabled
namespace data and migrate the tests to
make use of this generated data.

https://gitlab.com/gitlab-org/gitlab/-/issues/336767
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70362
parent a5aa831f
......@@ -170,7 +170,7 @@ describe('DevopsAdoptionAddDropdown', () => {
it('makes a request to enable the selected group', () => {
expect(mutateAdd).toHaveBeenCalledWith({
displayNamespaceId: groupGid,
namespaceIds: ['gid://gitlab/Group/1'],
namespaceIds: [groupGids[0]],
});
});
......
......@@ -65,7 +65,9 @@ describe('DevopsAdoptionOverviewTable', () => {
it('displays the correct name', () => {
createComponent();
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe('Group 1');
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe(
devopsAdoptionNamespaceData.nodes[0].namespace.fullName,
);
});
describe('"This group" badge', () => {
......
......@@ -110,7 +110,9 @@ describe('DevopsAdoptionTable', () => {
it('displays the correct name', () => {
createComponent();
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe('Group 1');
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe(
devopsAdoptionNamespaceData.nodes[0].namespace.fullName,
);
});
describe('"This group" badge', () => {
......@@ -220,13 +222,17 @@ describe('DevopsAdoptionTable', () => {
});
it('sorts the namespaces by name', async () => {
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe('Group 1');
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe(
devopsAdoptionNamespaceData.nodes[0].namespace.fullName,
);
headers.at(0).trigger('click');
await nextTick();
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe('Group 2');
expect(findCol(TABLE_TEST_IDS_NAMESPACE).text()).toBe(
devopsAdoptionNamespaceData.nodes[1].namespace.fullName,
);
});
it('should update local storage when the sort column changes', async () => {
......
export const groupData = [
{ id: 1, full_name: 'Foo' },
{ id: 2, full_name: 'Bar' },
];
import { DEVOPS_ADOPTION_TABLE_CONFIGURATION } from 'ee/analytics/devops_report/devops_adoption/constants';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
export const groupNodes = [
{
__typename: 'Group',
full_name: 'Foo',
id: 1,
},
{
__typename: 'Group',
full_name: 'Bar',
id: 2,
},
];
const json = getJSONFixture(
'graphql/analytics/devops_report/devops_adoption/graphql/queries/devops_adoption_enabled_namespaces.query.graphql.json',
);
export const groupNodeLabelValues = [
{ label: 'Foo', value: 1 },
{ label: 'Bar', value: 2 },
];
export const devopsAdoptionNamespaceData = json.data.devopsAdoptionEnabledNamespaces;
export const groupIds = [1, 2];
export const groupData = devopsAdoptionNamespaceData.nodes.map((node) => {
return {
fullName: node.namespace.fullName,
id: getIdFromGraphQLId(node.namespace.id),
};
});
export const groupGids = ['gid://gitlab/Group/1', 'gid://gitlab/Group/2'];
export const groupNodes = groupData.map((group) => {
return {
__typename: 'Group',
...group,
};
});
export const devopsAdoptionNamespaceData = {
nodes: [
{
id: 'gid://gitlab/EnabledNamespace/1',
namespace: {
fullName: 'Group 1',
id: 'gid://gitlab/Group/1',
},
latestSnapshot: {
issueOpened: true,
mergeRequestOpened: true,
mergeRequestApproved: false,
runnerConfigured: true,
pipelineSucceeded: false,
deploySucceeded: false,
codeOwnersUsedCount: 0,
sastEnabledCount: 0,
dastEnabledCount: 0,
coverageFuzzingEnabledCount: 0,
dependencyScanningEnabledCount: 0,
recordedAt: '2020-10-31T23:59:59Z',
__typename: 'latestSnapshot',
},
__typename: 'devopsAdoptionEnabledNamespace',
},
{
id: 'gid://gitlab/EnabledNamespace/2',
namespace: {
fullName: 'Group 2',
id: 'gid://gitlab/Group/2',
},
latestSnapshot: null,
__typename: 'devopsAdoptionEnabledNamespace',
},
],
__typename: 'devopsAdoptionEnabledNamespaces',
};
export const groupGids = devopsAdoptionNamespaceData.nodes.map((node) => node.namespace.id);
export const devopsAdoptionTableHeaders = [
{
......@@ -103,54 +63,21 @@ export const dataErrorMessage = 'Name already taken.';
export const genericDeleteErrorMessage =
'An error occurred while removing the group. Please try again.';
const firstNodelatestSnapshot = devopsAdoptionNamespaceData.nodes[0].latestSnapshot;
const sortedFeatures = DEVOPS_ADOPTION_TABLE_CONFIGURATION.reduce(
(features, section) => [...features, ...section.cols],
[],
);
export const overallAdoptionData = {
displayMeta: false,
featureMeta: [
{
adopted: false,
title: 'Approvals',
},
{
adopted: false,
title: 'Code owners',
},
{
adopted: true,
title: 'Issues',
},
{
adopted: true,
title: 'MRs',
},
{
adopted: false,
title: 'DAST',
},
{
adopted: false,
title: 'Dependency Scanning',
},
{
adopted: false,
title: 'Fuzz Testing',
},
{
adopted: false,
title: 'SAST',
},
{
adopted: false,
title: 'Deploys',
},
{
adopted: false,
title: 'Pipelines',
},
{
adopted: true,
title: 'Runners',
},
],
featureMeta: sortedFeatures.map((feature) => {
return {
title: feature.label,
adopted: Boolean(firstNodelatestSnapshot[feature.key]),
};
}),
icon: 'tanuki',
title: 'Overall adoption',
variant: 'primary',
......
......@@ -39,7 +39,6 @@ describe('deleteEnabledNamespacesFromCache', () => {
expect.not.objectContaining({
data: {
devopsAdoptionEnabledNamespaces: {
__typename: 'devopsAdoptionEnabledNamespaces',
nodes: devopsAdoptionNamespaceData.nodes,
},
},
......@@ -49,7 +48,6 @@ describe('deleteEnabledNamespacesFromCache', () => {
expect.objectContaining({
data: {
devopsAdoptionEnabledNamespaces: {
__typename: 'devopsAdoptionEnabledNamespaces',
// Remove the item at the first index
nodes: devopsAdoptionNamespaceData.nodes.slice(1),
},
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'DevOps Adoption (GraphQL fixtures)' do
describe GraphQL::Query, type: :request do
include ApiHelpers
include GraphqlHelpers
include JavaScriptFixturesHelpers
let_it_be(:current_user) { create(:user, :admin) }
let_it_be(:group) { create(:group, name: 'my-group') }
let_it_be(:sub_group) { create(:group, parent: group, name: 'my-sub-group') }
let_it_be(:enabled_namespace) do
create(:devops_adoption_enabled_namespace, namespace: group, display_namespace: group)
end
let_it_be(:second_enabled_namespace) do
create(:devops_adoption_enabled_namespace, namespace: sub_group, display_namespace: group)
end
let_it_be(:expected_metrics) do
result = {}
Analytics::DevopsAdoption::Snapshot::BOOLEAN_METRICS.each.with_index do |m, i|
result[m] = i.odd?
end
Analytics::DevopsAdoption::Snapshot::NUMERIC_METRICS.each do |m|
result[m] = rand(10)
end
result[:total_projects_count] += 10
result
end
let_it_be(:snapshot) do
create(:devops_adoption_snapshot, namespace: group, **expected_metrics, end_time: DateTime.parse('2021-01-31').end_of_month)
end
before do
clean_frontend_fixtures('graphql/analytics/devops_report/devops_adoption/')
stub_licensed_features(instance_level_devops_adoption: true, group_level_devops_adoption: true)
end
path = 'analytics/devops_report/devops_adoption/graphql/queries/devops_adoption_enabled_namespaces.query.graphql'
it "graphql/#{path}.json" do
query = get_graphql_query_as_string(path, ee: true)
travel_to(DateTime.parse('2021-02-02')) do
post_graphql(query, current_user: current_user, variables: { displayNamespaceId: group.to_gid.to_s })
end
expect_graphql_errors_to_be_empty
end
end
end
......@@ -42,9 +42,12 @@ module JavaScriptFixturesHelpers
# Public: Reads a GraphQL query from the filesystem as a string
#
# query_path - file path to the GraphQL query, relative to `app/assets/javascripts`
def get_graphql_query_as_string(query_path)
path = Rails.root / 'app/assets/javascripts' / query_path
# query_path - file path to the GraphQL query, relative to `app/assets/javascripts`.
# ee - boolean, when true `query_path` will be looked up in `/ee`.
def get_graphql_query_as_string(query_path, ee: false)
base = (ee ? 'ee/' : '') + 'app/assets/javascripts'
path = Rails.root / base / query_path
queries = Gitlab::Graphql::Queries.find(path)
if queries.length == 1
queries.first.text(mode: Gitlab.ee? ? :ee : :ce )
......
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