# É possível sobrescrever o objeto Site com um fixture próprio durante testes Front End de um Plugin?

**URL:** <https://meta.discourse.org/t/is-it-possible-to-override-the-site-object-with-own-fixture-during-front-end-tests-of-a-plugin/249167>\
**Category:** Development\
**Created:** [Dezembro 16, 2022, 6:32pm UTC](https://meta.discourse.org/t/is-it-possible-to-override-the-site-object-with-own-fixture-during-front-end-tests-of-a-plugin/249167 "2022-12-16T18:32:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [Dezembro 16, 2022, 6:32pm UTC](https://meta.discourse.org/t/is-it-possible-to-override-the-site-object-with-own-fixture-during-front-end-tests-of-a-plugin/249167/1 "2022-12-16T18:32:29Z")

</div>

Estou trabalhando neste PR: [FIX: presenting formatted location on User Card by merefield · Pull Request #73 · merefield/discourse-locations · GitHub](https://github.com/paviliondev/discourse-locations/pull/73)

Estou tentando cobrir a alteração com um novo teste de Front End.

Mas o teste falha ao executar porque um atributo de dados necessário não está definido.

O problema que estou enfrentando é como substituir com sucesso os dados em Site por um fixture mantido aqui:

> <https://github.com/merefield/discourse-locations/pull/73/files#diff-2832ca21c6e61a472acdc999c8da22e843c1ebec1a0b8d7a7ef85e4a8d5b5065>
>
> \* 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)

que contém um atributo adicional que Site possui quando o Plugin Locations está presente.

… e fazê-lo persistir para o resto do teste!

O novo teste está aqui.

> <https://github.com/merefield/discourse-locations/pull/73/files#diff-4d360f60e91cae2f99c0368cf620bf82c41a22783b590c65b9899802a3ab0f44>
>
> \* 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)

Eu carrego Site com sucesso com o fixture, aparentemente.

Eu paro neste ponto de depuração durante a execução do qunit no navegador e posso dizer que ele está carregado corretamente:

```plaintext
  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")

```

![image](https://global.discourse-cdn.com/meta/original/4X/0/c/6/0c638c4df0964d966c3085424b85df32ba0c1b43.png)

mas quando o User Card é clicado, os dados não são o que você esperaria e, criticamente, o atributo `country_codes` está faltando, então o teste para aqui:

> <https://github.com/merefield/discourse-locations/blob/2a686be1babb684901b5debfd7759fecf65b8338/assets/javascripts/discourse/widgets/user-location.js.es6#L30>

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/7/3/1738c3bd79a375f94b898acd0c3e7520a0d7039a.png)

Por que meus dados de Site substituídos estão sendo perdidos?

---

_[View the full topic](https://meta.discourse.org/t/is-it-possible-to-override-the-site-object-with-own-fixture-during-front-end-tests-of-a-plugin/249167)._
