Commit ee51e767 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'generic-alert-button-colour' into 'master'

Change generic alert button color with state

See merge request gitlab-org/gitlab!16420
parents 3b8ed909 8fd141b7
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
.col-lg-3 .col-lg-3
%h4.prepend-top-0 %h4.prepend-top-0
= @service.title = @service.title
= boolean_to_icon @service.activated? - [true, false].each do |value|
- hide_class = 'd-none' if @service.activated? != value
%span.js-service-active-status{ class: hide_class, data: { value: value.to_s } }
= boolean_to_icon value
%p= #{@service.description}. %p= #{@service.description}.
- if @service.respond_to?(:detailed_description) - if @service.respond_to?(:detailed_description)
......
...@@ -80,7 +80,21 @@ export default { ...@@ -80,7 +80,21 @@ export default {
return `${desc}${learnMoreDesc}`; return `${desc}${learnMoreDesc}`;
}, },
}, },
watch: {
activated() {
this.updateIcon();
},
},
methods: { methods: {
updateIcon() {
return document.querySelectorAll('.js-service-active-status').forEach(icon => {
if (icon.dataset.value === this.activated.toString()) {
icon.classList.remove('d-none');
} else {
icon.classList.add('d-none');
}
});
},
resetKey() { resetKey() {
return axios return axios
.put(this.formPath, { service: { token: '' } }) .put(this.formPath, { service: { token: '' } })
......
...@@ -36,9 +36,16 @@ describe('AlertsServiceForm', () => { ...@@ -36,9 +36,16 @@ describe('AlertsServiceForm', () => {
const findUrl = () => wrapper.find('#url'); const findUrl = () => wrapper.find('#url');
const findAuthorizationKey = () => wrapper.find('#authorization-key'); const findAuthorizationKey = () => wrapper.find('#authorization-key');
const findDescription = () => wrapper.find('p'); const findDescription = () => wrapper.find('p');
const findActiveStatusIcon = val =>
document.querySelector(`.js-service-active-status[data-value=${val.toString()}]`);
beforeEach(() => { beforeEach(() => {
mockAxios = new MockAdapter(axios); mockAxios = new MockAdapter(axios);
setFixtures(`
<div>
<span class="js-service-active-status fa fa-circle" data-value="true"></span>
<span class="js-service-active-status fa fa-power-off" data-value="false"></span>
</div>`);
}); });
afterEach(() => { afterEach(() => {
...@@ -127,25 +134,33 @@ describe('AlertsServiceForm', () => { ...@@ -127,25 +134,33 @@ describe('AlertsServiceForm', () => {
}); });
describe('successfully completes', () => { describe('successfully completes', () => {
const formPath = 'some/path'; describe.each`
initialActivated | value
it('enables toggle when initialActivated=false', () => { ${false} | ${true}
mockAxios.onPut(formPath, { service: { active: true } }).replyOnce(200, { active: true }); ${true} | ${false}
createComponent({ initialActivated: false, formPath }); `(
'when initialActivated=$initialActivated and value=$value',
return wrapper.vm.toggleActivated(true).then(() => { ({ initialActivated, value }) => {
expect(wrapper.find(ToggleButton).props('value')).toBe(true); beforeEach(() => {
}); const formPath = 'some/path';
}); mockAxios
.onPut(formPath, { service: { active: value } })
it('disables toggle when initialActivated=true', () => { .replyOnce(200, { active: value });
mockAxios.onPut(formPath, { service: { active: false } }).replyOnce(200, { active: false }); createComponent({ initialActivated, formPath });
createComponent({ initialActivated: true, formPath });
return wrapper.vm.toggleActivated(value);
return wrapper.vm.toggleActivated(false).then(() => { });
expect(wrapper.find(ToggleButton).props('value')).toBe(false);
}); it(`updates toggle button value to ${value}`, () => {
}); expect(wrapper.find(ToggleButton).props('value')).toBe(value);
});
it('updates visible status icons', () => {
expect(findActiveStatusIcon(!value)).toHaveClass('d-none');
expect(findActiveStatusIcon(value)).not.toHaveClass('d-none');
});
},
);
}); });
describe('error is encountered', () => { describe('error is encountered', () => {
......
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