Commit 965bb0d6 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '330969-update-admin-runner-spec' into 'master'

Update admin runners spec

See merge request gitlab-org/gitlab!65738
parents 7d8e54ba b2040ca9
<script> <script>
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { __, s__ } from '~/locale'; import { formatNumber, sprintf, __, s__ } from '~/locale';
import { OPERATOR_IS_ONLY } from '~/vue_shared/components/filtered_search_bar/constants'; import { OPERATOR_IS_ONLY } from '~/vue_shared/components/filtered_search_bar/constants';
import FilteredSearch from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue'; import FilteredSearch from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';
import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue'; import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue';
...@@ -58,6 +58,10 @@ export default { ...@@ -58,6 +58,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
activeRunnersCount: {
type: Number,
required: true,
},
}, },
data() { data() {
// filtered_search_bar_root.vue may mutate the inital // filtered_search_bar_root.vue may mutate the inital
...@@ -119,6 +123,11 @@ export default { ...@@ -119,6 +123,11 @@ export default {
}, },
]; ];
}, },
activeRunnersMessage() {
return sprintf(__('Runners currently online: %{active_runners_count}'), {
active_runners_count: formatNumber(this.activeRunnersCount),
});
},
}, },
methods: { methods: {
onFilter(filters) { onFilter(filters) {
...@@ -144,16 +153,20 @@ export default { ...@@ -144,16 +153,20 @@ export default {
}; };
</script> </script>
<template> <template>
<filtered-search <div>
v-bind="$attrs" <filtered-search
:namespace="namespace" v-bind="$attrs"
recent-searches-storage-key="runners-search" :namespace="namespace"
:sort-options="$options.sortOptions" recent-searches-storage-key="runners-search"
:initial-filter-value="initialFilterValue" :sort-options="$options.sortOptions"
:initial-sort-by="initialSortBy" :initial-filter-value="initialFilterValue"
:tokens="searchTokens" :initial-sort-by="initialSortBy"
:search-input-placeholder="__('Search or filter results...')" :tokens="searchTokens"
@onFilter="onFilter" :search-input-placeholder="__('Search or filter results...')"
@onSort="onSort" data-testid="runners-filtered-search"
/> @onFilter="onFilter"
@onSort="onSort"
/>
<div class="gl-text-right" data-testid="active-runners-message">{{ activeRunnersMessage }}</div>
</div>
</template> </template>
<script> <script>
import { GlTable, GlTooltipDirective, GlSkeletonLoader } from '@gitlab/ui'; import { GlTable, GlTooltipDirective, GlSkeletonLoader } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { formatNumber, sprintf, __, s__ } from '~/locale'; import { formatNumber, __, s__ } from '~/locale';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import { RUNNER_JOB_COUNT_LIMIT } from '../constants'; import { RUNNER_JOB_COUNT_LIMIT } from '../constants';
import RunnerActionsCell from './cells/runner_actions_cell.vue'; import RunnerActionsCell from './cells/runner_actions_cell.vue';
...@@ -52,17 +52,6 @@ export default { ...@@ -52,17 +52,6 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
activeRunnersCount: {
type: Number,
required: true,
},
},
computed: {
activeRunnersMessage() {
return sprintf(__('Runners currently online: %{active_runners_count}'), {
active_runners_count: formatNumber(this.activeRunnersCount),
});
},
}, },
methods: { methods: {
formatProjectCount(projectCount) { formatProjectCount(projectCount) {
...@@ -101,12 +90,12 @@ export default { ...@@ -101,12 +90,12 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<div class="gl-text-right" data-testid="active-runners-message">{{ activeRunnersMessage }}</div>
<gl-table <gl-table
:busy="loading" :busy="loading"
:items="runners" :items="runners"
:fields="$options.fields" :fields="$options.fields"
:tbody-tr-attr="runnerTrAttr" :tbody-tr-attr="runnerTrAttr"
data-testid="runner-list"
stacked="md" stacked="md"
fixed fixed
> >
......
...@@ -12,7 +12,8 @@ export const initRunnerList = (selector = '#js-runner-list') => { ...@@ -12,7 +12,8 @@ export const initRunnerList = (selector = '#js-runner-list') => {
return null; return null;
} }
// TODO `activeRunnersCount` should be implemented using a GraphQL API. // TODO `activeRunnersCount` should be implemented using a GraphQL API
// https://gitlab.com/gitlab-org/gitlab/-/issues/333806
const { activeRunnersCount, registrationToken, runnerInstallHelpPage } = el.dataset; const { activeRunnersCount, registrationToken, runnerInstallHelpPage } = el.dataset;
const apolloProvider = new VueApollo({ const apolloProvider = new VueApollo({
......
...@@ -116,17 +116,17 @@ export default { ...@@ -116,17 +116,17 @@ export default {
</div> </div>
</div> </div>
<runner-filtered-search-bar v-model="search" namespace="admin_runners" /> <runner-filtered-search-bar
v-model="search"
namespace="admin_runners"
:active-runners-count="activeRunnersCount"
/>
<div v-if="noRunnersFound" class="gl-text-center gl-p-5"> <div v-if="noRunnersFound" class="gl-text-center gl-p-5">
{{ __('No runners found') }} {{ __('No runners found') }}
</div> </div>
<template v-else> <template v-else>
<runner-list <runner-list :runners="runners.items" :loading="runnersLoading" />
:runners="runners.items"
:loading="runnersLoading"
:active-runners-count="activeRunnersCount"
/>
<runner-pagination v-model="search.pagination" :page-info="runners.pageInfo" /> <runner-pagination v-model="search.pagination" :page-info="runners.pageInfo" />
</template> </template>
</div> </div>
......
This diff is collapsed.
...@@ -13,6 +13,7 @@ describe('RunnerList', () => { ...@@ -13,6 +13,7 @@ describe('RunnerList', () => {
const findFilteredSearch = () => wrapper.findComponent(FilteredSearch); const findFilteredSearch = () => wrapper.findComponent(FilteredSearch);
const findGlFilteredSearch = () => wrapper.findComponent(GlFilteredSearch); const findGlFilteredSearch = () => wrapper.findComponent(GlFilteredSearch);
const findSortOptions = () => wrapper.findAllComponents(GlDropdownItem); const findSortOptions = () => wrapper.findAllComponents(GlDropdownItem);
const findActiveRunnersMessage = () => wrapper.findByTestId('active-runners-message');
const mockDefaultSort = 'CREATED_DESC'; const mockDefaultSort = 'CREATED_DESC';
const mockOtherSort = 'CONTACTED_DESC'; const mockOtherSort = 'CONTACTED_DESC';
...@@ -20,6 +21,7 @@ describe('RunnerList', () => { ...@@ -20,6 +21,7 @@ describe('RunnerList', () => {
{ type: PARAM_KEY_STATUS, value: { data: 'ACTIVE', operator: '=' } }, { type: PARAM_KEY_STATUS, value: { data: 'ACTIVE', operator: '=' } },
{ type: 'filtered-search-term', value: { data: '' } }, { type: 'filtered-search-term', value: { data: '' } },
]; ];
const mockActiveRunnersCount = 2;
const createComponent = ({ props = {}, options = {} } = {}) => { const createComponent = ({ props = {}, options = {} } = {}) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
...@@ -30,6 +32,7 @@ describe('RunnerList', () => { ...@@ -30,6 +32,7 @@ describe('RunnerList', () => {
filters: [], filters: [],
sort: mockDefaultSort, sort: mockDefaultSort,
}, },
activeRunnersCount: mockActiveRunnersCount,
...props, ...props,
}, },
stubs: { stubs: {
...@@ -55,6 +58,18 @@ describe('RunnerList', () => { ...@@ -55,6 +58,18 @@ describe('RunnerList', () => {
expect(findFilteredSearch().props('namespace')).toBe('runners'); expect(findFilteredSearch().props('namespace')).toBe('runners');
}); });
it('Displays an active runner count', () => {
expect(findActiveRunnersMessage().text()).toBe(
`Runners currently online: ${mockActiveRunnersCount}`,
);
});
it('Displays a large active runner count', () => {
createComponent({ props: { activeRunnersCount: 2000 } });
expect(findActiveRunnersMessage().text()).toBe('Runners currently online: 2,000');
});
it('sets sorting options', () => { it('sets sorting options', () => {
const SORT_OPTIONS_COUNT = 2; const SORT_OPTIONS_COUNT = 2;
......
...@@ -12,7 +12,6 @@ const mockActiveRunnersCount = mockRunners.length; ...@@ -12,7 +12,6 @@ const mockActiveRunnersCount = mockRunners.length;
describe('RunnerList', () => { describe('RunnerList', () => {
let wrapper; let wrapper;
const findActiveRunnersMessage = () => wrapper.findByTestId('active-runners-message');
const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader); const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
const findTable = () => wrapper.findComponent(GlTable); const findTable = () => wrapper.findComponent(GlTable);
const findHeaders = () => wrapper.findAll('th'); const findHeaders = () => wrapper.findAll('th');
...@@ -40,18 +39,6 @@ describe('RunnerList', () => { ...@@ -40,18 +39,6 @@ describe('RunnerList', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('Displays active runner count', () => {
expect(findActiveRunnersMessage().text()).toBe(
`Runners currently online: ${mockActiveRunnersCount}`,
);
});
it('Displays a large active runner count', () => {
createComponent({ props: { activeRunnersCount: 2000 } });
expect(findActiveRunnersMessage().text()).toBe('Runners currently online: 2,000');
});
it('Displays headers', () => { it('Displays headers', () => {
const headerLabels = findHeaders().wrappers.map((w) => w.text()); const headerLabels = findHeaders().wrappers.map((w) => w.text());
......
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