|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe SocleDeBasePresenter do |
| 6 | + let(:category) do |
| 7 | + create(:category, key: 'identite_entreprise', |
| 8 | + buyer_label: "Identité de l'entreprise", |
| 9 | + candidate_label: 'Les informations du marché et de votre entreprise') |
| 10 | + end |
| 11 | + let(:subcategory) do |
| 12 | + create(:subcategory, category:, key: 'identite_entreprise_identification', |
| 13 | + buyer_label: "Identification de l'entreprise", |
| 14 | + candidate_label: 'Informations de votre entreprise') |
| 15 | + end |
6 | 16 | let(:market_attribute) do |
7 | 17 | build(:market_attribute, |
8 | 18 | key: 'identite_entreprise_identification_siret', |
9 | 19 | category_key: 'identite_entreprise', |
10 | 20 | subcategory_key: 'identite_entreprise_identification', |
| 21 | + subcategory:, |
11 | 22 | mandatory: true, |
12 | 23 | api_name: 'Insee') |
13 | 24 | end |
|
55 | 66 | end |
56 | 67 |
|
57 | 68 | describe '#buyer_category_label' do |
58 | | - it 'returns the buyer category label from i18n' do |
| 69 | + it 'returns the buyer label from the category record' do |
59 | 70 | expect(presenter.buyer_category_label).to eq("Identité de l'entreprise") |
60 | 71 | end |
| 72 | + |
| 73 | + context 'when subcategory is nil' do |
| 74 | + let(:market_attribute) { build(:market_attribute, subcategory: nil, category_key: 'identite_entreprise') } |
| 75 | + |
| 76 | + it 'falls back to humanized category_key' do |
| 77 | + expect(presenter.buyer_category_label).to eq('Identite entreprise') |
| 78 | + end |
| 79 | + end |
61 | 80 | end |
62 | 81 |
|
63 | 82 | describe '#buyer_subcategory_label' do |
64 | | - it 'returns the buyer subcategory label from i18n' do |
| 83 | + it 'returns the buyer label from the subcategory record' do |
65 | 84 | expect(presenter.buyer_subcategory_label).to eq("Identification de l'entreprise") |
66 | 85 | end |
| 86 | + |
| 87 | + context 'when subcategory is nil' do |
| 88 | + let(:market_attribute) { build(:market_attribute, subcategory: nil, subcategory_key: 'some_key') } |
| 89 | + |
| 90 | + it 'falls back to humanized subcategory_key' do |
| 91 | + expect(presenter.buyer_subcategory_label).to eq('Some key') |
| 92 | + end |
| 93 | + end |
67 | 94 | end |
68 | 95 |
|
69 | 96 | describe '#candidate_category_label' do |
70 | | - it 'returns the candidate category label from i18n' do |
| 97 | + it 'returns the candidate label from the category record' do |
71 | 98 | expect(presenter.candidate_category_label).to eq('Les informations du marché et de votre entreprise') |
72 | 99 | end |
73 | 100 | end |
74 | 101 |
|
75 | 102 | describe '#candidate_subcategory_label' do |
76 | | - it 'returns the candidate subcategory label from i18n' do |
| 103 | + it 'returns the candidate label from the subcategory record' do |
77 | 104 | expect(presenter.candidate_subcategory_label).to eq('Informations de votre entreprise') |
78 | 105 | end |
79 | 106 | end |
|
0 commit comments