Commit ec5ee500 authored by Miguel Rincon's avatar Miguel Rincon

Add feature flag checks to the component

This change accounts for the feature flag being present and
extends current specs for a secondary state with the feature flag.
parent c83361e5
...@@ -56,15 +56,18 @@ export default { ...@@ -56,15 +56,18 @@ export default {
showLoader() { showLoader() {
return this.logs.isLoading || !this.logs.isComplete; return this.logs.isLoading || !this.logs.isComplete;
}, },
advancedControlsDisabled() { featureElasticEnabled() {
return this.environments.isLoading || !this.enableAdvancedQuerying; return gon.features && gon.features.enableClusterApplicationElasticStack;
},
advancedFeaturesEnabled() {
return this.featureElasticEnabled && this.enableAdvancedQuerying;
}, },
shouldShowElasticStackCallout() { shouldShowElasticStackCallout() {
return ( return (
!this.isElasticStackCalloutDismissed && !this.isElasticStackCalloutDismissed &&
!this.environments.isLoading && !this.environments.isLoading &&
!this.logs.isLoading && !this.logs.isLoading &&
!this.enableAdvancedQuerying !this.advancedFeaturesEnabled
); );
}, },
}, },
...@@ -124,7 +127,8 @@ export default { ...@@ -124,7 +127,8 @@ export default {
:label="s__('Environments|Environment')" :label="s__('Environments|Environment')"
label-size="sm" label-size="sm"
label-for="environments-dropdown" label-for="environments-dropdown"
class="col-3 px-1" class="px-1"
:class="featureElasticEnabled ? 'col-3' : 'col-6'"
> >
<gl-dropdown <gl-dropdown
id="environments-dropdown" id="environments-dropdown"
...@@ -147,7 +151,8 @@ export default { ...@@ -147,7 +151,8 @@ export default {
:label="s__('Environments|Pod logs from')" :label="s__('Environments|Pod logs from')"
label-size="sm" label-size="sm"
label-for="pods-dropdown" label-for="pods-dropdown"
class="col-3 px-1" class="px-1"
:class="featureElasticEnabled ? 'col-3' : 'col-6'"
> >
<gl-dropdown <gl-dropdown
id="pods-dropdown" id="pods-dropdown"
...@@ -165,47 +170,52 @@ export default { ...@@ -165,47 +170,52 @@ export default {
</gl-dropdown-item> </gl-dropdown-item>
</gl-dropdown> </gl-dropdown>
</gl-form-group> </gl-form-group>
<gl-form-group
id="dates-fg" <template v-if="featureElasticEnabled">
:label="s__('Environments|Show last')" <gl-form-group
label-size="sm" id="dates-fg"
label-for="time-window-dropdown" :label="s__('Environments|Show last')"
class="col-3 px-1" label-size="sm"
> label-for="time-window-dropdown"
<gl-dropdown class="col-3 px-1"
id="time-window-dropdown"
ref="time-window-dropdown"
:disabled="advancedControlsDisabled"
:text="timeWindow.options[timeWindow.current].label"
class="d-flex gl-h-32"
toggle-class="dropdown-menu-toggle"
> >
<gl-dropdown-item <gl-dropdown
v-for="(option, key) in timeWindow.options" id="time-window-dropdown"
:key="key" ref="time-window-dropdown"
@click="setTimeWindow(key)" :disabled="environments.isLoading || !advancedFeaturesEnabled"
:text="timeWindow.options[timeWindow.current].label"
class="d-flex gl-h-32"
toggle-class="dropdown-menu-toggle"
> >
{{ option.label }} <gl-dropdown-item
</gl-dropdown-item> v-for="(option, key) in timeWindow.options"
</gl-dropdown> :key="key"
</gl-form-group> @click="setTimeWindow(key)"
<gl-form-group >
id="search-fg" {{ option.label }}
:label="s__('Environments|Search')" </gl-dropdown-item>
label-size="sm" </gl-dropdown>
label-for="search" </gl-form-group>
class="col-3 px-1" <gl-form-group
> id="search-fg"
<gl-search-box-by-click :label="s__('Environments|Search')"
v-model.trim="searchQuery" label-size="sm"
:disabled="advancedControlsDisabled" label-for="search"
:placeholder="s__('Environments|Search')" class="col-3 px-1"
class="js-logs-search" >
type="search" <gl-search-box-by-click
autofocus v-model.trim="searchQuery"
@submit="!advancedControlsDisabled && setSearch(searchQuery)" :disabled="environments.isLoading || !advancedFeaturesEnabled"
/> :placeholder="s__('Environments|Search')"
</gl-form-group> class="js-logs-search"
type="search"
autofocus
@submit="
(environments.isLoading || !advancedFeaturesEnabled) && setSearch(searchQuery)
"
/>
</gl-form-group>
</template>
</div> </div>
<log-control-buttons <log-control-buttons
......
...@@ -49,6 +49,28 @@ describe('EnvironmentLogs', () => { ...@@ -49,6 +49,28 @@ describe('EnvironmentLogs', () => {
const findLogControlButtons = () => wrapper.find({ name: 'log-control-buttons-stub' }); const findLogControlButtons = () => wrapper.find({ name: 'log-control-buttons-stub' });
const findLogTrace = () => wrapper.find('.js-log-trace'); const findLogTrace = () => wrapper.find('.js-log-trace');
const mockSetInitData = () => {
state.pods.options = mockPods;
state.environments.current = mockEnvName;
[state.pods.current] = state.pods.options;
state.enableAdvancedQuerying = true;
state.logs.isComplete = false;
state.logs.lines = mockLogsResult;
};
const mockShowPodLogs = podName => {
state.pods.options = mockPods;
[state.pods.current] = podName;
state.logs.isComplete = false;
state.logs.lines = mockLogsResult;
};
const mockFetchEnvs = () => {
state.environments.options = mockEnvironments;
};
const initWrapper = () => { const initWrapper = () => {
wrapper = shallowMount(EnvironmentLogsComponent, { wrapper = shallowMount(EnvironmentLogsComponent, {
propsData, propsData,
...@@ -93,12 +115,17 @@ describe('EnvironmentLogs', () => { ...@@ -93,12 +115,17 @@ describe('EnvironmentLogs', () => {
// top bar // top bar
expect(findEnvironmentsDropdown().is(GlDropdown)).toBe(true); expect(findEnvironmentsDropdown().is(GlDropdown)).toBe(true);
expect(findPodsDropdown().is(GlDropdown)).toBe(true); expect(findPodsDropdown().is(GlDropdown)).toBe(true);
expect(findSearchBar().is(GlSearchBoxByClick)).toBe(true);
expect(findTimeWindowDropdown().is(GlDropdown)).toBe(true);
expect(findLogControlButtons().exists()).toBe(true); expect(findLogControlButtons().exists()).toBe(true);
expect(findSearchBar().exists()).toBe(false); // behind ff
expect(findTimeWindowDropdown().exists()).toBe(false); // behind ff
// log trace // log trace
expect(findLogTrace().isEmpty()).toBe(false); expect(findLogTrace().isEmpty()).toBe(false);
// layout
expect(wrapper.find('#environments-dropdown-fg').attributes('class')).toMatch('col-6');
expect(wrapper.find('#pods-dropdown-fg').attributes('class')).toMatch('col-6');
}); });
it('mounted inits data', () => { it('mounted inits data', () => {
...@@ -138,15 +165,6 @@ describe('EnvironmentLogs', () => { ...@@ -138,15 +165,6 @@ describe('EnvironmentLogs', () => {
expect(findPodsDropdown().findAll(GlDropdownItem).length).toBe(0); expect(findPodsDropdown().findAll(GlDropdownItem).length).toBe(0);
}); });
it('displays a disabled search bar', () => {
expect(findSearchBar().exists()).toEqual(true);
expect(findSearchBar().attributes('disabled')).toEqual('true');
});
it('displays a disabled time window dropdown', () => {
expect(findTimeWindowDropdown().attributes('disabled')).toEqual('true');
});
it('does not update buttons state', () => { it('does not update buttons state', () => {
expect(updateControlBtnsMock).not.toHaveBeenCalled(); expect(updateControlBtnsMock).not.toHaveBeenCalled();
}); });
...@@ -161,48 +179,11 @@ describe('EnvironmentLogs', () => { ...@@ -161,48 +179,11 @@ describe('EnvironmentLogs', () => {
}); });
}); });
describe('when advanced querying is disabled', () => {
beforeEach(() => {
state.pods.options = [];
state.logs.lines = [];
state.logs.isLoading = false;
state.environments.options = [];
state.environments.isLoading = false;
state.enableAdvancedQuerying = false;
initWrapper();
});
it('search bar and time window dropdown are disabled', () => {
expect(findSearchBar().attributes('disabled')).toEqual('true');
expect(findTimeWindowDropdown().attributes('disabled')).toEqual('true');
});
});
describe('state with data', () => { describe('state with data', () => {
beforeEach(() => { beforeEach(() => {
actionMocks.setInitData.mockImplementation(() => { actionMocks.setInitData.mockImplementation(mockSetInitData);
state.pods.options = mockPods; actionMocks.showPodLogs.mockImplementation(mockShowPodLogs);
state.environments.current = mockEnvName; actionMocks.fetchEnvironments.mockImplementation(mockFetchEnvs);
[state.pods.current] = state.pods.options;
state.enableAdvancedQuerying = true;
state.logs.isComplete = false;
state.logs.lines = mockLogsResult;
});
actionMocks.showPodLogs.mockImplementation(podName => {
state.pods.options = mockPods;
[state.pods.current] = podName;
state.logs.isComplete = false;
state.logs.lines = mockLogsResult;
});
actionMocks.fetchEnvironments.mockImplementation(() => {
state.environments.options = mockEnvironments;
});
initWrapper(); initWrapper();
}); });
...@@ -243,14 +224,6 @@ describe('EnvironmentLogs', () => { ...@@ -243,14 +224,6 @@ describe('EnvironmentLogs', () => {
expect(trace.text().split('\n')).toEqual(mockTrace); expect(trace.text().split('\n')).toEqual(mockTrace);
}); });
it('displays an enabled search bar', () => {
expect(findSearchBar().attributes('disabled')).toBeFalsy();
});
it('displays an enabled time window dropdown', () => {
expect(findTimeWindowDropdown().attributes('disabled')).toBeFalsy();
});
it('update control buttons state', () => { it('update control buttons state', () => {
expect(updateControlBtnsMock).toHaveBeenCalledTimes(1); expect(updateControlBtnsMock).toHaveBeenCalledTimes(1);
}); });
...@@ -294,4 +267,95 @@ describe('EnvironmentLogs', () => { ...@@ -294,4 +267,95 @@ describe('EnvironmentLogs', () => {
}); });
}); });
}); });
describe('when feature flag enable_cluster_application_elastic_stack is enabled', () => {
let originalGon;
beforeEach(() => {
originalGon = window.gon;
window.gon = { features: { enableClusterApplicationElasticStack: true } };
});
afterEach(() => {
window.gon = originalGon;
});
it('displays UI elements', () => {
initWrapper();
// elements
expect(findSearchBar().exists()).toBe(true);
expect(findSearchBar().is(GlSearchBoxByClick)).toBe(true);
expect(findTimeWindowDropdown().exists()).toBe(true);
expect(findTimeWindowDropdown().is(GlDropdown)).toBe(true);
// layout
expect(wrapper.find('#environments-dropdown-fg').attributes('class')).toMatch('col-3');
expect(wrapper.find('#pods-dropdown-fg').attributes('class')).toMatch('col-3');
expect(wrapper.find('#dates-fg').attributes('class')).toMatch('col-3');
expect(wrapper.find('#search-fg').attributes('class')).toMatch('col-3');
});
describe('loading state', () => {
beforeEach(() => {
state.pods.options = [];
state.logs.lines = [];
state.logs.isLoading = true;
state.environments.options = [];
state.environments.isLoading = true;
initWrapper();
});
it('displays a disabled search bar', () => {
expect(findSearchBar().exists()).toEqual(true);
expect(findSearchBar().attributes('disabled')).toEqual('true');
});
it('displays a disabled time window dropdown', () => {
expect(findTimeWindowDropdown().attributes('disabled')).toEqual('true');
});
});
describe('when advanced querying is disabled', () => {
beforeEach(() => {
state.pods.options = [];
state.logs.lines = [];
state.logs.isLoading = false;
state.environments.options = [];
state.environments.isLoading = false;
state.enableAdvancedQuerying = false;
initWrapper();
});
it('search bar and time window dropdown are disabled', () => {
expect(findSearchBar().attributes('disabled')).toEqual('true');
expect(findTimeWindowDropdown().attributes('disabled')).toEqual('true');
});
});
describe('state with data', () => {
beforeEach(() => {
actionMocks.setInitData.mockImplementation(mockSetInitData);
actionMocks.showPodLogs.mockImplementation(mockShowPodLogs);
actionMocks.fetchEnvironments.mockImplementation(mockFetchEnvs);
initWrapper();
});
it('displays an enabled search bar', () => {
expect(findSearchBar().attributes('disabled')).toBeFalsy();
});
it('displays an enabled time window dropdown', () => {
expect(findTimeWindowDropdown().attributes('disabled')).toBeFalsy();
});
});
});
}); });
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