Commit 404bab49 authored by Axel García's avatar Axel García Committed by Miguel Rincon

Make sure epic header tests DOM output

parent 91c1fa7c
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
return this.isEpicOpen ? __('Open') : __('Closed'); return this.isEpicOpen ? __('Open') : __('Closed');
}, },
actionButtonClass() { actionButtonClass() {
return `qa-close-reopen-epic-button ${this.isEpicOpen ? 'btn-close' : 'btn-open'}`; return this.isEpicOpen ? 'btn-close' : 'btn-open';
}, },
actionButtonText() { actionButtonText() {
return this.isEpicOpen ? __('Close epic') : __('Reopen epic'); return this.isEpicOpen ? __('Close epic') : __('Reopen epic');
...@@ -85,8 +85,8 @@ export default { ...@@ -85,8 +85,8 @@ export default {
class="issuable-status-box status-box" class="issuable-status-box status-box"
data-testid="status-box" data-testid="status-box"
> >
<gl-icon :name="statusIcon" class="d-block d-sm-none" /> <gl-icon :name="statusIcon" class="d-block d-sm-none" data-testid="status-icon" />
<span class="d-none d-sm-block">{{ statusText }}</span> <span class="d-none d-sm-block" data-testid="status-text">{{ statusText }}</span>
</div> </div>
<div class="issuable-meta" data-testid="author-details"> <div class="issuable-meta" data-testid="author-details">
<div <div
...@@ -134,7 +134,7 @@ export default { ...@@ -134,7 +134,7 @@ export default {
:class="actionButtonClass" :class="actionButtonClass"
category="secondary" category="secondary"
variant="warning" variant="warning"
class="gl-mt-3 gl-sm-mt-0! gl-w-full gl-sm-w-auto!" class="qa-close-reopen-epic-button gl-mt-3 gl-sm-mt-0! gl-w-full gl-sm-w-auto!"
data-testid="toggle-status-button" data-testid="toggle-status-button"
@click="toggleEpicStatus(isEpicOpen)" @click="toggleEpicStatus(isEpicOpen)"
> >
......
...@@ -33,9 +33,12 @@ describe('EpicHeaderComponent', () => { ...@@ -33,9 +33,12 @@ describe('EpicHeaderComponent', () => {
}); });
const findStatusBox = () => wrapper.find('[data-testid="status-box"]'); const findStatusBox = () => wrapper.find('[data-testid="status-box"]');
const findStatusIcon = () => wrapper.find('[data-testid="status-icon"]');
const findStatusText = () => wrapper.find('[data-testid="status-text"]');
const findConfidentialIcon = () => wrapper.find('[data-testid="confidential-icon"]').find(GlIcon); const findConfidentialIcon = () => wrapper.find('[data-testid="confidential-icon"]').find(GlIcon);
const findAuthorDetails = () => wrapper.find('[data-testid="author-details"]'); const findAuthorDetails = () => wrapper.find('[data-testid="author-details"]');
const findActionButtons = () => wrapper.find('[data-testid="action-buttons"]'); const findActionButtons = () => wrapper.find('[data-testid="action-buttons"]');
const findToggleStatusButton = () => wrapper.find('[data-testid="toggle-status-button"]');
const findNewEpicButton = () => wrapper.find('[data-testid="new-epic-button"]'); const findNewEpicButton = () => wrapper.find('[data-testid="new-epic-button"]');
const findSidebarToggle = () => wrapper.find('[data-testid="sidebar-toggle"]'); const findSidebarToggle = () => wrapper.find('[data-testid="sidebar-toggle"]');
...@@ -44,13 +47,15 @@ describe('EpicHeaderComponent', () => { ...@@ -44,13 +47,15 @@ describe('EpicHeaderComponent', () => {
it('returns string `issue-open-m` when `isEpicOpen` is true', () => { it('returns string `issue-open-m` when `isEpicOpen` is true', () => {
store.state.state = statusType.open; store.state.state = statusType.open;
expect(wrapper.vm.statusIcon).toBe('issue-open-m'); expect(findStatusIcon().props('name')).toBe('issue-open-m');
}); });
it('returns string `mobile-issue-close` when `isEpicOpen` is false', () => { it('returns string `mobile-issue-close` when `isEpicOpen` is false', () => {
store.state.state = statusType.close; store.state.state = statusType.close;
expect(wrapper.vm.statusIcon).toBe('mobile-issue-close'); return wrapper.vm.$nextTick().then(() => {
expect(findStatusIcon().props('name')).toBe('mobile-issue-close');
});
}); });
}); });
...@@ -58,13 +63,15 @@ describe('EpicHeaderComponent', () => { ...@@ -58,13 +63,15 @@ describe('EpicHeaderComponent', () => {
it('returns string `Open` when `isEpicOpen` is true', () => { it('returns string `Open` when `isEpicOpen` is true', () => {
store.state.state = statusType.open; store.state.state = statusType.open;
expect(wrapper.vm.statusText).toBe('Open'); expect(findStatusText().text()).toBe('Open');
}); });
it('returns string `Closed` when `isEpicOpen` is false', () => { it('returns string `Closed` when `isEpicOpen` is false', () => {
store.state.state = statusType.close; store.state.state = statusType.close;
expect(wrapper.vm.statusText).toBe('Closed'); return wrapper.vm.$nextTick().then(() => {
expect(findStatusText().text()).toBe('Closed');
});
}); });
}); });
...@@ -72,13 +79,15 @@ describe('EpicHeaderComponent', () => { ...@@ -72,13 +79,15 @@ describe('EpicHeaderComponent', () => {
it('returns `btn-close` when `isEpicOpen` is true', () => { it('returns `btn-close` when `isEpicOpen` is true', () => {
store.state.state = statusType.open; store.state.state = statusType.open;
expect(wrapper.vm.actionButtonClass).toContain('btn-close'); expect(findToggleStatusButton().classes()).toContain('btn-close');
}); });
it('returns `btn-open` when `isEpicOpen` is false', () => { it('returns `btn-open` when `isEpicOpen` is false', () => {
store.state.state = statusType.close; store.state.state = statusType.close;
expect(wrapper.vm.actionButtonClass).toContain('btn-open'); return wrapper.vm.$nextTick().then(() => {
expect(findToggleStatusButton().classes()).toContain('btn-open');
});
}); });
}); });
...@@ -86,13 +95,15 @@ describe('EpicHeaderComponent', () => { ...@@ -86,13 +95,15 @@ describe('EpicHeaderComponent', () => {
it('returns string `Close epic` when `isEpicOpen` is true', () => { it('returns string `Close epic` when `isEpicOpen` is true', () => {
store.state.state = statusType.open; store.state.state = statusType.open;
expect(wrapper.vm.actionButtonText).toBe('Close epic'); expect(findToggleStatusButton().text()).toBe('Close epic');
}); });
it('returns string `Reopen epic` when `isEpicOpen` is false', () => { it('returns string `Reopen epic` when `isEpicOpen` is false', () => {
store.state.state = statusType.close; store.state.state = statusType.close;
expect(wrapper.vm.actionButtonText).toBe('Reopen epic'); return wrapper.vm.$nextTick().then(() => {
expect(findToggleStatusButton().text()).toBe('Reopen epic');
});
}); });
}); });
}); });
...@@ -132,7 +143,7 @@ describe('EpicHeaderComponent', () => { ...@@ -132,7 +143,7 @@ describe('EpicHeaderComponent', () => {
it('renders action buttons element', () => { it('renders action buttons element', () => {
const actionButtons = findActionButtons(); const actionButtons = findActionButtons();
const toggleStatusButton = actionButtons.find('[data-testid="toggle-status-button"]'); const toggleStatusButton = findToggleStatusButton();
expect(actionButtons.exists()).toBeTruthy(); expect(actionButtons.exists()).toBeTruthy();
expect(toggleStatusButton.exists()).toBeTruthy(); expect(toggleStatusButton.exists()).toBeTruthy();
...@@ -167,6 +178,14 @@ describe('EpicHeaderComponent', () => { ...@@ -167,6 +178,14 @@ describe('EpicHeaderComponent', () => {
features = { createEpicForm: true }; features = { createEpicForm: true };
}); });
it('does not render new epic button if user cannot create it', () => {
store.state.canCreate = false;
return wrapper.vm.$nextTick().then(() => {
expect(findNewEpicButton().exists()).toBe(false);
});
});
it('renders new epic button if user can create it', () => { it('renders new epic button if user can create it', () => {
store.state.canCreate = true; store.state.canCreate = true;
......
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