Skip to content

Commit

Permalink
test: Fix of all broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Aug 11, 2023
1 parent b923b28 commit d779e04
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/services/api/charts/sector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(company_scope, enable_beta_mq_assessments: false)
@company_scope = company_scope
@enable_beta_mq_assessments = enable_beta_mq_assessments
@beta_levels = MQ::Assessment::BETA_LEVELS.each_with_object({}) { |l, r| r[l] = [] }
@empty_levels = enable_beta_mq_assessments ? DEFAULT_EMPTY_LEVELS.merge(@beta_levels) : DEFAULT_EMPTY_LEVELS
@empty_levels = enable_beta_mq_assessments ? DEFAULT_EMPTY_LEVELS.deep_merge(@beta_levels) : DEFAULT_EMPTY_LEVELS.deep_dup
end

# Returns Companies summaries (name, status) grouped by their latest MQ assessments levels.
Expand Down
Binary file modified db/test-dump.psql
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/models/mq/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

it 'should be invalid if level not recognized' do
subject.level = '5'
subject.level = '7'
expect(subject).to have(1).errors_on(:level)
end

Expand Down
7 changes: 5 additions & 2 deletions spec/services/api/charts/sector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
describe '.companies_count' do
it 'returns companies count grouped by their level' do
expect(subject.companies_count_by_level).to eq(
'0' => 0,
'1' => 1,
'2' => 0,
'3' => 0,
'4' => 1
)
end
Expand Down Expand Up @@ -96,7 +99,7 @@
describe '.companies_market_cap_by_sector' do
it 'returns Companies grouped by their sector and level' do
expect(subject.companies_market_cap_by_sector).to eq(
'Airlines' => {
sector.name => {
'0' => [],
'1' => [
{
Expand All @@ -114,7 +117,7 @@
'3' => [],
'4' => []
},
'Autos' => {
sector2.name => {
'0' => [],
'1' => [],
'2' => [],
Expand Down
10 changes: 10 additions & 0 deletions spec/support/capybara_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ def within_banking_area(header_text)
yield if block_given?
end
end

def with_mq_beta_scores
within '.mq-beta-scores' do
click_on 'BETA'
end
yield
within '.mq-beta-scores' do
click_on 'Current'
end
end
end
10 changes: 10 additions & 0 deletions spec/system/public/tpi/company_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
expect(page).to have_text('Japan Airlines')
end

it 'does not show BETA scores by default' do
expect(page).not_to have_text('Level 5 [BETA]')
end

it 'allows to show BETA scores' do
with_mq_beta_scores do
expect(page).to have_text('Level 5 [BETA]')
end
end

it 'shows management quality box' do
within 'a.summary-box-link[href="#management-quality"]' do
expect(page).to have_text('Integrating into Operational Decision Making')
Expand Down
29 changes: 28 additions & 1 deletion spec/system/public/tpi/sectors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,37 @@

# pie chart
within '.chart--mq-sector-pie-chart' do
expect(page).not_to have_text('Level 5')
expect(page).to have_selector('.companies-size', text: '111')
end

# bubble chart loads
within '.bubble-chart__container' do
expect(page).not_to have_text('Level 5')
expect(page).to have_text('Market cap')
expect(page).to have_text('Autos')
expect(page).to have_text('Airlines')
end

# all sectors chart TODO: readd this
# all sectors chart TODO: read this
# within '#cp-performance-all-sectors-chart' do
# expect(page).to have_text('Below 2 Degrees')
# expect(page).to have_text('Aluminium')
# expect(page).to have_text('Cement')
# end
end

it 'loads also beta scores' do
with_mq_beta_scores do
within '.chart--mq-sector-pie-chart' do
expect(page).to have_text('Level 5')
end

within '.bubble-chart__container' do
expect(page).to have_text('Level 5')
end
end
end
end

describe 'single sector page' do
Expand All @@ -38,9 +52,22 @@
it 'loads all elements' do
# bubble chart loads
within '.chart--mq-sector-pie-chart' do
expect(page).to have_text('Level 00 companies') # Level 0 0 companies
expect(page).to have_text('Level 12 companies') # Level 1 2 companies
expect(page).to have_text('Level 20 companies') # Level 2 0 companies
expect(page).to have_text('Level 32 companies') # Level 3 2 companies
expect(page).to have_text('Level 41 companies') # Level 4 1 companies
expect(page).not_to have_text('Level 5') # BETA level that is disabled by default
expect(page).to have_selector('.companies-size', text: '5')
end
end

it 'loads also beta scores' do
with_mq_beta_scores do
within '.chart--mq-sector-pie-chart' do
expect(page).to have_text('Level 5')
end
end
end
end
end

0 comments on commit d779e04

Please sign in to comment.