Commit ae20abff authored by Miguel Rincon's avatar Miguel Rincon

Remove .querySelector from dashboard specs

parent 95769190
...@@ -370,7 +370,9 @@ export default { ...@@ -370,7 +370,9 @@ export default {
> >
<gl-dropdown <gl-dropdown
id="monitor-environments-dropdown" id="monitor-environments-dropdown"
class="mb-0 d-flex js-environments-dropdown" ref="monitorEnvironmentsDropdown"
data-qa-selector="environments_dropdown"
class="mb-0 d-flex"
toggle-class="dropdown-menu-toggle" toggle-class="dropdown-menu-toggle"
:text="currentEnvironmentName" :text="currentEnvironmentName"
:disabled="environments.length === 0" :disabled="environments.length === 0"
......
...@@ -30,9 +30,9 @@ describe 'Environment > Metrics' do ...@@ -30,9 +30,9 @@ describe 'Environment > Metrics' do
click_link('See metrics') click_link('See metrics')
expect(page).to have_metrics_path(environment) expect(page).to have_metrics_path(environment)
expect(page).to have_css('div.js-environments-dropdown') expect(page).to have_css('[data-qa-selector="environments_dropdown"]')
within('div.js-environments-dropdown') do within('[data-qa-selector="environments_dropdown"]') do
# Click on the dropdown # Click on the dropdown
click_on(environment.name) click_on(environment.name)
......
...@@ -52,6 +52,9 @@ describe('Dashboard', () => { ...@@ -52,6 +52,9 @@ describe('Dashboard', () => {
}); });
}; };
const findEnvironmentsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' });
const findAllEnvironmentsDropdownItems = () => findEnvironmentsDropdown().findAll(GlDropdownItem);
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
...@@ -71,7 +74,7 @@ describe('Dashboard', () => { ...@@ -71,7 +74,7 @@ describe('Dashboard', () => {
}); });
it('shows the environment selector', () => { it('shows the environment selector', () => {
expect(wrapper.vm.$el.querySelector('.js-environments-dropdown')).toBeTruthy(); expect(findEnvironmentsDropdown().exists()).toBe(true);
}); });
}); });
...@@ -83,7 +86,7 @@ describe('Dashboard', () => { ...@@ -83,7 +86,7 @@ describe('Dashboard', () => {
}); });
it('shows the environment selector dropdown', () => { it('shows the environment selector dropdown', () => {
expect(wrapper.vm.$el.querySelector('.js-environments-dropdown')).toBeTruthy(); expect(findEnvironmentsDropdown().exists()).toBe(true);
}); });
}); });
...@@ -113,7 +116,7 @@ describe('Dashboard', () => { ...@@ -113,7 +116,7 @@ describe('Dashboard', () => {
.$nextTick() .$nextTick()
.then(() => { .then(() => {
expect(wrapper.vm.showEmptyState).toEqual(false); expect(wrapper.vm.showEmptyState).toEqual(false);
expect(wrapper.vm.$el.querySelector('.prometheus-panel')).toEqual(null); expect(wrapper.findAll('.prometheus-panel')).toHaveLength(0);
done(); done();
}) })
...@@ -152,9 +155,7 @@ describe('Dashboard', () => { ...@@ -152,9 +155,7 @@ describe('Dashboard', () => {
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => { .then(() => {
const environmentDropdownItems = wrapper const environmentDropdownItems = findAllEnvironmentsDropdownItems();
.find('.js-environments-dropdown')
.findAll(GlDropdownItem);
expect(wrapper.vm.environments.length).toEqual(environmentData.length); expect(wrapper.vm.environments.length).toEqual(environmentData.length);
expect(environmentDropdownItems.length).toEqual(wrapper.vm.environments.length); expect(environmentDropdownItems.length).toEqual(wrapper.vm.environments.length);
...@@ -176,10 +177,7 @@ describe('Dashboard', () => { ...@@ -176,10 +177,7 @@ describe('Dashboard', () => {
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => { .then(() => {
const environmentDropdownItems = wrapper const activeItem = findAllEnvironmentsDropdownItems().wrappers.filter(itemWrapper =>
.find('.js-environments-dropdown')
.findAll(GlDropdownItem);
const activeItem = environmentDropdownItems.wrappers.filter(itemWrapper =>
itemWrapper.find('.active').exists(), itemWrapper.find('.active').exists(),
); );
...@@ -205,11 +203,7 @@ describe('Dashboard', () => { ...@@ -205,11 +203,7 @@ describe('Dashboard', () => {
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => { .then(() => {
const environmentDropdownItems = wrapper expect(findAllEnvironmentsDropdownItems()).toHaveLength(0);
.find('.js-environments-dropdown')
.findAll(GlDropdownItem);
expect(environmentDropdownItems.length).toEqual(0);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);
......
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