Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added stepper component and tests #408

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/components/stepper.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#if this.arePropsValid}}
<article data-test-stepper class='stepper'>
<div class='stepper-progress--container'>
<div class='progress'></div>
{{#each this.numberOfSteps as |_ index|}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have we used _ here with index?

<div data-test-stepper-step={{getStepperStepDataTestSelector index completedSteps=@completedSteps }}
class='stepper__step'>
{{#if (eq index this.parsedCompletedSteps)}}
<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='#1d1283' viewBox='0 0 256 256'>
<path d='M232,128A104,104,0,1,1,128,24,104.13,104.13,0,0,1,232,128Z'>
</path>
</svg>
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use svg in img tag?

{{else if
(lt index this.parsedCompletedSteps)
}}
<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='#1d1283' viewBox='0 0 256 256'>
<path
d='M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm45.66,85.66-56,56a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L112,148.69l50.34-50.35a8,8,0,0,1,11.32,11.32Z'>
</path>
</svg>
Comment on lines +16 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use svg in img tag?

{{/if}}
</div>
{{/each}}
</div>
</article>
{{/if}}
17 changes: 17 additions & 0 deletions app/components/stepper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Component from '@glimmer/component';

export default class StepperComponent extends Component {
get arePropsValid() {
const { totalSteps, completedSteps } = this.args;
return !isNaN(totalSteps) && !isNaN(completedSteps) && totalSteps > 0;
}

get numberOfSteps() {
const times = Number.parseInt(this.args.totalSteps, 10);
return new Array(times);
}

get parsedCompletedSteps() {
return parseInt(this.args.completedSteps, 10);
}
}
13 changes: 13 additions & 0 deletions app/helpers/getStepperStepDataTestSelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { helper } from '@ember/component/helper';

function getStepperStepDataTestSelector([index], { completedSteps }) {
if (index < completedSteps) {
return 'completed';
} else if (index === completedSteps) {
return 'active';
} else {
return 'idle';
Comment on lines +5 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use enums (constants) here ?

}
}

export default helper(getStepperStepDataTestSelector);
36 changes: 36 additions & 0 deletions app/styles/stepper.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.stepper {
text-align: center;
}

.stepper-progress--container {
display: flex;
justify-content: space-between;
position: relative;
}

.progress {
background-color: var(--line-border-fill);
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
height: 4px;
width: 100%;
z-index: 1;
transition: 0.4s ease;
}

.stepper__step {
background-color: #fff;
color: #999;
Comment on lines +24 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use CSS variables here too ?

border-radius: 50%;
height: 20px;
width: 20px;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid var(--line-border-empty);
border-color: var(--line-border-fill);
transition: 0.4s ease;
z-index: 2;
}
3 changes: 3 additions & 0 deletions app/styles/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@

--placeholder-text-color: grey;

--line-border-fill: #1d1283;
--line-border-empty: #e0e0e0;

--profile-field-input-bg-clr: #f9fafb;
--profile-field-input-border-clr: #d1d5db;
--profile-input-outline-clr: #1c64f2;
Expand Down
58 changes: 58 additions & 0 deletions tests/integration/components/stepper-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | stepper', (hooks) => {
setupRenderingTest(hooks);

test('it not renders the stepper component when no props passed', async function (assert) {
await render(hbs`<Stepper />`);

assert.dom('[data-test-stepper]').doesNotExist();
});

test('it renders the stepper component without completed steps', async function (assert) {
this.setProperties({
totalSteps: 5,
completedSteps: 0,
});

await render(
hbs`<Stepper
@totalSteps={{this.totalSteps}}
@completedSteps={{this.completedSteps}}
/>`
);

assert.dom('[data-test-stepper]').exists();
assert
.dom('[data-test-stepper-step="active"]')
.exists({ count: 1 }, 'Active Step present on step-1 in the stepper');
assert
.dom('[data-test-stepper-step="completed"]')
.exists({ count: 0 }, 'No Cleared Steps present in the stepper');
});

test('it renders the stepper component with completed steps', async function (assert) {
this.setProperties({
totalSteps: 5,
completedSteps: 2,
});

await render(
hbs`<Stepper
@totalSteps={{this.totalSteps}}
@completedSteps={{this.completedSteps}}
/>`
);

assert.dom('[data-test-stepper]').exists();
assert
.dom('[data-test-stepper-step="active"]')
.exists({ count: 1 }, 'Active Step present on step-3 in the stepper');
assert
.dom('[data-test-stepper-step="completed"]')
.exists({ count: 2 }, 'Two Cleared Steps present in the stepper');
});
});