Skip to content

Commit

Permalink
Display estimated time correctly in wiki macro
Browse files Browse the repository at this point in the history
For instance with the following wiki text: "Current estimates: workPackageValue:1234:estimatedTime".
  • Loading branch information
cbliard committed Jan 8, 2024
1 parent 6bdc1ba commit 070b68c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export class EstimatedTimeDisplayField extends DisplayField {
public renderSeparator(element:HTMLElement) {
const span = document.createElement('span');
span.classList.add('-separator');
span.textContent = '·';
span.ariaHidden = 'true';
element.appendChild(span);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
width: 100%
text-align: center

// READ value of display fields in wiki macros
display-field
& .split-time-field
white-space: nowrap

.-separator
display: inline-block
width: 1rem
padding-left: 0.25rem
padding-right: 0.25rem
text-align: center


// READ value of edit fields
.inline-edit--display-field
display: inline-block
Expand Down Expand Up @@ -87,8 +101,7 @@
.-actual-value
@include wp-table--actual-time-values

.-separator::before
content: "·"
.-separator
display: inline-block
width: 1rem
padding-left: 0.25rem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

require 'spec_helper'

RSpec.describe 'Estimated hours display' do
RSpec.describe 'Estimated hours display', :js do
shared_let(:project) { create(:project) }
shared_let(:user) { create(:admin) }
shared_let(:wiki_page) { create(:wiki_page, wiki: project.wiki) }
shared_let(:query) do
create(:query,
project:,
Expand All @@ -46,6 +47,7 @@
end

let(:wp_table) { Pages::WorkPackagesTable.new project }
let(:editor) { Components::WysiwygEditor.new }

before do
WorkPackages::UpdateAncestorsService
Expand All @@ -55,50 +57,50 @@
login_as(user)
end

context "with both work and derived work" do
let_work_packages(<<~TABLE)
hierarchy | work |
parent | 1h |
child | 3h |
TABLE

it 'work package index', :js do
shared_examples 'estimated time display' do |expected_text:|
it 'work package index' do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, estimatedTime: "1 hΣ 4 h"
parent, estimatedTime: expected_text
)
end

it 'work package details', :js do
it 'work package details' do
visit work_package_path(parent.id)

expect(page).to have_content("Work\n1 hΣ 4 h")
expect(page).to have_content("Work\n#{expected_text}")
end

it 'wiki page workPackageValue:id:estimatedTime macro' do
visit edit_project_wiki_path(project, wiki_page.id)

editor.set_markdown("workPackageValue:#{parent.id}:estimatedTime")
click_on 'Save'

expect(page).to have_css('.wiki-content', text: expected_text)
end
end

context "with just work" do
context "with both work and derived work" do
let_work_packages(<<~TABLE)
hierarchy | work |
parent | 1h |
child | 0h |
child | 3h |
TABLE

it 'work package index', :js do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, subject: parent.subject, estimatedTime: "1 h"
)
end
include_examples 'estimated time display', expected_text: '1 h·Σ 4 h'
end

it 'work package details', :js do
visit work_package_path(parent.id)
context "with just work" do
let_work_packages(<<~TABLE)
hierarchy | work |
parent | 1h |
child | 0h |
TABLE

expect(page).to have_content("Work\n1 h")
end
include_examples 'estimated time display', expected_text: '1 h'
end

context "with just derived work with (parent work 0 h)" do
Expand All @@ -108,20 +110,7 @@
child | 3h |
TABLE

it 'work package index', :js do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, subject: parent.subject, estimatedTime: "0 hΣ 3 h"
)
end

it 'work package details', :js do
visit work_package_path(parent.id)

expect(page).to have_content("Work\n0 hΣ 3 h")
end
include_examples 'estimated time display', expected_text: '0 h·Σ 3 h'
end

context "with just derived work (parent work unset)" do
Expand All @@ -131,20 +120,7 @@
child | 3h |
TABLE

it 'work package index', :js do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, subject: parent.subject, estimatedTime: "-Σ 3 h"
)
end

it 'work package details', :js do
visit work_package_path(parent.id)

expect(page).to have_content("Work\n-Σ 3 h")
end
include_examples 'estimated time display', expected_text: '-·Σ 3 h'
end

context "with neither work nor derived work (both 0 h)" do
Expand All @@ -154,20 +130,7 @@
child | 0h |
TABLE

it 'work package index', :js do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, subject: parent.subject, estimatedTime: "0 h"
)
end

it 'work package details', :js do
visit work_package_path(parent.id)

expect(page).to have_content("Work\n0 h")
end
include_examples 'estimated time display', expected_text: '0 h'
end

context "with neither work nor derived work (both unset)" do
Expand All @@ -177,19 +140,6 @@
child | |
TABLE

it 'work package index', :js do
wp_table.visit_query query
wp_table.expect_work_package_listed child

wp_table.expect_work_package_with_attributes(
parent, subject: parent.subject, estimatedTime: "-"
)
end

it 'work package details', :js do
visit work_package_path(parent.id)

expect(page).to have_content("Work\n-")
end
include_examples 'estimated time display', expected_text: '-'
end
end

0 comments on commit 070b68c

Please sign in to comment.