Commit 43de07eb authored by Andrew Fontaine's avatar Andrew Fontaine

Refactor environment empty state to use scope

The empty state reported that you didn't have any environments
regardless of scope, which was a bit misleading if you had many
available environments and no stopped environments.

I have refactored the component to allow the scope to be injected so the
text can change depending on what scope the user is looking at.

I've also refactored the rest of the translations to follow more
up-to-date patterns, and rewritten the tests to utilize the testing
library's queries for finding things by role.

Changelog: fixed
parent 36086a83
<script> <script>
import { s__ } from '~/locale';
import { ENVIRONMENTS_SCOPE } from '../constants';
export default { export default {
name: 'EnvironmentsEmptyState', name: 'EnvironmentsEmptyState',
props: { props: {
...@@ -6,6 +9,25 @@ export default { ...@@ -6,6 +9,25 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
scope: {
type: String,
required: true,
},
},
computed: {
title() {
return this.$options.i18n.title[this.scope];
},
},
i18n: {
title: {
[ENVIRONMENTS_SCOPE.AVAILABLE]: s__("Environments|You don't have any environments."),
[ENVIRONMENTS_SCOPE.STOPPED]: s__("Environments|You don't have any stopped environments."),
},
content: s__(
'Environments|Environments are places where code gets deployed, such as staging or production.',
),
link: s__('Environments|How do I create an environment?'),
}, },
}; };
</script> </script>
...@@ -13,14 +35,11 @@ export default { ...@@ -13,14 +35,11 @@ export default {
<div class="empty-state"> <div class="empty-state">
<div class="text-content"> <div class="text-content">
<h4 class="js-blank-state-title"> <h4 class="js-blank-state-title">
{{ s__("Environments|You don't have any environments right now") }} {{ title }}
</h4> </h4>
<p> <p>
{{ {{ $options.i18n.content }}
s__(`Environments|Environments are places where <a :href="helpPath"> {{ $options.i18n.link }} </a>
code gets deployed, such as staging or production.`)
}}
<a :href="helpPath"> {{ s__('Environments|More information') }} </a>
</p> </p>
</div> </div>
</div> </div>
......
...@@ -253,7 +253,7 @@ export default { ...@@ -253,7 +253,7 @@ export default {
@change="resetPolling" @change="resetPolling"
/> />
</template> </template>
<empty-state v-else :help-path="helpPagePath" /> <empty-state v-else :help-path="helpPagePath" :scope="scope" />
<gl-pagination <gl-pagination
align="center" align="center"
:total-items="totalItems" :total-items="totalItems"
......
...@@ -14190,6 +14190,9 @@ msgstr "" ...@@ -14190,6 +14190,9 @@ msgstr ""
msgid "Environments|Environments are places where code gets deployed, such as staging or production." msgid "Environments|Environments are places where code gets deployed, such as staging or production."
msgstr "" msgstr ""
msgid "Environments|How do I create an environment?"
msgstr ""
msgid "Environments|Install Elastic Stack on your cluster to enable advanced querying capabilities such as full text search." msgid "Environments|Install Elastic Stack on your cluster to enable advanced querying capabilities such as full text search."
msgstr "" msgstr ""
...@@ -14205,9 +14208,6 @@ msgstr "" ...@@ -14205,9 +14208,6 @@ msgstr ""
msgid "Environments|Logs from %{start} to %{end}." msgid "Environments|Logs from %{start} to %{end}."
msgstr "" msgstr ""
msgid "Environments|More information"
msgstr ""
msgid "Environments|New environment" msgid "Environments|New environment"
msgstr "" msgstr ""
...@@ -14289,7 +14289,10 @@ msgstr "" ...@@ -14289,7 +14289,10 @@ msgstr ""
msgid "Environments|Updated" msgid "Environments|Updated"
msgstr "" msgstr ""
msgid "Environments|You don't have any environments right now" msgid "Environments|You don't have any environments."
msgstr ""
msgid "Environments|You don't have any stopped environments."
msgstr "" msgstr ""
msgid "Environments|by %{avatar}" msgid "Environments|by %{avatar}"
......
...@@ -70,7 +70,7 @@ RSpec.describe 'Environments page', :js do ...@@ -70,7 +70,7 @@ RSpec.describe 'Environments page', :js do
it 'shows no environments' do it 'shows no environments' do
visit_environments(project, scope: 'stopped') visit_environments(project, scope: 'stopped')
expect(page).to have_content('You don\'t have any environments right now') expect(page).to have_content(s_('Environments|You don\'t have any stopped environments.'))
end end
end end
...@@ -99,7 +99,7 @@ RSpec.describe 'Environments page', :js do ...@@ -99,7 +99,7 @@ RSpec.describe 'Environments page', :js do
it 'shows no environments' do it 'shows no environments' do
visit_environments(project, scope: 'available') visit_environments(project, scope: 'available')
expect(page).to have_content('You don\'t have any environments right now') expect(page).to have_content(s_('Environments|You don\'t have any environments.'))
end end
end end
...@@ -120,7 +120,7 @@ RSpec.describe 'Environments page', :js do ...@@ -120,7 +120,7 @@ RSpec.describe 'Environments page', :js do
end end
it 'does not show environments and counters are set to zero' do it 'does not show environments and counters are set to zero' do
expect(page).to have_content('You don\'t have any environments right now') expect(page).to have_content(s_('Environments|You don\'t have any environments.'))
expect(page).to have_link("#{_('Available')} 0") expect(page).to have_link("#{_('Available')} 0")
expect(page).to have_link("#{_('Stopped')} 0") expect(page).to have_link("#{_('Stopped')} 0")
......
import { mountExtended } from 'helpers/vue_test_utils_helper';
import { s__ } from '~/locale';
import EmptyState from '~/environments/components/empty_state.vue';
import { ENVIRONMENTS_SCOPE } from '~/environments/constants';
const HELP_PATH = '/help';
describe('~/environments/components/empty_state.vue', () => {
let wrapper;
const createWrapper = ({ propsData = {} } = {}) =>
mountExtended(EmptyState, {
propsData: {
scope: ENVIRONMENTS_SCOPE.AVAILABLE,
helpPath: HELP_PATH,
...propsData,
},
});
afterEach(() => {
wrapper.destroy();
});
it('shows an empty state for available environments', () => {
wrapper = createWrapper();
const title = wrapper.findByRole('heading', {
name: s__("Environments|You don't have any environments."),
});
expect(title.exists()).toBe(true);
});
it('shows an empty state for stopped environments', () => {
wrapper = createWrapper({ propsData: { scope: ENVIRONMENTS_SCOPE.STOPPED } });
const title = wrapper.findByRole('heading', {
name: s__("Environments|You don't have any stopped environments."),
});
expect(title.exists()).toBe(true);
});
it('shows a link to the the help path', () => {
wrapper = createWrapper();
const link = wrapper.findByRole('link', {
name: s__('Environments|How do I create an environment?'),
});
expect(link.attributes('href')).toBe(HELP_PATH);
});
});
import { shallowMount } from '@vue/test-utils';
import EmptyState from '~/environments/components/empty_state.vue';
describe('environments empty state', () => {
let vm;
beforeEach(() => {
vm = shallowMount(EmptyState, {
propsData: {
helpPath: 'bar',
},
});
});
afterEach(() => {
vm.destroy();
});
it('renders the empty state', () => {
expect(vm.find('.js-blank-state-title').text()).toEqual(
"You don't have any environments right now",
);
});
});
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