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

fix the upload profile image button #614

Merged
9 changes: 9 additions & 0 deletions app/controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const BASE_URL = ENV.BASE_API_URL;
export default class ProfileController extends Controller {
@service toast;
@service router;
get isDev() {
if (
this.router.currentRoute &&
this.router.currentRoute.queryParams.dev === 'true'
) {
return this.router.currentRoute.queryParams.dev;
}
return false;
}
get imageUploadUrl() {
return `${BASE_URL}/users/picture`;
}
Expand Down
16 changes: 15 additions & 1 deletion app/styles/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

.profile-page-error {
text-align: center;
text-align: center;
color: red;
}

Expand Down Expand Up @@ -91,6 +91,7 @@
aspect-ratio: 1;
margin: auto;
text-align: center;
position: relative;
}

.profile-form .user__pic {
Expand All @@ -101,6 +102,19 @@

.edit-btn {
padding: 0;
margin-top: 0.5rem;
color: var(--profile-edit-btn-clr);
font-weight: 600;
font-size: 1rem;
}

.profile-edit-button {
padding: 8px;
z-index: 10;
border-radius: 100%;
position: absolute;
top: 8px;
right: 12px;
mdansarijaved marked this conversation as resolved.
Show resolved Hide resolved
font-size: 1rem;
margin-top: 0.5rem;
color: var(--profile-edit-btn-clr);
Expand Down
23 changes: 15 additions & 8 deletions app/templates/profile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
<img
class='user__pic'
src={{'dummyProfilePicture.png'}}
alt='user profile '
alt='user profile'
/>
{{/if}}
<Button
@onClick={{this.handleShowEditProfilePictureModal}}
@class='edit-btn btn'
@data-test-btn='edit'
>
Update Picture
</Button>

{{#if this.isDev}}
<Button @onClick={{this.handleShowEditProfilePictureModal}}
@class='profile-edit-button '
@data-test-btn='edit'>
<FaIcon @icon="edit" />
</Button>
{{else}}
<Button @onClick={{this.handleShowEditProfilePictureModal}}
@class='edit-btn btn'
@data-test-btn='edit'>
Update Picture
</Button>
{{/if}}
</div>
<div class='profile-form-grid'>
{{#if (get @model 'isDeveloper')}}
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/components/profile-field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module('Integration | Component | profile-field', function (hooks) {
});

await render(hbs`
<ProfileField
@label={{this.label}}
<ProfileField
@label={{this.label}}
@icon_url={{this.icon_url}}
/>
`);
Expand All @@ -35,8 +35,8 @@ module('Integration | Component | profile-field', function (hooks) {
});

await render(hbs`
<ProfileField
@showError={{this.showError}}
<ProfileField
@showError={{this.showError}}
@errorMessage={{this.errorMessage}}
/>
`);
Expand All @@ -53,8 +53,8 @@ module('Integration | Component | profile-field', function (hooks) {
});

await render(hbs`
<ProfileField
@label={{this.label}}
<ProfileField
@label={{this.label}}
@icon_url={{this.icon_url}}
@isDeveloper={{this.isDeveloper}}
/>
Expand All @@ -80,8 +80,8 @@ module('Integration | Component | profile-field', function (hooks) {
});

await render(hbs`
<ProfileField
@label={{this.label}}
<ProfileField
@label={{this.label}}
@icon_url={{this.icon_url}}
@isDeveloper={{this.isDeveloper}}
/>
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/components/profile-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | profile-component', function (hooks) {
setupRenderingTest(hooks);

test('button appearance based on isDev property', async function (assert) {
this.set('handleShowEditProfilePictureModal', function () {
//
});
mdansarijaved marked this conversation as resolved.
Show resolved Hide resolved

this.set('isDev', true);

await render(hbs`
{{#if this.isDev}}
<Button @onClick={{this.handleShowEditProfilePictureModal}}
@class='profile-edit-button '
@data-test-btn='edit'>
<FaIcon @icon="edit" />
</Button>
{{else}}
<Button @onClick={{this.handleShowEditProfilePictureModal}}
@class='edit-btn btn'
@data-test-btn='edit'>
Update Picture
</Button>
{{/if}}
`);

assert.dom('[data-test-btn="edit"]').exists();
assert.dom('[data-test-btn="edit"]').hasClass('profile-edit-button');

this.set('isDev', false);

await settled();

assert.dom('[data-test-btn="edit"]').exists();
assert.dom('[data-test-btn="edit"]').hasClass('edit-btn');
assert.dom('[data-test-btn="edit"]').hasText('Update Picture');
});
});
12 changes: 12 additions & 0 deletions tests/unit/routes/profile-test.js
mdansarijaved marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ module('Unit | Route | profile', function (hooks) {
assert.dom('[data-test-modal="image-upload"]').exists();
assert.dom('[data-test-btn="browse"]').exists();
});
test('button appearance based on dev query param', async (assert) => {
await visit('/profile?dev=true');

assert.dom('[data-test-btn="edit"]').exists();
assert.dom('[data-test-btn="edit"]').hasClass('profile-edit-button');

await visit('/profile?dev=false');

assert.dom('[data-test-btn="edit"]').exists();
assert.dom('[data-test-btn="edit"]').hasClass('edit-btn');
assert.dom('[data-test-btn="edit"]').hasText('Update Picture');
});
});
Loading