implement ComboPaysSearch

This commit is contained in:
Christophe Robillard 2020-11-25 15:17:59 +01:00 committed by LeSim (Rebase PR Action)
parent 0012fd3aa5
commit 12d1a5bece
6 changed files with 884 additions and 7 deletions

View file

@ -0,0 +1,21 @@
import React from 'react';
import { ReactQueryCacheProvider } from 'react-query';
import ComboSearch from './ComboSearch';
import { queryCache } from './shared/queryCache';
function ComboPaysSearch(params) {
return (
<ReactQueryCacheProvider queryCache={queryCache}>
<ComboSearch
required={params.mandatory}
hiddenFieldId={params.hiddenFieldId}
scope="pays"
minimumInputLength={0}
transformResult={({ nom }) => [nom, nom]}
/>
</ReactQueryCacheProvider>
);
}
export default ComboPaysSearch;

View file

@ -1,5 +1,6 @@
import { QueryCache } from 'react-query'; import { QueryCache } from 'react-query';
import { isNumeric } from '@utils'; import { isNumeric } from '@utils';
import matchSorter from 'match-sorter';
const { api_geo_url, api_adresse_url } = gon.autocomplete || {}; const { api_geo_url, api_adresse_url } = gon.autocomplete || {};
@ -31,6 +32,11 @@ function buildOptions() {
} }
async function defaultQueryFn(scope, term) { async function defaultQueryFn(scope, term) {
if (scope == 'pays') {
const pays = await fetch('/pays.json').then((response) => response.json());
return matchSorter(pays, term, { keys: ['nom'] });
}
const url = buildURL(scope, term); const url = buildURL(scope, term);
const [options, controller] = buildOptions(); const [options, controller] = buildOptions();
const promise = fetch(url, options).then((response) => response.json()); const promise = fetch(url, options).then((response) => response.json());

View file

@ -0,0 +1,3 @@
import Loadable from '../components/Loadable';
export default Loadable(() => import('../components/ComboPaysSearch'));

View file

@ -1,5 +1,3 @@
= form.select :value, - hidden_field_id = SecureRandom.uuid
Champs::PaysChamp.pays, = form.hidden_field :value, { data: { uuid: hidden_field_id } }
{ disabled: Champs::PaysChamp.disabled_options, include_blank: true }, = react_component("ComboPaysSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id)
required: champ.mandatory?,
class: 'select2 pays'

848
public/pays.json Normal file
View file

@ -0,0 +1,848 @@
[
{
"nom": "FRANCE"
},
{
"nom": "ACORES, MADERE"
},
{
"nom": "AFGHANISTAN"
},
{
"nom": "AFRIQUE DU SUD"
},
{
"nom": "ALASKA"
},
{
"nom": "ALBANIE"
},
{
"nom": "ALGERIE"
},
{
"nom": "ALLEMAGNE"
},
{
"nom": "ANDORRE"
},
{
"nom": "ANGOLA"
},
{
"nom": "ANGUILLA"
},
{
"nom": "ANTIGUA-ET-BARBUDA"
},
{
"nom": "ANTILLES NEERLANDAISES"
},
{
"nom": "ARABIE SAOUDITE"
},
{
"nom": "ARGENTINE"
},
{
"nom": "ARMENIE"
},
{
"nom": "ARUBA"
},
{
"nom": "AUSTRALIE"
},
{
"nom": "AUTRICHE"
},
{
"nom": "AZERBAIDJAN"
},
{
"nom": "BAHAMAS"
},
{
"nom": "BAHREIN"
},
{
"nom": "BANGLADESH"
},
{
"nom": "BARBADE"
},
{
"nom": "BELGIQUE"
},
{
"nom": "BELIZE"
},
{
"nom": "BENIN"
},
{
"nom": "BERMUDES"
},
{
"nom": "BHOUTAN"
},
{
"nom": "BIELORUSSIE"
},
{
"nom": "BIRMANIE"
},
{
"nom": "BOLIVIE"
},
{
"nom": "BONAIRE, SAINT EUSTACHE ET SABA"
},
{
"nom": "BOSNIE-HERZEGOVINE"
},
{
"nom": "BOTSWANA"
},
{
"nom": "BOUVET (ILE)"
},
{
"nom": "BRESIL"
},
{
"nom": "BRUNEI"
},
{
"nom": "BULGARIE"
},
{
"nom": "BURKINA"
},
{
"nom": "BURUNDI"
},
{
"nom": "CAIMANES (ILES)"
},
{
"nom": "CAMBODGE"
},
{
"nom": "CAMEROUN"
},
{
"nom": "CAMEROUN ET TOGO"
},
{
"nom": "CANADA"
},
{
"nom": "CANARIES (ILES)"
},
{
"nom": "CAP-VERT"
},
{
"nom": "CENTRAFRICAINE (REPUBLIQUE)"
},
{
"nom": "CHILI"
},
{
"nom": "CHINE"
},
{
"nom": "CHRISTMAS (ILE)"
},
{
"nom": "CHYPRE"
},
{
"nom": "CLIPPERTON (ILE)"
},
{
"nom": "COCOS ou KEELING (ILES)"
},
{
"nom": "COLOMBIE"
},
{
"nom": "COMORES"
},
{
"nom": "CONGO"
},
{
"nom": "CONGO (REPUBLIQUE DEMOCRATIQUE)"
},
{
"nom": "COOK (ILES)"
},
{
"nom": "COREE"
},
{
"nom": "COREE (REPUBLIQUE DE)"
},
{
"nom": "COREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)"
},
{
"nom": "COSTA RICA"
},
{
"nom": "COTE D'IVOIRE"
},
{
"nom": "CROATIE"
},
{
"nom": "CUBA"
},
{
"nom": "CURAÇAO"
},
{
"nom": "DANEMARK"
},
{
"nom": "DJIBOUTI"
},
{
"nom": "DOMINICAINE (REPUBLIQUE)"
},
{
"nom": "DOMINIQUE"
},
{
"nom": "EGYPTE"
},
{
"nom": "EL SALVADOR"
},
{
"nom": "EMIRATS ARABES UNIS"
},
{
"nom": "EQUATEUR"
},
{
"nom": "ERYTHREE"
},
{
"nom": "ESPAGNE"
},
{
"nom": "ESTONIE"
},
{
"nom": "ETATS MALAIS NON FEDERES"
},
{
"nom": "ETATS-UNIS"
},
{
"nom": "ETHIOPIE"
},
{
"nom": "FEROE (ILES)"
},
{
"nom": "FIDJI"
},
{
"nom": "FINLANDE"
},
{
"nom": "GABON"
},
{
"nom": "GAMBIE"
},
{
"nom": "GEORGIE"
},
{
"nom": "GEORGIE DU SUD ET LES ILES SANDWICH DU SUD"
},
{
"nom": "GHANA"
},
{
"nom": "GIBRALTAR"
},
{
"nom": "GOA"
},
{
"nom": "GRECE"
},
{
"nom": "GRENADE"
},
{
"nom": "GROENLAND"
},
{
"nom": "GUADELOUPE"
},
{
"nom": "GUAM"
},
{
"nom": "GUATEMALA"
},
{
"nom": "GUERNESEY"
},
{
"nom": "GUINEE"
},
{
"nom": "GUINEE EQUATORIALE"
},
{
"nom": "GUINEE-BISSAU"
},
{
"nom": "GUYANA"
},
{
"nom": "GUYANE"
},
{
"nom": "HAITI"
},
{
"nom": "HAWAII (ILES)"
},
{
"nom": "HEARD ET MACDONALD (ILES)"
},
{
"nom": "HONDURAS"
},
{
"nom": "HONG-KONG"
},
{
"nom": "HONGRIE"
},
{
"nom": "ILES PORTUGAISES DE L'OCEAN INDIEN"
},
{
"nom": "INDE"
},
{
"nom": "INDONESIE"
},
{
"nom": "IRAN"
},
{
"nom": "IRAQ"
},
{
"nom": "IRLANDE, ou EIRE"
},
{
"nom": "ISLANDE"
},
{
"nom": "ISRAEL"
},
{
"nom": "ITALIE"
},
{
"nom": "JAMAIQUE"
},
{
"nom": "JAPON"
},
{
"nom": "JERSEY"
},
{
"nom": "JORDANIE"
},
{
"nom": "KAMTCHATKA"
},
{
"nom": "KAZAKHSTAN"
},
{
"nom": "KENYA"
},
{
"nom": "KIRGHIZISTAN"
},
{
"nom": "KIRIBATI"
},
{
"nom": "KOSOVO"
},
{
"nom": "KOWEIT"
},
{
"nom": "LA REUNION"
},
{
"nom": "LABRADOR"
},
{
"nom": "LAOS"
},
{
"nom": "LESOTHO"
},
{
"nom": "LETTONIE"
},
{
"nom": "LIBAN"
},
{
"nom": "LIBERIA"
},
{
"nom": "LIBYE"
},
{
"nom": "LIECHTENSTEIN"
},
{
"nom": "LITUANIE"
},
{
"nom": "LUXEMBOURG"
},
{
"nom": "MACAO"
},
{
"nom": "MACEDOINE DU NORD (REPUBLIQUE DE)"
},
{
"nom": "MADAGASCAR"
},
{
"nom": "MALAISIE"
},
{
"nom": "MALAWI"
},
{
"nom": "MALDIVES"
},
{
"nom": "MALI"
},
{
"nom": "MALOUINES, OU FALKLAND (ILES)"
},
{
"nom": "MALTE"
},
{
"nom": "MAN (ILE)"
},
{
"nom": "MANDCHOURIE"
},
{
"nom": "MARIANNES DU NORD (ILES)"
},
{
"nom": "MAROC"
},
{
"nom": "MARSHALL (ILES)"
},
{
"nom": "MARTINIQUE"
},
{
"nom": "MAURICE"
},
{
"nom": "MAURITANIE"
},
{
"nom": "MAYOTTE"
},
{
"nom": "MEXIQUE"
},
{
"nom": "MICRONESIE (ETATS FEDERES DE)"
},
{
"nom": "MOLDAVIE"
},
{
"nom": "MONACO"
},
{
"nom": "MONGOLIE"
},
{
"nom": "MONTENEGRO"
},
{
"nom": "MONTSERRAT"
},
{
"nom": "MOZAMBIQUE"
},
{
"nom": "NAMIBIE"
},
{
"nom": "NAURU"
},
{
"nom": "NEPAL"
},
{
"nom": "NICARAGUA"
},
{
"nom": "NIGER"
},
{
"nom": "NIGERIA"
},
{
"nom": "NIUE"
},
{
"nom": "NORFOLK (ILE)"
},
{
"nom": "NORVEGE"
},
{
"nom": "NOUVELLE-CALEDONIE"
},
{
"nom": "NOUVELLE-ZELANDE"
},
{
"nom": "OCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')"
},
{
"nom": "OMAN"
},
{
"nom": "OUGANDA"
},
{
"nom": "OUZBEKISTAN"
},
{
"nom": "PAKISTAN"
},
{
"nom": "PALAOS (ILES)"
},
{
"nom": "PALESTINE (Etat de)"
},
{
"nom": "PANAMA"
},
{
"nom": "PAPOUASIE-NOUVELLE-GUINEE"
},
{
"nom": "PARAGUAY"
},
{
"nom": "PAYS-BAS"
},
{
"nom": "PEROU"
},
{
"nom": "PHILIPPINES"
},
{
"nom": "PITCAIRN (ILE)"
},
{
"nom": "POLOGNE"
},
{
"nom": "POLYNESIE FRANCAISE"
},
{
"nom": "PORTO RICO"
},
{
"nom": "PORTUGAL"
},
{
"nom": "POSSESSIONS BRITANNIQUES AU PROCHE-ORIENT"
},
{
"nom": "PRESIDES"
},
{
"nom": "PROVINCES ESPAGNOLES D'AFRIQUE"
},
{
"nom": "QATAR"
},
{
"nom": "REPUBLIQUE DEMOCRATIQUE ALLEMANDE"
},
{
"nom": "REPUBLIQUE FEDERALE D'ALLEMAGNE"
},
{
"nom": "ROUMANIE"
},
{
"nom": "ROYAUME-UNI"
},
{
"nom": "RUSSIE"
},
{
"nom": "RWANDA"
},
{
"nom": "SAHARA OCCIDENTAL"
},
{
"nom": "SAINT-BARTHELEMY"
},
{
"nom": "SAINT-CHRISTOPHE-ET-NIEVES"
},
{
"nom": "SAINT-MARIN"
},
{
"nom": "SAINT-MARTIN"
},
{
"nom": "SAINT-MARTIN (PARTIE NEERLANDAISE)"
},
{
"nom": "SAINT-PIERRE-ET-MIQUELON"
},
{
"nom": "SAINT-VINCENT-ET-LES GRENADINES"
},
{
"nom": "SAINTE HELENE, ASCENSION ET TRISTAN DA CUNHA"
},
{
"nom": "SAINTE-LUCIE"
},
{
"nom": "SALOMON (ILES)"
},
{
"nom": "SAMOA AMERICAINES"
},
{
"nom": "SAMOA OCCIDENTALES"
},
{
"nom": "SAO TOME-ET-PRINCIPE"
},
{
"nom": "SENEGAL"
},
{
"nom": "SERBIE"
},
{
"nom": "SEYCHELLES"
},
{
"nom": "SIBERIE"
},
{
"nom": "SIERRA LEONE"
},
{
"nom": "SINGAPOUR"
},
{
"nom": "SLOVAQUIE"
},
{
"nom": "SLOVENIE"
},
{
"nom": "SOMALIE"
},
{
"nom": "SOUDAN"
},
{
"nom": "SOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA"
},
{
"nom": "SOUDAN DU SUD"
},
{
"nom": "SRI LANKA"
},
{
"nom": "SUEDE"
},
{
"nom": "SUISSE"
},
{
"nom": "SURINAME"
},
{
"nom": "SVALBARD et ILE JAN MAYEN"
},
{
"nom": "SWAZILAND"
},
{
"nom": "SYRIE"
},
{
"nom": "TADJIKISTAN"
},
{
"nom": "TAIWAN"
},
{
"nom": "TANGER"
},
{
"nom": "TANZANIE"
},
{
"nom": "TCHAD"
},
{
"nom": "TCHECOSLOVAQUIE"
},
{
"nom": "TCHEQUE (REPUBLIQUE)"
},
{
"nom": "TERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE"
},
{
"nom": "TERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE"
},
{
"nom": "TERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD"
},
{
"nom": "TERRE-NEUVE"
},
{
"nom": "TERRES AUSTRALES FRANCAISES"
},
{
"nom": "TERRITOIRES DU ROYAUME-UNI AUX ANTILLES"
},
{
"nom": "THAILANDE"
},
{
"nom": "TIMOR ORIENTAL"
},
{
"nom": "TOGO"
},
{
"nom": "TOKELAU"
},
{
"nom": "TONGA"
},
{
"nom": "TRINITE-ET-TOBAGO"
},
{
"nom": "TUNISIE"
},
{
"nom": "TURKESTAN RUSSE"
},
{
"nom": "TURKMENISTAN"
},
{
"nom": "TURKS ET CAIQUES (ILES)"
},
{
"nom": "TURQUIE"
},
{
"nom": "TURQUIE D'EUROPE"
},
{
"nom": "TUVALU"
},
{
"nom": "UKRAINE"
},
{
"nom": "URUGUAY"
},
{
"nom": "VANUATU"
},
{
"nom": "VATICAN, ou SAINT-SIEGE"
},
{
"nom": "VENEZUELA"
},
{
"nom": "VIERGES BRITANNIQUES (ILES)"
},
{
"nom": "VIERGES DES ETATS-UNIS (ILES)"
},
{
"nom": "VIET NAM"
},
{
"nom": "VIET NAM DU NORD"
},
{
"nom": "VIET NAM DU SUD"
},
{
"nom": "WALLIS-ET-FUTUNA"
},
{
"nom": "YEMEN"
},
{
"nom": "YEMEN (REPUBLIQUE ARABE DU)"
},
{
"nom": "YEMEN DEMOCRATIQUE"
},
{
"nom": "ZAMBIE"
},
{
"nom": "ZANZIBAR"
},
{
"nom": "ZIMBABWE"
}
]

View file

@ -27,7 +27,7 @@ feature 'The user' do
select('bravo', from: form_id_for('simple_choice_drop_down_list_long')) select('bravo', from: form_id_for('simple_choice_drop_down_list_long'))
select('alpha', from: form_id_for('multiple_choice_drop_down_list_long')) select('alpha', from: form_id_for('multiple_choice_drop_down_list_long'))
select('charly', from: form_id_for('multiple_choice_drop_down_list_long')) select('charly', from: form_id_for('multiple_choice_drop_down_list_long'))
select('AUSTRALIE', from: 'pays') select_champ_geo('pays', 'aust', 'AUSTRALIE')
select_champ_geo('regions', 'Ma', 'Martinique') select_champ_geo('regions', 'Ma', 'Martinique')
@ -40,6 +40,7 @@ feature 'The user' do
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
blur blur
sleep(0.7)
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true) expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
# check data on the dossier # check data on the dossier
@ -83,7 +84,7 @@ feature 'The user' do
expect(page).to have_checked_field('val3') 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('simple_choice_drop_down_list_long', selected: 'bravo')
expect(page).to have_selected_value('multiple_choice_drop_down_list_long', selected: ['alpha', 'charly']) expect(page).to have_selected_value('multiple_choice_drop_down_list_long', selected: ['alpha', 'charly'])
expect(page).to have_selected_value('pays', selected: 'AUSTRALIE') expect(page).to have_hidden_field('pays', with: 'AUSTRALIE')
expect(page).to have_hidden_field('regions', with: 'Martinique') expect(page).to have_hidden_field('regions', with: 'Martinique')
expect(page).to have_hidden_field('departements', with: '02 - Aisne') expect(page).to have_hidden_field('departements', with: '02 - Aisne')
expect(page).to have_hidden_field('communes', with: 'Ambléon (01300)') expect(page).to have_hidden_field('communes', with: 'Ambléon (01300)')