diff --git a/addon/components/o-s-s/progress-bar.hbs b/addon/components/o-s-s/progress-bar.hbs index 1bafa09ce..3dadf794c 100644 --- a/addon/components/o-s-s/progress-bar.hbs +++ b/addon/components/o-s-s/progress-bar.hbs @@ -7,16 +7,14 @@ {{#if this.hasSkins}}
{{#each this.progressSegments as |skin|}} - {{#if (this.isSegmentVisible skin=skin)}} -
- {{/if}} +
{{/each}}
{{else}} diff --git a/addon/components/o-s-s/progress-bar.ts b/addon/components/o-s-s/progress-bar.ts index 866b9f6d4..3e25f48e8 100644 --- a/addon/components/o-s-s/progress-bar.ts +++ b/addon/components/o-s-s/progress-bar.ts @@ -36,12 +36,8 @@ export default class OSSProgressBar extends Component { } } - isSegmentVisible = helper((_, { skin }: { skin: ProgressBarSkins }): boolean => { - return this.hasSkins && (this.skins[skin] || 0) > 0; - }); - getSegmentValue = helper((_, { skin }: { skin: ProgressBarSkins }): number => { - return this.hasSkins ? this.skins[skin] || 0 : 0; + return this.skins[skin] ?? 0; }); progressBarStyle = helper((_, { value }: { value: number }): ReturnType => { @@ -59,7 +55,7 @@ export default class OSSProgressBar extends Component { } get progressSegments(): ProgressBarSkins[] { - return this.hasSkins ? (Object.keys(this.skins) as ProgressBarSkins[]) : []; + return Object.keys(this.skins) as ProgressBarSkins[]; } get computedStyles(): string { diff --git a/tests/dummy/app/controllers/visual.ts b/tests/dummy/app/controllers/visual.ts index 5adb0a37a..02407c670 100644 --- a/tests/dummy/app/controllers/visual.ts +++ b/tests/dummy/app/controllers/visual.ts @@ -116,9 +116,14 @@ export default class Visual extends Controller { @tracked progressBarWarning: number = 25; @tracked progressBarDanger: number = 15; + @tracked progressBarSuccess2: number = 30; + @tracked progressBarWarning2: number = 25; + @tracked progressBarDanger2: number = 15; + constructor() { super(); this.liveProgressBar(); + this.liveProgressBarZero(); } get progressBarSkins(): Record { @@ -129,6 +134,14 @@ export default class Visual extends Controller { }; } + get progressBarSkins2(): Record { + return { + success: this.progressBarSuccess2, + warning: this.progressBarWarning2, + danger: this.progressBarDanger2 + }; + } + liveProgressBar = (negative: boolean = false): void => { const value = negative ? -1 : 1; setTimeout(() => { @@ -140,6 +153,17 @@ export default class Visual extends Controller { }, 2000); }; + liveProgressBarZero = (negative: boolean = false): void => { + const value = negative ? -1 : 1; + setTimeout(() => { + this.progressBarSuccess2 = value === 1 ? 0 : 20; + this.progressBarWarning2 = value === 1 ? 0 : 10; + this.progressBarDanger2 = value === 1 ? 0 : 5; + + this.liveProgressBarZero(!negative); + }, 2000); + }; + @action redirectTo(route: string): void { console.log('Redirect to', route); diff --git a/tests/dummy/app/templates/visual.hbs b/tests/dummy/app/templates/visual.hbs index 49f5a677a..0d9f5a749 100644 --- a/tests/dummy/app/templates/visual.hbs +++ b/tests/dummy/app/templates/visual.hbs @@ -37,6 +37,16 @@ Multi-skin Progress bars
+ + + `); + await render(hbs``); assert.dom('.oss-progress-bar').hasClass('oss-progress-bar--multi-skin'); }); test('if the value is defined, the progress bar has the correct success, warning, and danger classes', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner').hasClass('oss-progress-bar__inner--pending'); assert.dom('.oss-progress-bar__inner:nth-of-type(2)').hasClass('oss-progress-bar__inner--success'); @@ -200,26 +200,35 @@ module('Integration | Component | o-s-s/progress-bar', function (hooks) { assert.dom('.oss-progress-bar__inner:nth-of-type(4)').hasClass('oss-progress-bar__inner--danger'); }); + test('if the values are equals to 0, it renders an empty progress bar', async function (assert) { + this.skins = { pending: 0, success: 0, warning: 0, danger: 0 }; + await render(hbs``); + + assert + .dom('.oss-progress-bar .oss-progress-bar__inner') + .hasAttribute('style', 'width: 0%;--progress-bar-animation-width: 0%'); + }); + test('if the value is defined, the progress bar has the correct pending value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--pending').hasAttribute('aria-valuenow', '10'); }); test('if the value is defined, the progress bar has the correct success value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--success').hasAttribute('aria-valuenow', '30'); }); test('if the value is defined, the progress bar has the correct warning value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--warning').hasAttribute('aria-valuenow', '25'); }); test('if the value is defined, the progress bar has the correct danger value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--danger').hasAttribute('aria-valuenow', '15'); }); @@ -232,13 +241,11 @@ module('Integration | Component | o-s-s/progress-bar', function (hooks) { ); }); - await render( - hbs`` - ); + await render(hbs``); }); test('if the value is updated, the classes also update', async function (assert) { - await render(hbs``); + await render(hbs``); this.set('skins', { success: 50, warning: 30, danger: 20 }); @@ -249,28 +256,28 @@ module('Integration | Component | o-s-s/progress-bar', function (hooks) { }); test('if only the pending value is defined, the progress bar has the correct pending value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--pending').exists(); assert.dom('.oss-progress-bar__inner--pending').hasAttribute('aria-valuenow', '33'); }); test('if only the success value is defined, the progress bar has the correct success value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--success').exists(); assert.dom('.oss-progress-bar__inner--success').hasAttribute('aria-valuenow', '33'); }); test('if only the warning value is defined, the progress bar has the correct warning value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--warning').exists(); assert.dom('.oss-progress-bar__inner--warning').hasAttribute('aria-valuenow', '33'); }); test('if only the danger value is defined, the progress bar has the correct danger value', async function (assert) { - await render(hbs``); + await render(hbs``); assert.dom('.oss-progress-bar__inner--danger').exists(); assert.dom('.oss-progress-bar__inner--danger').hasAttribute('aria-valuenow', '33');