Merge pull request #8246 from tchak/feat-simple-selects

refactor(champs): pays, regions et departements as simple select
This commit is contained in:
Paul Chavard 2022-12-21 15:07:26 +01:00 committed by GitHub
commit 5a7ddd52d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 1454 additions and 144 deletions

View file

@ -1,3 +1,13 @@
class EditableChamp::DepartementsComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
private
def options
APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
end
def select_options
{ selected: @champ.selected }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
end
end

View file

@ -1,7 +1 @@
= @form.hidden_field :value
= @form.hidden_field :external_id
= react_component("ComboDepartementsSearch",
required: @champ.required?,
id: @champ.input_id,
className: "width-33-desktop width-100-mobile",
describedby: @champ.describedby_id)
= @form.select :value, options, select_options, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id }, class: "width-33-desktop width-100-mobile"

View file

@ -1,3 +1,18 @@
class EditableChamp::PaysComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
private
def options
options = APIGeoService.countries.map { [_1[:name], _1[:code]] }
# For legacy fields, selected value is non standard country name. Add it to the list.
if (@champ.selected&.size || 0) > 2
options.unshift([@champ.selected, @champ.selected])
end
options
end
def select_options
{ selected: @champ.selected }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
end
end

View file

@ -1,7 +1 @@
= @form.hidden_field :value
= @form.hidden_field :external_id
= react_component("ComboPaysSearch",
required: @champ.required?,
id: @champ.input_id,
className: "width-33-desktop width-100-mobile",
describedby: @champ.describedby_id)
= @form.select :value, options, select_options, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id }, class: "width-33-desktop width-100-mobile"

View file

@ -1,3 +1,13 @@
class EditableChamp::RegionsComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
private
def options
APIGeoService.regions.map { [_1[:name], _1[:code]] }
end
def select_options
{ selected: @champ.selected }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
end
end

View file

@ -1,7 +1 @@
= @form.hidden_field :value
= @form.hidden_field :external_id
= react_component("ComboRegionsSearch",
required: @champ.required?,
id: @champ.input_id,
className: "width-33-desktop width-100-mobile",
describedby: @champ.describedby_id)
= @form.select :value, options, select_options, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id }, class: "width-33-desktop width-100-mobile"

View file

@ -1,20 +0,0 @@
class API::PaysController < ApplicationController
before_action :authenticate_logged_user!
def index
countries = CountriesService.get('FR').zip(CountriesService.get(I18n.locale))
countries = countries.map do |(code, value_fr), (localized_code, localized_value)|
if code != localized_code
raise "Countries lists mismatch. It means i18n_data gem has some internal inconsistencies."
end
{
code: code,
value: value_fr,
label: localized_value
}
end
render json: countries
end
end

View file

@ -54,11 +54,13 @@ class API::V2::Schema < GraphQL::Schema
Types::Champs::DateChampType,
Types::Champs::DatetimeChampType,
Types::Champs::DecimalNumberChampType,
Types::Champs::DepartementChampType,
Types::Champs::DossierLinkChampType,
Types::Champs::IntegerNumberChampType,
Types::Champs::LinkedDropDownListChampType,
Types::Champs::MultipleDropDownListChampType,
Types::Champs::PieceJustificativeChampType,
Types::Champs::RegionChampType,
Types::Champs::RepetitionChampType,
Types::Champs::SiretChampType,
Types::Champs::TextChampType,

View file

@ -442,6 +442,18 @@ class API::V2::StoredQuery
code
}
}
... on DepartementChamp {
departement {
name
code
}
}
... on RegionChamp {
region {
name
code
}
}
... on SiretChamp {
etablissement {
...PersonneMoraleFragment

View file

@ -685,6 +685,21 @@ type Departement {
name: String!
}
type DepartementChamp implements Champ {
departement: Departement
id: ID!
"""
Libellé du champ.
"""
label: String!
"""
La valeur du champ sous forme texte.
"""
stringValue: String
}
"""
Represents direct upload credentials
"""
@ -2088,6 +2103,26 @@ type Query {
): GroupeInstructeurWithDossiers!
}
type Region {
code: String!
name: String!
}
type RegionChamp implements Champ {
id: ID!
"""
Libellé du champ.
"""
label: String!
region: Region
"""
La valeur du champ sous forme texte.
"""
stringValue: String
}
type RepetitionChamp implements Champ {
champs: [Champ!]! @deprecated(reason: "Utilisez le champ `rows` à la place.")
id: ID!

View file

@ -31,6 +31,18 @@ module Types
else
Types::Champs::TextChampType
end
when ::Champs::DepartementChamp
if context.has_fragment?(:DepartementChamp)
Types::Champs::DepartementChampType
else
Types::Champs::TextChampType
end
when ::Champs::RegionChamp
if context.has_fragment?(:RegionChamp)
Types::Champs::RegionChampType
else
Types::Champs::TextChampType
end
when ::Champs::DossierLinkChamp
Types::Champs::DossierLinkChampType
when ::Champs::PieceJustificativeChamp

View file

@ -7,13 +7,8 @@ module Types::Champs
field :code, String, "Le code INSEE", null: false
end
class DepartementType < Types::BaseObject
field :name, String, null: false
field :code, String, null: false
end
field :commune, CommuneType, null: true
field :departement, DepartementType, null: true
field :departement, Types::Champs::DepartementChampType::DepartementType, null: true
def commune
if object.code?

View file

@ -0,0 +1,16 @@
module Types::Champs
class DepartementChampType < Types::BaseObject
implements Types::ChampType
class DepartementType < Types::BaseObject
field :name, String, null: false
field :code, String, null: false
end
field :departement, DepartementType, null: true
def departement
object if object.external_id.present?
end
end
end

View file

@ -0,0 +1,16 @@
module Types::Champs
class RegionChampType < Types::BaseObject
implements Types::ChampType
class RegionType < Types::BaseObject
field :name, String, null: false
field :code, String, null: false
end
field :region, RegionType, null: true
def region
object if object.external_id.present?
end
end
end

View file

@ -1,9 +1,7 @@
import React from 'react';
import { QueryClientProvider } from 'react-query';
import { matchSorter } from 'match-sorter';
import ComboSearch, { ComboSearchProps } from './ComboSearch';
import { queryClient } from './shared/queryClient';
type DepartementResult = { code: string; nom: string };
@ -42,13 +40,3 @@ export function ComboDepartementsSearch({
/>
);
}
export default function ComboDepartementsSearchDefault(
params: ComboDepartementsSearchProps
) {
return (
<QueryClientProvider client={queryClient}>
<ComboDepartementsSearch {...params} />
</QueryClientProvider>
);
}

View file

@ -1,20 +0,0 @@
import React from 'react';
import { QueryClientProvider } from 'react-query';
import ComboSearch, { ComboSearchProps } from './ComboSearch';
import { queryClient } from './shared/queryClient';
export default function ComboPaysSearch(
props: ComboSearchProps<{ code: string; value: string; label: string }>
) {
return (
<QueryClientProvider client={queryClient}>
<ComboSearch
{...props}
scope="pays"
minimumInputLength={0}
transformResult={({ code, value, label }) => [code, value, label]}
/>
</QueryClientProvider>
);
}

View file

@ -1,20 +0,0 @@
import React from 'react';
import { QueryClientProvider } from 'react-query';
import ComboSearch, { ComboSearchProps } from './ComboSearch';
import { queryClient } from './shared/queryClient';
export default function ComboRegionsSearch(
props: ComboSearchProps<{ code: string; nom: string }>
) {
return (
<QueryClientProvider client={queryClient}>
<ComboSearch
{...props}
scope="regions"
minimumInputLength={0}
transformResult={({ code, nom }) => [code, nom]}
/>
</QueryClientProvider>
);
}

View file

@ -21,4 +21,48 @@
# type_de_champ_id :integer
#
class Champs::DepartementChamp < Champs::TextChamp
def for_export
[name, code]
end
def to_s
formatted_value
end
def for_tag
formatted_value
end
def selected
code
end
def code
external_id || APIGeoService.departement_code(name)
end
def name
maybe_code_and_name = value&.match(/(\d+) - (.+)/)
if maybe_code_and_name
maybe_code_and_name[2]
else
value
end
end
def value=(code)
if code&.size == 2
self.external_id = code
super(APIGeoService.departement_name(code))
elsif code.blank?
self.external_id = nil
super(nil)
end
end
private
def formatted_value
blank? ? "" : "#{code} #{name}"
end
end

View file

@ -21,19 +21,46 @@
# type_de_champ_id :integer
#
class Champs::PaysChamp < Champs::TextChamp
def localized_value
def for_export
[formatted_value, code]
end
def to_s
formatted_value
end
def for_tag
formatted_value
end
def selected
code || value
end
def value=(code)
if code&.size == 2
self.external_id = code
super(APIGeoService.country_name(code, locale: 'FR'))
elsif code.blank?
self.external_id = nil
super(nil)
elsif code != value
self.external_id = APIGeoService.country_code(code)
super(code)
end
end
def code
external_id || APIGeoService.country_code(value)
end
private
def formatted_value
if external_id
CountriesService.get(I18n.locale)[external_id].to_s
APIGeoService.country_name(external_id)
else
value.present? ? value.to_s : ''
end
end
def to_s
localized_value
end
def for_tag
localized_value
end
end

View file

@ -21,4 +21,29 @@
# type_de_champ_id :integer
#
class Champs::RegionChamp < Champs::TextChamp
def for_export
[name, code]
end
def selected
code
end
def name
value
end
def code
external_id || APIGeoService.region_code(value)
end
def value=(code)
if code&.size == 2
self.external_id = code
super(APIGeoService.region_name(code))
elsif code.blank?
self.external_id = nil
super(nil)
end
end
end

View file

@ -1,2 +1,5 @@
class TypesDeChamp::DepartementTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index)
[libelle, "#{libelle} (Code)"][index]
end
end

View file

@ -1,2 +1,5 @@
class TypesDeChamp::PaysTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index)
[libelle, "#{libelle} (Code)"][index]
end
end

View file

@ -1,2 +1,5 @@
class TypesDeChamp::RegionTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def libelle_for_export(index)
[libelle, "#{libelle} (Code)"][index]
end
end

View file

@ -0,0 +1,77 @@
class APIGeoService
class << self
def countries(locale: I18n.locale)
I18nData.countries(locale)
.merge(get_localized_additional_countries(locale))
.map { |(code, name)| { name:, code: } }
.sort_by { I18n.transliterate(_1[:name]) }
end
def country_name(code, locale: I18n.locale)
countries(locale:).find { _1[:code] == code }&.dig(:name)
end
def country_code(name)
return if name.nil?
code = I18nData.country_code(name) || I18nData.country_code(name.humanize) || I18nData.country_code(name.titleize)
if code.nil?
countries_index_fr[I18n.transliterate(name).upcase]&.dig(:code)
else
code
end
end
def regions
get_from_api_geo(:regions).sort_by { I18n.transliterate(_1[:name]) }
end
def region_name(code)
regions.find { _1[:code] == code }&.dig(:name)
end
def region_code(name)
return if name.nil?
regions.find { _1[:name] == name }&.dig(:code)
end
def departements
[{ code: '99', name: 'Etranger' }] + get_from_api_geo(:departements).sort_by { _1[:code] }
end
def departement_name(code)
departements.find { _1[:code] == code }&.dig(:name)
end
def departement_code(name)
return if name.nil?
departements.find { _1[:name] == name }&.dig(:code)
end
private
def get_from_api_geo(scope)
Rails.cache.fetch("api_geo_#{scope}", expires_in: 1.year) do
response = Typhoeus.get("#{API_GEO_URL}/#{scope}")
JSON.parse(response.body).map(&:symbolize_keys)
.map { { name: _1[:nom].tr("'", ''), code: _1[:code] } }
end
end
def countries_index_fr
Rails.cache.fetch('countries_index_fr', expires_in: 1.year) do
countries(locale: 'FR').index_by { I18n.transliterate(_1[:name]).upcase }
end
end
def get_localized_additional_countries(locale)
additional_countries[locale.to_s.upcase] || {}
end
def additional_countries
{
'FR' => { 'XK' => 'Kosovo' },
'EN' => { 'XK' => 'Kosovo' }
}
end
end
end

View file

@ -1,16 +0,0 @@
class CountriesService
def self.get(locale)
I18nData.countries(locale).merge(get_localized_additional_countries(locale))
end
def self.get_localized_additional_countries(locale)
additional_countries[locale.to_s.upcase] || {}
end
def self.additional_countries
{
'FR' => { 'XK' => 'Kosovo' },
'EN' => { 'XK' => 'Kosovo' }
}
end
end

View file

@ -191,6 +191,28 @@ class SerializerService
...AddressFragment
}
}
... on CommuneChamp {
commune {
name
code
}
departement {
name
code
}
}
... on DepartementChamp {
departement {
name
code
}
}
... on RegionChamp {
region {
name
code
}
}
}
fragment RepetitionChampFragment on RepetitionChamp {

View file

@ -1,4 +1,4 @@
- if champ.external_id.present?
= format_text_value("#{champ.external_id} - #{champ}")
= format_text_value("#{champ.external_id} #{champ}")
- else
= format_text_value(champ.to_s)

View file

@ -15,7 +15,7 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:zone_ids) { [zone.id] }
let(:tags) { "[\"planete\",\"environnement\"]" }
describe '#apercu' do
describe '#apercu', vcr: { cassette_name: 'api_geo_all' } do
render_views
let(:procedure) { create(:procedure, :with_all_champs) }

79
spec/fixtures/cassettes/api_geo_all.yml vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,41 @@
---
http_interactions:
- request:
method: get
uri: https://geo.api.gouv.fr/regions
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- nginx/1.10.3 (Ubuntu)
Date:
- Tue, 20 Dec 2022 11:55:45 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '653'
Vary:
- Accept-Encoding
- Origin
X-Powered-By:
- Express
Etag:
- W/"28d-NqjRJu+ph9X/ycpx3D2pjeoeVto"
Strict-Transport-Security:
- max-age=15552000
body:
encoding: ASCII-8BIT
string: !binary |-
W3sibm9tIjoiw45sZS1kZS1GcmFuY2UiLCJjb2RlIjoiMTEifSx7Im5vbSI6IkNlbnRyZS1WYWwgZGUgTG9pcmUiLCJjb2RlIjoiMjQifSx7Im5vbSI6IkJvdXJnb2duZS1GcmFuY2hlLUNvbXTDqSIsImNvZGUiOiIyNyJ9LHsibm9tIjoiTm9ybWFuZGllIiwiY29kZSI6IjI4In0seyJub20iOiJIYXV0cy1kZS1GcmFuY2UiLCJjb2RlIjoiMzIifSx7Im5vbSI6IkdyYW5kIEVzdCIsImNvZGUiOiI0NCJ9LHsibm9tIjoiUGF5cyBkZSBsYSBMb2lyZSIsImNvZGUiOiI1MiJ9LHsibm9tIjoiQnJldGFnbmUiLCJjb2RlIjoiNTMifSx7Im5vbSI6Ik5vdXZlbGxlLUFxdWl0YWluZSIsImNvZGUiOiI3NSJ9LHsibm9tIjoiT2NjaXRhbmllIiwiY29kZSI6Ijc2In0seyJub20iOiJBdXZlcmduZS1SaMO0bmUtQWxwZXMiLCJjb2RlIjoiODQifSx7Im5vbSI6IlByb3ZlbmNlLUFscGVzLUPDtHRlIGQnQXp1ciIsImNvZGUiOiI5MyJ9LHsibm9tIjoiQ29yc2UiLCJjb2RlIjoiOTQifSx7Im5vbSI6Ikd1YWRlbG91cGUiLCJjb2RlIjoiMDEifSx7Im5vbSI6Ik1hcnRpbmlxdWUiLCJjb2RlIjoiMDIifSx7Im5vbSI6Ikd1eWFuZSIsImNvZGUiOiIwMyJ9LHsibm9tIjoiTGEgUsOpdW5pb24iLCJjb2RlIjoiMDQifSx7Im5vbSI6Ik1heW90dGUiLCJjb2RlIjoiMDYifV0=
recorded_at: Tue, 20 Dec 2022 11:55:45 GMT
recorded_with: VCR 6.1.0

676
spec/fixtures/files/pays_dump.json vendored Normal file
View file

@ -0,0 +1,676 @@
[
"ACORES, MADERE",
"Afghanistan",
"AFGHANISTAN",
"Afrique du Sud",
"AFRIQUE DU SUD",
"Åland, Îles",
"ALASKA",
"Albania",
"Albanie",
"ALBANIE",
"Algeria",
"ALGERIE",
"Algérie",
"Allemagne",
"ALLEMAGNE",
"American Samoa",
"Andorra",
"Andorre",
"ANDORRE",
"Angola",
"ANGOLA",
"Anguilla",
"ANGUILLA",
"Antarctique",
"Antigua and Barbuda",
"Antigua-et-Barbuda",
"ANTIGUA-ET-BARBUDA",
"ANTILLES NEERLANDAISES",
"Arabie saoudite",
"ARABIE SAOUDITE",
"Argentina",
"Argentine",
"ARGENTINE",
"Armenia",
"ARMENIE",
"Arménie",
"Aruba",
"ARUBA",
"Australia",
"Australie",
"AUSTRALIE",
"Austria",
"Autriche",
"AUTRICHE",
"AZERBAIDJAN",
"Azerbaïdjan",
"Azerbaijan",
"Bahamas",
"BAHAMAS",
"Bahrain",
"BAHREIN",
"Bahreïn",
"Bangladesh",
"BANGLADESH",
"Barbade",
"BARBADE",
"Barbados",
"Belarus",
"Bélarus",
"Belgique",
"BELGIQUE",
"Belgium",
"Belize",
"BELIZE",
"Benin",
"BENIN",
"Bénin",
"Bermuda",
"Bermudes",
"BERMUDES",
"Bhoutan",
"BHOUTAN",
"Bhutan",
"BIELORUSSIE",
"Birmanie",
"BIRMANIE",
"Bolivia",
"Bolivie",
"BOLIVIE",
"BONAIRE, SAINT EUSTACHE ET SABA",
"Bonaire, Saint-Eustache et Saba",
"Bonaire, Sint Eustatius and Saba",
"Bosnia and Herzegovina",
"BOSNIE-HERZEGOVINE",
"Bosnie-Herzégovine",
"Botswana",
"BOTSWANA",
"Brazil",
"BRESIL",
"Brésil",
"British Indian Ocean Territory",
"Brunei Darussalam",
"Brunéi Darussalam",
"BRUNEI",
"Bulgaria",
"Bulgarie",
"BULGARIE",
"Burkina Faso",
"BURKINA",
"Burundi",
"BURUNDI",
"Cabo Verde",
"CAIMANES (ILES)",
"Cambodge",
"CAMBODGE",
"Cambodia",
"Cameroon",
"CAMEROUN ET TOGO",
"Cameroun",
"CAMEROUN",
"Canada",
"CANADA",
"CANARIES (ILES)",
"Cap-Vert",
"CAP-VERT",
"Cayman Islands",
"CENTRAFRICAINE (REPUBLIQUE)",
"Central African Republic",
"Chad",
"Chile",
"Chili",
"CHILI",
"China",
"Chine",
"CHINE",
"CHRISTMAS (ILE)",
"Christmas, Île",
"Chypre",
"CHYPRE",
"Cocos (Keeling) Islands",
"Cocos (Keeling), Îles",
"Colombia",
"Colombie",
"COLOMBIE",
"Comores",
"COMORES",
"Comoros",
"CONGO (REPUBLIQUE DEMOCRATIQUE)",
"Congo, The Democratic Republic of the",
"Congo",
"CONGO",
"COOK (ILES)",
"COREE (REPUBLIQUE DE)",
"COREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)",
"Corée, République de",
"Corée, République populaire démocratique de",
"COREE",
"Costa Rica",
"COSTA RICA",
"COTE D'IVOIRE",
"Côte d'Ivoire",
"Croatia",
"Croatie",
"CROATIE",
"Cuba",
"CUBA",
"Curaçao",
"CURAÇAO",
"Cyprus",
"Czechia",
"Danemark",
"DANEMARK",
"Denmark",
"Djibouti",
"DJIBOUTI",
"Dominica",
"DOMINICAINE (REPUBLIQUE)",
"Dominican Republic",
"Dominique",
"DOMINIQUE",
"Ecuador",
"Egypt",
"EGYPTE",
"Égypte",
"El Salvador",
"EL SALVADOR",
"EMIRATS ARABES UNIS",
"Émirats arabes unis",
"EQUATEUR",
"Équateur",
"Equatorial Guinea",
"Eritrea",
"ERYTHREE",
"Érythrée",
"Espagne",
"ESPAGNE",
"Estonia",
"Estonie",
"ESTONIE",
"Eswatini",
"ETATS MALAIS NON FEDERES",
"ETATS-UNIS",
"États-Unis",
"Ethiopia",
"ETHIOPIE",
"Éthiopie",
"Falkland Islands (Malvinas)",
"FEROE (ILES)",
"Fidji",
"FIDJI",
"Fiji",
"Finland",
"Finlande",
"FINLANDE",
"France",
"FRANCE",
"French Guiana",
"French Polynesia",
"French Southern Territories",
"Gabon",
"GABON",
"Gambia",
"Gambie",
"GAMBIE",
"Georgia",
"GEORGIE DU SUD ET LES ILES SANDWICH DU SUD",
"Géorgie du Sud et les îles Sandwich du Sud",
"GEORGIE",
"Géorgie",
"Germany",
"Ghana",
"GHANA",
"Gibraltar",
"GIBRALTAR",
"GRECE",
"Grèce",
"Greece",
"Grenada",
"Grenade",
"GRENADE",
"GROENLAND",
"Groënland",
"Guadeloupe",
"GUADELOUPE",
"Guam",
"GUAM",
"Guatemala",
"GUATEMALA",
"Guernesey",
"GUERNESEY",
"Guernsey",
"Guinea",
"GUINEE EQUATORIALE",
"Guinée Équatoriale",
"GUINEE-BISSAU",
"Guinée-Bissau",
"GUINEE",
"Guinée",
"Guyana",
"GUYANA",
"Guyane française",
"GUYANE",
"Haiti",
"HAITI",
"Haïti",
"HAWAII (ILES)",
"HEARD ET MACDONALD (ILES)",
"Holy See (Vatican City State)",
"Honduras",
"HONDURAS",
"Hong Kong",
"HONG-KONG",
"Hongrie",
"HONGRIE",
"Hungary",
"Iceland",
"île Bouvet",
"Île de Man",
"île Norfolk",
"îles Caïmans",
"îles Cook",
"îles Féroé",
"îles Heard-et-MacDonald",
"Îles Mariannes du Nord",
"Îles Marshall",
"Îles mineures éloignées des États-Unis",
"Îles Pitcairn",
"ILES PORTUGAISES DE L'OCEAN INDIEN",
"îles Turques-et-Caïques",
"Îles Vierges britanniques",
"Îles Vierges des États-Unis",
"Inde",
"INDE",
"India",
"Indonesia",
"INDONESIE",
"Indonésie",
"Irak",
"Iran, Islamic Republic of",
"Iran, République islamique d'",
"IRAN",
"Iraq",
"IRAQ",
"Ireland",
"IRLANDE, ou EIRE",
"Irlande",
"Islande",
"ISLANDE",
"Isle of Man",
"Israel",
"ISRAEL",
"Israël",
"Italie",
"ITALIE",
"Italy",
"Jamaica",
"JAMAIQUE",
"Jamaïque",
"Japan",
"Japon",
"JAPON",
"Jersey",
"JERSEY",
"Jordan",
"Jordanie",
"JORDANIE",
"KAMTCHATKA",
"Kazakhstan",
"KAZAKHSTAN",
"Kenya",
"KENYA",
"Kirghizistan",
"KIRGHIZISTAN",
"Korea, Democratic People's Republic of",
"Korea, Republic of",
"Kosovo",
"KOSOVO",
"KOWEIT",
"Koweït",
"Kuwait",
"Kyrgyzstan",
"LA REUNION",
"LABRADOR",
"Lao People's Democratic Republic",
"Lao, République démocratique populaire",
"LAOS",
"Latvia",
"Lebanon",
"Lesotho",
"LESOTHO",
"Lettonie",
"LETTONIE",
"Liban",
"LIBAN",
"Liberia",
"LIBERIA",
"Libéria",
"Libya",
"Libye",
"LIBYE",
"Liechtenstein",
"LIECHTENSTEIN",
"Lithuania",
"Lituanie",
"LITUANIE",
"Luxembourg",
"LUXEMBOURG",
"Macao",
"MACAO",
"Macau",
"MACEDOINE DU NORD (REPUBLIQUE DE)",
"Macédoine du Nord",
"Madagascar",
"MADAGASCAR",
"Malaisie",
"MALAISIE",
"Malawi",
"MALAWI",
"Malaysia",
"Maldives",
"MALDIVES",
"Mali",
"MALI",
"Malouines, Îles (Falkland)",
"MALOUINES, OU FALKLAND (ILES)",
"Malta",
"Malte",
"MALTE",
"MAN (ILE)",
"MARIANNES DU NORD (ILES)",
"Maroc",
"MAROC",
"MARSHALL (ILES)",
"Martinique",
"MARTINIQUE",
"Maurice",
"MAURICE",
"Mauritania",
"Mauritanie",
"MAURITANIE",
"Mauritius",
"Mayotte",
"MAYOTTE",
"Mexico",
"Mexique",
"MEXIQUE",
"Micronésie, États fédérés de",
"Moldavie",
"MOLDAVIE",
"Moldova",
"Monaco",
"MONACO",
"Mongolia",
"Mongolie",
"MONGOLIE",
"Montenegro",
"MONTENEGRO",
"Monténégro",
"MONTSERRAT",
"Morocco",
"Mozambique",
"MOZAMBIQUE",
"Myanmar",
"Namibia",
"Namibie",
"NAMIBIE",
"Nepal",
"NEPAL",
"Népal",
"Netherlands",
"New Caledonia",
"New Zealand",
"Nicaragua",
"NICARAGUA",
"Niger",
"NIGER",
"Nigeria",
"NIGERIA",
"North Macedonia",
"NORVEGE",
"Norvège",
"Norway",
"NOUVELLE-CALEDONIE",
"Nouvelle-Calédonie",
"NOUVELLE-ZELANDE",
"Nouvelle-Zélande",
"OCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')",
"Oman",
"OMAN",
"Ouganda",
"OUGANDA",
"OUZBEKISTAN",
"Ouzbékistan",
"Pakistan",
"PAKISTAN",
"Palaos",
"PALESTINE (Etat de)",
"Palestine, État de",
"Palestine, State of",
"Panama",
"PANAMA",
"PAPOUASIE-NOUVELLE-GUINEE",
"Papouasie-Nouvelle-Guinée",
"Papua New Guinea",
"Paraguay",
"PARAGUAY",
"Pays-Bas",
"PAYS-BAS",
"PEROU",
"Pérou",
"Peru",
"Philippines",
"PHILIPPINES",
"Poland",
"Pologne",
"POLOGNE",
"POLYNESIE FRANCAISE",
"Polynésie française",
"Porto Rico",
"PORTO RICO",
"Portugal",
"PORTUGAL",
"POSSESSIONS BRITANNIQUES AU PROCHE-ORIENT",
"PROVINCES ESPAGNOLES D'AFRIQUE",
"Puerto Rico",
"Qatar",
"QATAR",
"République centrafricaine",
"REPUBLIQUE DEMOCRATIQUE ALLEMANDE",
"République démocratique du Congo",
"République dominicaine",
"République du Congo",
"REPUBLIQUE FEDERALE D'ALLEMAGNE",
"Réunion, Île de la",
"Réunion",
"Romania",
"Roumanie",
"ROUMANIE",
"Royaume-Uni",
"ROYAUME-UNI",
"Russian Federation",
"Russie, Fédération de",
"RUSSIE",
"Rwanda",
"RWANDA",
"Sahara occidental",
"SAHARA OCCIDENTAL",
"Saint Barthélemy",
"Saint Kitts and Nevis",
"Saint Lucia",
"Saint Martin (French part)",
"Saint Pierre and Miquelon",
"Saint Vincent and the Grenadines",
"SAINT-BARTHELEMY",
"Saint-Barthélemy",
"SAINT-CHRISTOPHE-ET-NIEVES",
"Saint-Christophe-et-Niévès",
"Saint-Marin",
"SAINT-MARIN",
"Saint-Martin (partie française)",
"SAINT-MARTIN (PARTIE NEERLANDAISE)",
"Saint-Martin (partie néerlandaise)",
"SAINT-MARTIN",
"Saint-Pierre-et-Miquelon",
"SAINT-PIERRE-ET-MIQUELON",
"Saint-Siège (état de la cité du Vatican)",
"SAINT-VINCENT-ET-LES GRENADINES",
"Saint-Vincent-et-les-Grenadines",
"SAINTE HELENE, ASCENSION ET TRISTAN DA CUNHA",
"Sainte-Hélène, Ascension et Tristan da Cunha",
"Sainte-Lucie",
"SAINTE-LUCIE",
"SALOMON (ILES)",
"Salomon, Îles",
"Salvador",
"SAMOA AMERICAINES",
"Samoa américaines",
"SAMOA OCCIDENTALES",
"Samoa",
"Sao Tome and Principe",
"SAO TOME-ET-PRINCIPE",
"Sao Tomé-et-Principe",
"Saudi Arabia",
"Senegal",
"SENEGAL",
"Sénégal",
"Serbia",
"Serbie",
"SERBIE",
"Seychelles",
"SEYCHELLES",
"SIBERIE",
"Sierra Leone",
"SIERRA LEONE",
"Singapore",
"Singapour",
"SINGAPOUR",
"Sint Maarten (Dutch part)",
"Slovakia",
"Slovaquie",
"SLOVAQUIE",
"Slovenia",
"SLOVENIE",
"Slovénie",
"Somalia",
"Somalie",
"SOMALIE",
"SOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA",
"Soudan du Sud",
"SOUDAN DU SUD",
"Soudan",
"SOUDAN",
"South Africa",
"South Georgia and the South Sandwich Islands",
"South Sudan",
"Spain",
"Sri Lanka",
"SRI LANKA",
"Sudan",
"SUEDE",
"Suède",
"Suisse",
"SUISSE",
"Surinam",
"Suriname",
"SURINAME",
"Svalbard and Jan Mayen",
"Svalbard et île Jan Mayen",
"SWAZILAND",
"Sweden",
"Switzerland",
"Syrian Arab Republic",
"SYRIE",
"Syrienne, République arabe",
"Tadjikistan",
"TADJIKISTAN",
"Taiwan",
"TAIWAN",
"Taïwan",
"Tajikistan",
"TANGER",
"Tanzania",
"Tanzanie",
"TANZANIE",
"Tchad",
"TCHAD",
"TCHECOSLOVAQUIE",
"TCHEQUE (REPUBLIQUE)",
"Tchéquie",
"TERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE",
"TERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE",
"TERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD",
"TERRE-NEUVE",
"TERRES AUSTRALES FRANCAISES",
"Terres australes françaises",
"Territoire britannique de l'océan Indien",
"TERRITOIRES DU ROYAUME-UNI AUX ANTILLES",
"Thailand",
"THAILANDE",
"Thaïlande",
"Timor oriental",
"TIMOR ORIENTAL",
"Timor-Leste",
"Togo",
"TOGO",
"Tonga",
"TONGA",
"Trinidad and Tobago",
"TRINITE-ET-TOBAGO",
"Trinité-et-Tobago",
"Tunisia",
"Tunisie",
"TUNISIE",
"TURKESTAN RUSSE",
"Turkey",
"Turkmenistan",
"TURKMENISTAN",
"Turkménistan",
"Turks and Caicos Islands",
"TURKS ET CAIQUES (ILES)",
"TURQUIE D'EUROPE",
"Turquie",
"TURQUIE",
"Tuvalu",
"TUVALU",
"Uganda",
"Ukraine",
"UKRAINE",
"United Arab Emirates",
"United Kingdom",
"United States Minor Outlying Islands",
"United States",
"Uruguay",
"URUGUAY",
"Uzbekistan",
"Vanuatu",
"VANUATU",
"VATICAN, ou SAINT-SIEGE",
"Venezuela",
"VENEZUELA",
"Vénézuela",
"VIERGES BRITANNIQUES (ILES)",
"VIERGES DES ETATS-UNIS (ILES)",
"VIET NAM DU NORD",
"VIET NAM DU SUD",
"VIET NAM",
"Viêt Nam",
"Vietnam",
"Virgin Islands, British",
"Virgin Islands, U.S.",
"Wallis et Futuna",
"WALLIS-ET-FUTUNA",
"Western Sahara",
"YEMEN (REPUBLIQUE ARABE DU)",
"YEMEN DEMOCRATIQUE",
"Yemen",
"YEMEN",
"Yémen",
"Zambia",
"Zambie",
"ZAMBIE",
"ZANZIBAR",
"Zimbabwe",
"ZIMBABWE"
]

View file

@ -196,7 +196,7 @@ describe Champ do
end
end
describe '#search_terms' do
describe '#search_terms', vcr: { cassette_name: 'api_geo_all' } do
let(:champ) { type_de_champ.champ.build(value: value) }
subject { champ.search_terms }
@ -247,9 +247,9 @@ describe Champ do
context 'for département champ' do
let(:type_de_champ) { build(:type_de_champ_departements) }
let(:value) { "69 - Rhône" }
let(:value) { "69" }
it { is_expected.to eq([value]) }
it { is_expected.to eq(['69 Rhône']) }
end
context 'for dossier link champ' do
@ -319,9 +319,9 @@ describe Champ do
context 'for pays champ' do
let(:type_de_champ) { build(:type_de_champ_pays) }
let(:value) { "FRANCE" }
let(:value) { "FR" }
it { is_expected.to eq([value]) }
it { is_expected.to eq(['France']) }
end
context 'for phone champ' do
@ -340,9 +340,9 @@ describe Champ do
context 'for region champ' do
let(:type_de_champ) { build(:type_de_champ_regions) }
let(:value) { "Île-de-France" }
let(:value) { "11" }
it { is_expected.to eq([value]) }
it { is_expected.to eq(['Île-de-France']) }
end
context 'for siret champ' do

View file

@ -0,0 +1,64 @@
describe Champs::DepartementChamp, type: :model do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
let(:champ) { described_class.new }
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
it 'with code' do
champ.value = '01'
expect(champ.external_id).to eq('01')
expect(champ.code).to eq('01')
expect(champ.name).to eq('Ain')
expect(champ.value).to eq('Ain')
expect(champ.selected).to eq('01')
expect(champ.to_s).to eq('01 Ain')
end
it 'with nil' do
champ.write_attribute(:value, 'Ain')
champ.write_attribute(:external_id, '01')
champ.value = nil
expect(champ.external_id).to be_nil
expect(champ.code).to be_nil
expect(champ.name).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with blank' do
champ.write_attribute(:value, 'Ain')
champ.write_attribute(:external_id, '01')
champ.value = ''
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial nil' do
champ.write_attribute(:value, nil)
expect(champ.external_id).to be_nil
expect(champ.code).to be_nil
expect(champ.name).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial name' do
champ.write_attribute(:value, '01 - Ain')
expect(champ.external_id).to be_nil
expect(champ.code).to eq('01')
expect(champ.name).to eq('Ain')
expect(champ.value).to eq('01 - Ain')
expect(champ.selected).to eq('01')
expect(champ.to_s).to eq('01 Ain')
end
end
end

View file

@ -0,0 +1,71 @@
describe Champs::PaysChamp, type: :model do
let(:champ) { described_class.new }
describe 'value' do
it 'with code' do
champ.value = 'GB'
expect(champ.external_id).to eq('GB')
expect(champ.value).to eq('Royaume-Uni')
expect(champ.selected).to eq('GB')
expect(champ.to_s).to eq('Royaume-Uni')
I18n.with_locale(:en) do
expect(champ.to_s).to eq('United Kingdom')
end
I18n.with_locale(:fr) do
expect(champ.to_s).to eq('Royaume-Uni')
end
end
it 'with name' do
champ.value = 'Royaume-Uni'
expect(champ.external_id).to eq('GB')
expect(champ.value).to eq('Royaume-Uni')
expect(champ.selected).to eq('GB')
expect(champ.to_s).to eq('Royaume-Uni')
end
it 'with nil' do
champ.write_attribute(:value, 'Royaume-Uni')
champ.write_attribute(:external_id, 'GB')
champ.value = nil
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with blank' do
champ.write_attribute(:value, 'Royaume-Uni')
champ.write_attribute(:external_id, 'GB')
champ.value = ''
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial nil' do
champ.write_attribute(:value, nil)
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial name' do
champ.write_attribute(:value, 'Royaume-Uni')
expect(champ.external_id).to be_nil
expect(champ.value).to eq('Royaume-Uni')
expect(champ.selected).to eq('GB')
expect(champ.to_s).to eq('Royaume-Uni')
end
it 'with initial bad name' do
champ.write_attribute(:value, 'ROYAUME-UNIS')
expect(champ.external_id).to be_nil
expect(champ.value).to eq('ROYAUME-UNIS')
expect(champ.selected).to eq('ROYAUME-UNIS')
expect(champ.to_s).to eq('ROYAUME-UNIS')
end
end
end

View file

@ -0,0 +1,56 @@
describe Champs::RegionChamp, type: :model do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
let(:champ) { described_class.new }
describe 'value', vcr: { cassette_name: 'api_geo_regions' } do
it 'with code' do
champ.value = '01'
expect(champ.external_id).to eq('01')
expect(champ.value).to eq('Guadeloupe')
expect(champ.selected).to eq('01')
expect(champ.to_s).to eq('Guadeloupe')
end
it 'with nil' do
champ.write_attribute(:value, 'Guadeloupe')
champ.write_attribute(:external_id, '01')
champ.value = nil
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with blank' do
champ.write_attribute(:value, 'Guadeloupe')
champ.write_attribute(:external_id, '01')
champ.value = ''
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial nil' do
champ.write_attribute(:value, nil)
expect(champ.external_id).to be_nil
expect(champ.value).to be_nil
expect(champ.selected).to be_nil
expect(champ.to_s).to eq('')
end
it 'with initial name' do
champ.write_attribute(:value, 'Guadeloupe')
expect(champ.external_id).to be_nil
expect(champ.value).to eq('Guadeloupe')
expect(champ.selected).to eq('01')
expect(champ.to_s).to eq('Guadeloupe')
end
end
end

View file

@ -0,0 +1,45 @@
describe APIGeoService do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
describe 'pays' do
it 'countrie_code' do
countries = JSON.parse(Rails.root.join('spec/fixtures/files/pays_dump.json').read)
countries_without_code = countries.map { APIGeoService.country_code(_1) }.count(&:nil?)
expect(countries_without_code).to eq(67)
end
describe 'country_name' do
it 'Kosovo' do
expect(APIGeoService.country_code('Kosovo')).to eq('XK')
expect(APIGeoService.country_name('XK')).to eq('Kosovo')
end
it 'Thaïlande' do
expect(APIGeoService.country_code('Thaïlande')).to eq('TH')
expect(APIGeoService.country_name('TH')).to eq('Thaïlande')
end
end
end
describe 'regions', vcr: { cassette_name: 'api_geo_regions' } do
it 'return sorted results' do
expect(APIGeoService.regions.size).to eq(18)
expect(APIGeoService.regions.first).to eq(code: '84', name: 'Auvergne-Rhône-Alpes')
expect(APIGeoService.regions.last).to eq(code: '93', name: 'Provence-Alpes-Côte dAzur')
end
end
describe 'departements', vcr: { cassette_name: 'api_geo_departements' } do
it 'return sorted results' do
expect(APIGeoService.departements.size).to eq(102)
expect(APIGeoService.departements.first).to eq(code: '99', name: 'Etranger')
expect(APIGeoService.departements.second).to eq(code: '01', name: 'Ain')
expect(APIGeoService.departements.last).to eq(code: '976', name: 'Mayotte')
end
end
end

View file

@ -68,8 +68,11 @@ describe ProcedureExportService do
"communes (Code insee)",
"communes (Département)",
"departements",
"departements (Code)",
"regions",
"regions (Code)",
"pays",
"pays (Code)",
"dossier_link",
"piece_justificative",
"rna",
@ -172,8 +175,11 @@ describe ProcedureExportService do
"communes (Code insee)",
"communes (Département)",
"departements",
"departements (Code)",
"regions",
"regions (Code)",
"pays",
"pays (Code)",
"dossier_link",
"piece_justificative",
"rna",
@ -259,8 +265,11 @@ describe ProcedureExportService do
"communes (Code insee)",
"communes (Département)",
"departements",
"departements (Code)",
"regions",
"regions (Code)",
"pays",
"pays (Code)",
"dossier_link",
"piece_justificative",
"rna",

View file

@ -1,4 +1,4 @@
describe 'wcag rules for usager', js: true do
describe 'wcag rules for usager', js: true, vcr: { cassette_name: 'api_geo_all' } do
let(:procedure) { create(:procedure, :published, :with_all_champs, :with_service, :for_individual) }
let(:password) { 'a very complicated password' }
let(:litteraire_user) { create(:user, password: password) }

View file

@ -1,4 +1,4 @@
describe 'Accessing the /patron page:' do
describe 'Accessing the /patron page:', vcr: { cassette_name: 'api_geo_all' } do
scenario 'I can display a page with all form fields and UI elements' do
visit patron_path
expect(page).to have_text('Icônes')

View file

@ -6,7 +6,14 @@ describe 'The user' do
let(:user_dossier) { user.dossiers.first }
let!(:dossier_to_link) { create(:dossier) }
scenario 'fill a dossier', js: true do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
scenario 'fill a dossier', js: true, vcr: { cassette_name: 'api_geo_all' } do
log_in(user, procedure)
fill_individual
@ -33,9 +40,9 @@ describe 'The user' do
select_combobox('multiple_choice_drop_down_list_long', 'alp', 'alpha')
select_combobox('multiple_choice_drop_down_list_long', 'cha', 'charly')
select_combobox('pays', 'aust', 'Australie')
select_combobox('regions', 'Ma', 'Martinique')
select_combobox('departements', 'Ai', '02 - Aisne')
select('Australie', from: form_id_for('pays'))
select('Martinique', from: form_id_for('regions'))
select('02 Aisne', from: form_id_for('departements'))
select_combobox('communes', 'Ai', '02 - Aisne', check: false)
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
@ -65,7 +72,7 @@ describe 'The user' do
expect(JSON.parse(champ_value_for('multiple_drop_down_list'))).to match(['val1', 'val3'])
expect(champ_value_for('pays')).to eq('Australie')
expect(champ_value_for('regions')).to eq('Martinique')
expect(champ_value_for('departements')).to eq('02 - Aisne')
expect(champ_value_for('departements')).to eq('Aisne')
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
expect(champ_value_for('dossier_link')).to eq('123')
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
@ -86,10 +93,10 @@ describe 'The user' do
expect(page).to have_checked_field('val1')
expect(page).to have_checked_field('val3')
expect(page).to have_selected_value('simple_choice_drop_down_list_long', selected: 'bravo')
expect(page).to have_selected_value('pays', selected: 'Australie')
expect(page).to have_selected_value('regions', selected: 'Martinique')
expect(page).to have_selected_value('departements', selected: '02 Aisne')
check_selected_value('multiple_choice_drop_down_list_long', with: ['alpha', 'charly'])
check_selected_value('pays', with: 'Australie')
check_selected_value('regions', with: 'Martinique')
check_selected_value('departements', with: '02 - Aisne')
check_selected_value('communes', with: 'Ambléon (01300)')
expect(page).to have_field('dossier_link', with: '123')
expect(page).to have_text('file.pdf')