DEV: Use ownership system in model tests

This commit is contained in:
Jarek Radosz 2023-02-13 22:45:12 +01:00
parent f48ed7371b
commit ee8d531ae3
2 changed files with 14 additions and 7 deletions

View File

@ -10,6 +10,10 @@ function concatVersions(repos) {
} }
export default class Repo { export default class Repo {
static create() {
return new Repo(...arguments);
}
static async findAll() { static async findAll() {
if (loaded.length) { if (loaded.length) {
return loaded; return loaded;

View File

@ -2,8 +2,8 @@ import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit"; import { setupRenderingTest } from "ember-qunit";
import { render, settled } from "@ember/test-helpers"; import { render, settled } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import Repo from "discourse/plugins/docker_manager/discourse/models/repo";
import { query } from "discourse/tests/helpers/qunit-helpers"; import { query } from "discourse/tests/helpers/qunit-helpers";
import { getOwner } from "discourse-common/lib/get-owner";
const repoProps = { const repoProps = {
unloaded: false, unloaded: false,
@ -47,8 +47,9 @@ module("Integration | Component | RepoStatus", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
test("it renders correctly", async function (assert) { test("it renders correctly", async function (assert) {
this.set("repo", new Repo(repoProps)); const store = getOwner(this).lookup("service:store");
this.set("managerRepo", new Repo(managerProps)); this.set("repo", store.createRecord("repo", repoProps));
this.set("managerRepo", store.createRecord("repo", managerProps));
await render( await render(
hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />` hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />`
@ -87,8 +88,9 @@ module("Integration | Component | RepoStatus", function (hooks) {
}); });
test("official check mark", async function (assert) { test("official check mark", async function (assert) {
this.set("repo", new Repo(repoProps)); const store = getOwner(this).lookup("service:store");
this.set("managerRepo", new Repo(managerProps)); this.set("repo", store.createRecord("repo", repoProps));
this.set("managerRepo", store.createRecord("repo", managerProps));
await render( await render(
hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />` hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />`
@ -107,8 +109,9 @@ module("Integration | Component | RepoStatus", function (hooks) {
}); });
test("upgrade button", async function (assert) { test("upgrade button", async function (assert) {
this.set("repo", new Repo(repoProps)); const store = getOwner(this).lookup("service:store");
this.set("managerRepo", new Repo(managerProps)); this.set("repo", store.createRecord("repo", repoProps));
this.set("managerRepo", store.createRecord("repo", managerProps));
await render( await render(
hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />` hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />`