merefield
(Robert)
16 Dicembre 2022, 6:32pm
1
Sto attualmente lavorando su questa PR: FIX: presenting formatted location on User Card by merefield · Pull Request #73 · merefield/discourse-locations · GitHub
Sto tentando di coprire la modifica con un nuovo test Front End.
Ma il test non viene eseguito perché manca un attributo di dati richiesto.
Il problema che sto affrontando è come sovrascrivere con successo i dati in Site con un fixture che si trova qui:
main ← production_fixes
opened 03:54PM - 14 Dec 22 UTC
* FIX: all places where geolocation is formatted (+ add covering & first FE test… )
* FIX: failure to build
* IMPROVE: add CI workflow
* FIX: specs (out of date with latest Rails)
che contiene un attributo aggiuntivo che Site detiene quando è presente il plugin Locations.
… e farlo persistere per il resto del test!
Il nuovo test è qui.
main ← production_fixes
opened 03:54PM - 14 Dec 22 UTC
* FIX: all places where geolocation is formatted (+ add covering & first FE test… )
* FIX: failure to build
* IMPROVE: add CI workflow
* FIX: specs (out of date with latest Rails)
Carico con successo Site con il fixture, apparentemente.
Mi fermo a questo punto di debug durante l’esecuzione di qunit nel browser e posso dire che è caricato correttamente:
test("user card location - shows correct format", async function (assert) {
const siteAttrs = {
...siteFixtures["site.json"].site,
};
PreloadStore.store("site", cloneJSON(siteAttrs));
Site.resetCurrent();
debugger;
PreloadStore.get("site")
ma quando si fa clic sulla User Card, i dati non sono quelli che ci si aspetta e, in modo critico, manca l’attributo country_codes, quindi il test si blocca qui:
if (user && user.geo_location) {
contents.push(iconNode('map-marker-alt'));
let format = this.siteSettings.location_user_profile_format.split('|');
let opts = {};
let userLocation;
if (format.length && format[0]) {
opts['geoAttrs'] = format;
userLocation = geoLocationFormat(user.geo_location, self.site.country_codes, opts);
} else {
userLocation = user.geo_location.address;
};
contents.push(h('div.location-label', userLocation));
if (this.siteSettings.location_user_profile_map) {
let mapContents = [];
let btnParams = {
Perché i miei dati Site sovrascritti vengono persi?
1 Mi Piace
merefield
(Robert)
20 Dicembre 2022, 9:49pm
2
OK, questo è frustrante.
Sembra che il valore dell’oggetto Site sia impostato qui:
const clock = fakeTime(timeString, timezone, false);
try {
callback();
} finally {
clock.restore();
}
}
let _pretenderCallbacks = {};
export function resetSite(extras = {}) {
const siteAttrs = {
...siteFixtures["site.json"].site,
...extras,
};
PreloadStore.store("site", cloneJSON(siteAttrs));
Site.resetCurrent();
}
export function applyPretender(name, server, helper) {
E non può essere sovrascritto?
Ho verificato questo modificando il fixture nel core (qui: discourse/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js at 93a4012ecb3af7306de0c51283d6dd2b2e90818c · discourse/discourse · GitHub ) e rileva la mia modifica.
Ma non voglio questo, voglio sovrascriverlo nel mio test del plugin con un fixture memorizzato nel mio plugin.
Per ribadire, sono in grado di farlo per l’ambito del codice di test, ma una volta che il codice del plugin è in esecuzione, l’ambito sembra rilevare l’oggetto site che si riferisce al fixture caricato dall’helper di test del core…
merefield
(Robert)
28 Dicembre 2022, 9:57pm
3
Ho finalmente risolto questo problema. Ho capito che puoi usare needs proprio come faresti per altri oggetti:
Indizio qui:
};
const needs = {
user(changes) {
loggedIn = true;
userChanges = changes;
},
pretender(fn) {
addPretenderCallback(name, fn);
},
site(changes) {
siteChanges = changes;
},
settings(changes) {
settingChanges = changes;
},
mobileView() {
mobileView = true;
},
};
Codice finale:
needs.site(cloneJSON(siteFixtures["country_codes.json"]));
3 Mi Piace
system
(system)
Chiuso
27 Gennaio 2023, 9:58pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.