|
@@ -1,6 +1,7 @@
|
|
|
import React from 'react';
|
|
|
|
|
|
import {initializeOrg} from 'app-test/helpers/initializeOrg';
|
|
|
+import {mockRouterPush} from 'app-test/helpers/mockRouterPush';
|
|
|
import {mount} from 'enzyme';
|
|
|
import ConfigStore from 'app/stores/configStore';
|
|
|
import GlobalSelectionHeader from 'app/components/organizations/globalSelectionHeader';
|
|
@@ -23,7 +24,7 @@ const changeQuery = (routerContext, query) => ({
|
|
|
|
|
|
jest.mock('app/utils/localStorage', () => {
|
|
|
return {
|
|
|
- getItem: () => JSON.stringify({projects: [5], environments: ['staging']}),
|
|
|
+ getItem: () => JSON.stringify({projects: [3], environments: ['staging']}),
|
|
|
setItem: jest.fn(),
|
|
|
};
|
|
|
});
|
|
@@ -33,14 +34,19 @@ describe('GlobalSelectionHeader', function() {
|
|
|
organization: {features: ['global-views']},
|
|
|
projects: [
|
|
|
{
|
|
|
- id: 5,
|
|
|
- isMember: true,
|
|
|
+ id: 2,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 3,
|
|
|
+ slug: 'project-3',
|
|
|
+ environments: ['prod', 'staging'],
|
|
|
},
|
|
|
],
|
|
|
router: {
|
|
|
location: {query: {}},
|
|
|
},
|
|
|
});
|
|
|
+ jest.spyOn(ProjectsStore, 'getAll').mockImplementation(() => organization.projects);
|
|
|
|
|
|
beforeAll(function() {
|
|
|
jest.spyOn(globalActions, 'updateDateTime');
|
|
@@ -124,13 +130,22 @@ describe('GlobalSelectionHeader', function() {
|
|
|
})
|
|
|
);
|
|
|
|
|
|
- // component will initially try to sync router + stores
|
|
|
+ wrapper.setContext(
|
|
|
+ changeQuery(routerContext, {
|
|
|
+ statsPeriod: '21d',
|
|
|
+ }).context
|
|
|
+ );
|
|
|
+
|
|
|
+ await tick();
|
|
|
+ wrapper.update();
|
|
|
+
|
|
|
expect(globalActions.updateDateTime).toHaveBeenCalledWith({
|
|
|
- period: '7d',
|
|
|
+ period: '21d',
|
|
|
utc: null,
|
|
|
start: null,
|
|
|
end: null,
|
|
|
});
|
|
|
+ // These should not be called because they have not changed, only date has changed
|
|
|
expect(globalActions.updateProjects).toHaveBeenCalledWith([]);
|
|
|
expect(globalActions.updateEnvironments).toHaveBeenCalledWith([]);
|
|
|
|
|
@@ -138,35 +153,101 @@ describe('GlobalSelectionHeader', function() {
|
|
|
globalActions.updateProjects.mockClear();
|
|
|
globalActions.updateEnvironments.mockClear();
|
|
|
|
|
|
- wrapper.setContext(
|
|
|
- changeQuery(routerContext, {
|
|
|
- statsPeriod: '21d',
|
|
|
- }).context
|
|
|
+ expect(GlobalSelectionStore.get()).toEqual({
|
|
|
+ datetime: {
|
|
|
+ period: '21d',
|
|
|
+ utc: null,
|
|
|
+ start: null,
|
|
|
+ end: null,
|
|
|
+ },
|
|
|
+ environments: [],
|
|
|
+ projects: [],
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updates environments when switching projects', async function() {
|
|
|
+ const wrapper = mount(
|
|
|
+ <GlobalSelectionHeader
|
|
|
+ organization={organization}
|
|
|
+ projects={organization.projects}
|
|
|
+ />,
|
|
|
+ routerContext
|
|
|
);
|
|
|
+
|
|
|
+ mockRouterPush(wrapper, router);
|
|
|
+
|
|
|
+ // Open dropdown and select both projects
|
|
|
+ wrapper.find('MultipleProjectSelector HeaderItem').simulate('click');
|
|
|
+ wrapper
|
|
|
+ .find('MultipleProjectSelector CheckboxFancy')
|
|
|
+ .at(0)
|
|
|
+ .simulate('click');
|
|
|
+ wrapper
|
|
|
+ .find('MultipleProjectSelector CheckboxFancy')
|
|
|
+ .at(1)
|
|
|
+ .simulate('click');
|
|
|
+ wrapper.find('MultipleProjectSelector HeaderItem').simulate('click');
|
|
|
+
|
|
|
await tick();
|
|
|
wrapper.update();
|
|
|
+ expect(wrapper.find('MultipleProjectSelector Content').text()).toBe(
|
|
|
+ 'project-slug, project-3'
|
|
|
+ );
|
|
|
|
|
|
- expect(globalActions.updateDateTime).toHaveBeenCalledWith({
|
|
|
- period: '21d',
|
|
|
- utc: null,
|
|
|
- start: null,
|
|
|
- end: null,
|
|
|
+ // Select environment
|
|
|
+ wrapper.find('MultipleEnvironmentSelector HeaderItem').simulate('click');
|
|
|
+ wrapper
|
|
|
+ .find('MultipleEnvironmentSelector CheckboxFancy')
|
|
|
+ .at(1)
|
|
|
+ .simulate('click');
|
|
|
+ wrapper.find('MultipleEnvironmentSelector HeaderItem').simulate('click');
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ expect(wrapper.find('MultipleEnvironmentSelector Content').text()).toBe('staging');
|
|
|
+
|
|
|
+ expect(GlobalSelectionStore.get()).toEqual({
|
|
|
+ datetime: {
|
|
|
+ period: null,
|
|
|
+ utc: null,
|
|
|
+ start: null,
|
|
|
+ end: null,
|
|
|
+ },
|
|
|
+ environments: ['staging'],
|
|
|
+ projects: [2, 3],
|
|
|
+ });
|
|
|
+ const query = wrapper.prop('location').query;
|
|
|
+ expect(query).toEqual({
|
|
|
+ environment: 'staging',
|
|
|
+ project: ['2', '3'],
|
|
|
});
|
|
|
|
|
|
- // These should not be called because they have not changed, only date has changed
|
|
|
- expect(globalActions.updateProjects).not.toHaveBeenCalled();
|
|
|
- expect(globalActions.updateEnvironments).not.toHaveBeenCalled();
|
|
|
+ // Now change projects, first project has no enviroments
|
|
|
+ wrapper.find('MultipleProjectSelector HeaderItem').simulate('click');
|
|
|
+ wrapper
|
|
|
+ .find('MultipleProjectSelector CheckboxFancy')
|
|
|
+ .at(1)
|
|
|
+ .simulate('click');
|
|
|
|
|
|
+ wrapper.find('MultipleProjectSelector HeaderItem').simulate('click');
|
|
|
+
|
|
|
+ await tick();
|
|
|
+ wrapper.update();
|
|
|
+
|
|
|
+ // Store should not have any environments selected
|
|
|
expect(GlobalSelectionStore.get()).toEqual({
|
|
|
datetime: {
|
|
|
- period: '21d',
|
|
|
+ period: null,
|
|
|
utc: null,
|
|
|
start: null,
|
|
|
end: null,
|
|
|
},
|
|
|
environments: [],
|
|
|
- projects: [],
|
|
|
+ projects: [2],
|
|
|
});
|
|
|
+ expect(wrapper.prop('location').query).toEqual({project: '2'});
|
|
|
+ expect(wrapper.find('MultipleEnvironmentSelector Content').text()).toBe(
|
|
|
+ 'All Environments'
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
it('updates URL to match GlobalSelection store when re-rendered with `forceUrlSync` prop', async function() {
|
|
@@ -188,7 +269,7 @@ describe('GlobalSelectionHeader', function() {
|
|
|
expect.objectContaining({
|
|
|
query: {
|
|
|
environment: ['staging'],
|
|
|
- project: [5],
|
|
|
+ project: [3],
|
|
|
},
|
|
|
})
|
|
|
);
|
|
@@ -367,7 +448,7 @@ describe('GlobalSelectionHeader', function() {
|
|
|
it('selects first project if none (i.e. all) is requested', function() {
|
|
|
const project = TestStubs.Project({id: '3'});
|
|
|
const org = TestStubs.Organization({projects: [project]});
|
|
|
- ProjectsStore.loadInitialData(org.projects);
|
|
|
+ jest.spyOn(ProjectsStore, 'getAll').mockImplementation(() => org.projects);
|
|
|
|
|
|
const initializationObj = initializeOrg({
|
|
|
organization: org,
|
|
@@ -427,7 +508,7 @@ describe('GlobalSelectionHeader', function() {
|
|
|
memberProject = TestStubs.Project({id: '3', isMember: true});
|
|
|
nonMemberProject = TestStubs.Project({id: '4', isMember: false});
|
|
|
const org = TestStubs.Organization({projects: [memberProject, nonMemberProject]});
|
|
|
- ProjectsStore.loadInitialData(org.projects);
|
|
|
+ jest.spyOn(ProjectsStore, 'getAll').mockImplementation(() => org.projects);
|
|
|
|
|
|
initialData = initializeOrg({
|
|
|
organization: org,
|