Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-28 12:09:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-28 12:09:34 +0300
commit0f59ad0c29c8679957c716317c842f606177f223 (patch)
tree387d1f932ad462e2906c840160e0305671acc274 /spec
parent99454db49e04656e8df692c5a1c4582fec50eee3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/groups_spec.rb36
-rw-r--r--spec/frontend/behaviors/markdown/paste_markdown_table_spec.js12
-rw-r--r--spec/frontend/monitoring/components/dashboard_spec.js34
-rw-r--r--spec/frontend/monitoring/components/dashboard_template_spec.js12
-rw-r--r--spec/models/environment_spec.rb21
5 files changed, 88 insertions, 27 deletions
diff --git a/spec/features/groups_spec.rb b/spec/features/groups_spec.rb
index d2e65c02e37..c1cb0b4951e 100644
--- a/spec/features/groups_spec.rb
+++ b/spec/features/groups_spec.rb
@@ -262,6 +262,42 @@ describe 'Group' do
end
end
+ describe 'new subgroup / project button' do
+ let(:group) { create(:group, project_creation_level: Gitlab::Access::NO_ONE_PROJECT_ACCESS, subgroup_creation_level: Gitlab::Access::OWNER_SUBGROUP_ACCESS) }
+
+ it 'new subgroup button is displayed without project creation permission' do
+ visit group_path(group)
+
+ page.within '.group-buttons' do
+ expect(page).to have_link('New subgroup')
+ end
+ end
+
+ it 'new subgroup button is displayed together with new project button when having project creation permission' do
+ group.update!(project_creation_level: Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
+ visit group_path(group)
+
+ page.within '.group-buttons' do
+ expect(page).to have_css("li[data-text='New subgroup']", visible: false)
+ expect(page).to have_css("li[data-text='New project']", visible: false)
+ end
+ end
+
+ it 'new project button is displayed without subgroup creation permission' do
+ group.update!(project_creation_level: Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
+ user = create(:user)
+
+ group.add_maintainer(user)
+ sign_out(:user)
+ sign_in(user)
+
+ visit group_path(group)
+ page.within '.group-buttons' do
+ expect(page).to have_link('New project')
+ end
+ end
+ end
+
def remove_with_confirm(button_text, confirm_with)
click_button button_text
fill_in 'confirm_name_input', with: confirm_with
diff --git a/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js
index a98919e2113..eab805382bd 100644
--- a/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js
+++ b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js
@@ -57,6 +57,18 @@ describe('PasteMarkdownTable', () => {
expect(new PasteMarkdownTable(data).isTable()).toBe(false);
});
+
+ it('returns false when the table copy comes from a diff', () => {
+ data.types = ['text/html', 'text/plain'];
+ data.getData = jest.fn().mockImplementation(mimeType => {
+ if (mimeType === 'text/html') {
+ return '<table class="diff-wrap-lines"><tr><td>First</td><td>Second</td></tr></table>';
+ }
+ return 'First\tSecond';
+ });
+
+ expect(new PasteMarkdownTable(data).isTable()).toBe(false);
+ });
});
describe('convertToTableMarkdown', () => {
diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js
index 0ee0a2e6e41..be3c83dfd7d 100644
--- a/spec/frontend/monitoring/components/dashboard_spec.js
+++ b/spec/frontend/monitoring/components/dashboard_spec.js
@@ -11,6 +11,7 @@ import Dashboard from '~/monitoring/components/dashboard.vue';
import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue';
import CustomMetricsFormFields from '~/custom_metrics/components/custom_metrics_form_fields.vue';
import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue';
+import EmptyState from '~/monitoring/components/empty_state.vue';
import GroupEmptyState from '~/monitoring/components/group_empty_state.vue';
import DashboardPanel from '~/monitoring/components/dashboard_panel.vue';
import { createStore } from '~/monitoring/stores';
@@ -33,9 +34,6 @@ describe('Dashboard', () => {
const createShallowWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(Dashboard, {
propsData: { ...propsData, ...props },
- methods: {
- fetchData: jest.fn(),
- },
store,
...options,
});
@@ -44,9 +42,6 @@ describe('Dashboard', () => {
const createMountedWrapper = (props = {}, options = {}) => {
wrapper = mount(Dashboard, {
propsData: { ...propsData, ...props },
- methods: {
- fetchData: jest.fn(),
- },
store,
stubs: ['graph-group', 'dashboard-panel'],
...options,
@@ -56,14 +51,14 @@ describe('Dashboard', () => {
beforeEach(() => {
store = createStore();
mock = new MockAdapter(axios);
+ jest.spyOn(store, 'dispatch').mockResolvedValue();
});
afterEach(() => {
- if (wrapper) {
- wrapper.destroy();
- wrapper = null;
- }
mock.restore();
+ if (store.dispatch.mockReset) {
+ store.dispatch.mockReset();
+ }
});
describe('no metrics are available yet', () => {
@@ -104,9 +99,7 @@ describe('Dashboard', () => {
describe('request information to the server', () => {
it('calls to set time range and fetch data', () => {
- jest.spyOn(store, 'dispatch');
-
- createShallowWrapper({ hasMetrics: true }, { methods: {} });
+ createShallowWrapper({ hasMetrics: true });
return wrapper.vm.$nextTick().then(() => {
expect(store.dispatch).toHaveBeenCalledWith(
@@ -119,10 +112,13 @@ describe('Dashboard', () => {
});
it('shows up a loading state', () => {
- createShallowWrapper({ hasMetrics: true }, { methods: {} });
+ store.state.monitoringDashboard.emptyState = 'loading';
+
+ createShallowWrapper({ hasMetrics: true });
return wrapper.vm.$nextTick().then(() => {
- expect(wrapper.vm.emptyState).toEqual('loading');
+ expect(wrapper.find(EmptyState).exists()).toBe(true);
+ expect(wrapper.find(EmptyState).props('selectedState')).toBe('loading');
});
});
@@ -254,6 +250,10 @@ describe('Dashboard', () => {
return wrapper.vm.$nextTick();
});
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
it('renders a search input', () => {
expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownSearch' }).exists()).toBe(true);
});
@@ -322,8 +322,10 @@ describe('Dashboard', () => {
const findRearrangeButton = () => wrapper.find('.js-rearrange-button');
beforeEach(() => {
- createShallowWrapper({ hasMetrics: true });
+ // call original dispatch
+ store.dispatch.mockRestore();
+ createShallowWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store);
return wrapper.vm.$nextTick();
diff --git a/spec/frontend/monitoring/components/dashboard_template_spec.js b/spec/frontend/monitoring/components/dashboard_template_spec.js
index d1790df4189..0257515f18e 100644
--- a/spec/frontend/monitoring/components/dashboard_template_spec.js
+++ b/spec/frontend/monitoring/components/dashboard_template_spec.js
@@ -18,21 +18,11 @@ describe('Dashboard template', () => {
});
afterEach(() => {
- if (wrapper) {
- wrapper.destroy();
- wrapper = null;
- }
mock.restore();
});
it('matches the default snapshot', () => {
- wrapper = shallowMount(Dashboard, {
- propsData: { ...propsData },
- methods: {
- fetchData: jest.fn(),
- },
- store,
- });
+ wrapper = shallowMount(Dashboard, { propsData: { ...propsData }, store });
expect(wrapper.element).toMatchSnapshot();
});
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index d0305d878e3..c0b2a4ae984 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -1311,4 +1311,25 @@ describe Environment, :use_clean_rails_memory_store_caching do
expect { environment.destroy }.to change { project.commit(deployment.ref_path) }.to(nil)
end
end
+
+ describe '.count_by_state' do
+ context 'when environments are not empty' do
+ let!(:environment1) { create(:environment, project: project, state: 'stopped') }
+ let!(:environment2) { create(:environment, project: project, state: 'available') }
+ let!(:environment3) { create(:environment, project: project, state: 'stopped') }
+
+ it 'returns the environments count grouped by state' do
+ expect(project.environments.count_by_state).to eq({ stopped: 2, available: 1 })
+ end
+
+ it 'returns the environments count grouped by state with zero value' do
+ environment2.update(state: 'stopped')
+ expect(project.environments.count_by_state).to eq({ stopped: 3, available: 0 })
+ end
+ end
+
+ it 'returns zero state counts when environments are empty' do
+ expect(project.environments.count_by_state).to eq({ stopped: 0, available: 0 })
+ end
+ end
end