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

dev to main sync #617

Merged
merged 4 commits into from
Oct 15, 2024
Merged
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
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
2 changes: 0 additions & 2 deletions app/helpers/convertDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const timeDifference = (timestamp, timeNow) => {
const months = Math.floor(days / 30);
const years = Math.floor(months / 12);

console.log({ timeInSec, mins, hours, days, months, years }); // Debug log

if (timeInSec < 1) {
return { result: '', cycle: 'just now' };
}
Expand Down
15 changes: 14 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,18 @@

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

.profile-edit-button {
padding: 0.5rem;
border-radius: 100%;
position: absolute;
top: 0.5rem;
right: 1rem;
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
57 changes: 57 additions & 0 deletions tests/integration/components/profile-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled, click } 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', () => {
this.set('showEditProfilePictureModal', true);
});

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');

await click('[data-test-btn="edit"]');

assert.ok(
this.showEditProfilePictureModal,
'Modal should be shown after clicking the 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');

await click('[data-test-btn="edit"]');

assert.ok(
this.showEditProfilePictureModal,
'Modal should be shown after clicking the button'
);
});
});
12 changes: 12 additions & 0 deletions tests/unit/routes/profile-test.js
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