Skip to content

Commit

Permalink
fix: hbs warnings (adfinis#894)
Browse files Browse the repository at this point in the history
* fix: hbs warnings

* fix: (user-controller): action naming and invocation

* fix: writing tests for new change

* fix: code readability
  • Loading branch information
MitanOmar committed Apr 3, 2023
1 parent 9c87083 commit b00f97b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/components/paginated-table/foot/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{#if (gt this.pages 1)}}
<PaginationPager @current={{this.page}} @count={{this.pages}} @class="pagination-nav" />
{{/if}}
{{pagination-limit page=this.page page_size=this.page_size}}
<PaginationLimit page={{this.page}} page_size={{this.page_size}} />
</td>
</tr>
{{yield to='inverse'}}
2 changes: 1 addition & 1 deletion app/components/sy-toggle/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="sy-toggle {{if @value 'active' 'inactive'}}"
title={{concat @hint (if @disabled " (disabled)")}}
tabindex="0"
role="button"
role="link"
{{on "click" (optional (unless @disabled @onToggle))}}
{{on "keyup" this.handleKeyUp}}
>
Expand Down
2 changes: 1 addition & 1 deletion app/components/worktime-balance-chart/template.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{yield}}
<div>{{yield}}</div>
4 changes: 2 additions & 2 deletions app/users/edit/credits/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<tbody>
{{#each absenceCredits as |absenceCredit|}}
<tr
role="link"
class={{if (can "edit absence-credit") "pointer"}}
{{on
"click"
Expand Down Expand Up @@ -89,7 +90,6 @@
<br />
<LinkTo
@route="users.edit.credits.absence-credits.new"
@tagName="button"
class="btn btn-success"
>Add new credit</LinkTo>
{{/if}}
Expand Down Expand Up @@ -128,6 +128,7 @@
<tbody>
{{#each overtimeCredits as |overtimeCredit|}}
<tr
role="link"
class="{{if (can 'edit overtime-credit') 'pointer'}}"
{{on
"click"
Expand Down Expand Up @@ -169,7 +170,6 @@
<br />
<LinkTo
@route="users.edit.credits.overtime-credits.new"
@tagName="button"
class="btn btn-success"
>Add new credit</LinkTo>
{{/if}}
Expand Down
8 changes: 8 additions & 0 deletions app/users/edit/responsibilities/controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { task } from "ember-concurrency";
import QueryParams from "ember-parachute";
import moment from "moment";
Expand All @@ -7,11 +9,17 @@ import { all } from "rsvp";
const UsersEditResponsibilitiesQueryParams = new QueryParams({});

export default Controller.extend(UsersEditResponsibilitiesQueryParams.Mixin, {
router: service("router"),

setup() {
this.projects.perform();
this.supervisees.perform();
},

openSupervisorProfile: action(function (superviseId) {
return this.router.transitionTo("users.edit", superviseId);
}),

projects: task(function* () {
return yield this.store.query("project", {
has_reviewer: this.get("model.id"),
Expand Down
9 changes: 4 additions & 5 deletions app/users/edit/responsibilities/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@
</thead>
<tbody>
{{#each supervisees as |supervisee|}}
<LinkTo
@route="users.edit"
@model={{supervisee.id}}
@tagName="tr"
<tr
role="link"
{{on "click" (fn this.openSupervisorProfile supervisee.id)}}
class="pointer"
>
<td>{{supervisee.fullName}}</td>
Expand All @@ -90,7 +89,7 @@
}}
<td
>{{supervisee.absenceBalances.firstObject.balance}}</td>
</LinkTo>
</tr>
{{/each}}
</tbody>
</table>
Expand Down
7 changes: 6 additions & 1 deletion app/users/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Controller from "@ember/controller";
import { computed } from "@ember/object";
import { computed, action } from "@ember/object";
import { reads } from "@ember/object/computed";
import { inject as service } from "@ember/service";
import { task, timeout, hash } from "ember-concurrency";
Expand Down Expand Up @@ -31,9 +31,14 @@ const UsersQueryParams = new QueryParams({

const UsersIndexController = Controller.extend(UsersQueryParams.Mixin, {
session: service("session"),
router: service("router"),

currentUser: reads("session.data.user"),

viewUserProfile: action(function (userId) {
return this.router.transitionTo("users.edit", userId);
}),

selectedSupervisor: computed(
"prefetchData.lastSuccessful.value.supervisor",
"store",
Expand Down
9 changes: 4 additions & 5 deletions app/users/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@
@containerSelector=".page-content--scroll"
as |user|
>
<LinkTo
@route="users.edit"
@model={{user.id}}
@tagName="tr"
<tr
role="link"
{{on "click" (fn this.viewUserProfile user.id)}}
class="pointer"
>
<td
Expand All @@ -99,7 +98,7 @@
{{format-duration user.currentWorktimeBalance.balance false}}
</span>
</td>
</LinkTo>
</tr>
</VerticalCollection>
</table>
{{/if}}
Expand Down
21 changes: 18 additions & 3 deletions tests/acceptance/users-edit-responsibilities-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { visit } from "@ember/test-helpers";
import { visit, currentURL, click } from "@ember/test-helpers";
import { setupMirage } from "ember-cli-mirage/test-support";
import { setupApplicationTest } from "ember-qunit";
import { authenticateSession } from "ember-simple-auth/test-support";
Expand All @@ -9,15 +9,30 @@ module("Acceptance | users edit responsibilities", function (hooks) {
setupMirage(hooks);

hooks.beforeEach(async function () {
this.user = this.server.create("user");
this.admin = this.server.create("user", {
isSuperuser: true,
firstName: "Admin FirstName",
lastName: "Admin LastName",
});
this.user = this.server.create("user", {
supervisorIds: [this.admin.id],
firstName: "FirstName",
lastName: "LastName",
});

// eslint-disable-next-line camelcase
await authenticateSession({ user_id: this.user.id });
await authenticateSession({ user_id: this.admin.id });
});

test("can visit /users/:id/responsibilities", async function (assert) {
await visit(`/users/1/responsibilities`);

assert.dom(".card").exists({ count: 2 });
});

test("Super user can visit the users profile", async function (assert) {
await visit(`/users/1/responsibilities`);
await click("tbody tr:nth-child(2)");
assert.strictEqual(currentURL(), `/users/${this.user.id}`);
});
});
6 changes: 6 additions & 0 deletions tests/acceptance/users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ module("Acceptance | users", function (hooks) {

assert.strictEqual(currentURL(), "/users");
});
test("can open other users profile", async function (assert) {
await visit("/users");
await waitFor("table tbody tr");
await click("table tbody tr");
assert.strictEqual(currentURL(), "/users/2");
});
});

0 comments on commit b00f97b

Please sign in to comment.