Commit e37f5d99 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'afontaine/environment-auto-stop-at' into 'master'

Display when environments will auto-stop

See merge request gitlab-org/gitlab!78913
parents 688e227d 010b39f7
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import { truncate } from '~/lib/utils/text_utility'; import { truncate } from '~/lib/utils/text_utility';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import isLastDeployment from '../graphql/queries/is_last_deployment.query.graphql'; import isLastDeployment from '../graphql/queries/is_last_deployment.query.graphql';
import ExternalUrl from './environment_external_url.vue'; import ExternalUrl from './environment_external_url.vue';
import Actions from './environment_actions.vue'; import Actions from './environment_actions.vue';
...@@ -35,6 +36,7 @@ export default { ...@@ -35,6 +36,7 @@ export default {
Monitoring, Monitoring,
Pin, Pin,
Terminal, Terminal,
TimeAgoTooltip,
Delete, Delete,
}, },
directives: { directives: {
...@@ -66,6 +68,7 @@ export default { ...@@ -66,6 +68,7 @@ export default {
emptyState: s__( emptyState: s__(
'Environments|There are no deployments for this environment yet. %{linkStart}Learn more about setting up deployments.%{linkEnd}', 'Environments|There are no deployments for this environment yet. %{linkStart}Learn more about setting up deployments.%{linkEnd}',
), ),
autoStopIn: s__('Environment|Auto stop %{time}'),
}, },
data() { data() {
return { visible: false }; return { visible: false };
...@@ -185,7 +188,14 @@ export default { ...@@ -185,7 +188,14 @@ export default {
{{ displayName }} {{ displayName }}
</gl-link> </gl-link>
</div> </div>
<div> <div class="gl-display-flex gl-align-items-center">
<p v-if="canShowAutoStopDate" class="gl-font-sm gl-text-gray-700 gl-mr-5 gl-mb-0">
<gl-sprintf :message="$options.i18n.autoStopIn">
<template #time>
<time-ago-tooltip :time="environment.autoStopAt" css-class="gl-font-weight-bold" />
</template>
</gl-sprintf>
</p>
<div class="btn-group table-action-buttons" role="group"> <div class="btn-group table-action-buttons" role="group">
<external-url <external-url
v-if="externalUrl" v-if="externalUrl"
......
...@@ -13794,6 +13794,9 @@ msgstr "" ...@@ -13794,6 +13794,9 @@ msgstr ""
msgid "Environments|protected" msgid "Environments|protected"
msgstr "" msgstr ""
msgid "Environment|Auto stop %{time}"
msgstr ""
msgid "Epic" msgid "Epic"
msgstr "" msgstr ""
......
...@@ -4,7 +4,8 @@ import { GlCollapse, GlIcon } from '@gitlab/ui'; ...@@ -4,7 +4,8 @@ import { GlCollapse, GlIcon } from '@gitlab/ui';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper'; import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper';
import { stubTransition } from 'helpers/stub_transition'; import { stubTransition } from 'helpers/stub_transition';
import { __, s__ } from '~/locale'; import { formatDate, getTimeago } from '~/lib/utils/datetime_utility';
import { __, s__, sprintf } from '~/locale';
import EnvironmentItem from '~/environments/components/new_environment_item.vue'; import EnvironmentItem from '~/environments/components/new_environment_item.vue';
import Deployment from '~/environments/components/deployment.vue'; import Deployment from '~/environments/components/deployment.vue';
import { resolvedEnvironment } from './graphql/mock_data'; import { resolvedEnvironment } from './graphql/mock_data';
...@@ -173,25 +174,92 @@ describe('~/environments/components/new_environment_item.vue', () => { ...@@ -173,25 +174,92 @@ describe('~/environments/components/new_environment_item.vue', () => {
}); });
describe('pin', () => { describe('pin', () => {
it('shows the option to pin the environment if there is an autostop date', () => { describe('with autostop', () => {
wrapper = createWrapper({ let environment;
propsData: {
environment: { ...resolvedEnvironment, autoStopAt: new Date(Date.now() + 100000) }, beforeEach(() => {
}, environment = {
apolloProvider: createApolloProvider(), ...resolvedEnvironment,
autoStopAt: new Date(Date.now() + 100000).toString(),
};
wrapper = createWrapper({
propsData: {
environment,
},
apolloProvider: createApolloProvider(),
});
}); });
const rollback = wrapper.findByRole('menuitem', { name: __('Prevent auto-stopping') }); it('shows the option to pin the environment if there is an autostop date', () => {
const rollback = wrapper.findByRole('menuitem', { name: __('Prevent auto-stopping') });
expect(rollback.exists()).toBe(true); expect(rollback.exists()).toBe(true);
});
it('shows when the environment auto stops', () => {
const autoStop = wrapper.findByTitle(formatDate(environment.autoStopAt));
expect(autoStop.text()).toBe('in 1 minute');
});
}); });
it('does not show the option to pin the environment if there is no autostop date', () => { describe('without autostop', () => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() }); beforeEach(() => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() });
});
const rollback = wrapper.findByRole('menuitem', { name: __('Prevent auto-stopping') }); it('does not show the option to pin the environment if there is no autostop date', () => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() });
expect(rollback.exists()).toBe(false); const rollback = wrapper.findByRole('menuitem', { name: __('Prevent auto-stopping') });
expect(rollback.exists()).toBe(false);
});
it('does not show when the environment auto stops', () => {
const autoStop = wrapper.findByText(
sprintf(s__('Environment|Auto stop %{time}'), {
time: getTimeago().format(resolvedEnvironment.autoStopAt),
}),
);
expect(autoStop.exists()).toBe(false);
});
});
describe('with past autostop', () => {
let environment;
beforeEach(() => {
environment = {
...resolvedEnvironment,
autoStopAt: new Date(Date.now() - 100000).toString(),
};
wrapper = createWrapper({
propsData: {
environment,
},
apolloProvider: createApolloProvider(),
});
});
it('does not show the option to pin the environment if there is no autostop date', () => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() });
const rollback = wrapper.findByRole('menuitem', { name: __('Prevent auto-stopping') });
expect(rollback.exists()).toBe(false);
});
it('does not show when the environment auto stops', () => {
const autoStop = wrapper.findByText(
sprintf(s__('Environment|Auto stop %{time}'), {
time: getTimeago().format(environment.autoStopAt),
}),
);
expect(autoStop.exists()).toBe(false);
});
}); });
}); });
......
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