-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbasic-test.gts
134 lines (114 loc) · 3.91 KB
/
basic-test.gts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { find, visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import window from 'ember-window-mock';
import { setupWindowMock } from 'ember-window-mock/test-support';
import { module, test } from 'qunit';
import { baseRealm } from '@cardstack/runtime-common';
import type LoaderService from '@cardstack/host/services/loader-service';
import {
setupLocalIndexing,
setupServerSentEvents,
setupAcceptanceTestRealm,
} from '../helpers';
module('Acceptance | basic tests', function (hooks) {
setupApplicationTest(hooks);
setupLocalIndexing(hooks);
setupServerSentEvents(hooks);
setupWindowMock(hooks);
hooks.afterEach(async function () {
window.localStorage.removeItem('recent-files');
});
hooks.beforeEach(async function () {
window.localStorage.removeItem('recent-files');
let loaderService = this.owner.lookup(
'service:loader-service',
) as LoaderService;
let loader = loaderService.loader;
let { field, contains, CardDef, Component } = await loader.import<
typeof import('https://cardstack.com/base/card-api')
>(`${baseRealm.url}card-api`);
let { default: StringField } = await loader.import<
typeof import('https://cardstack.com/base/string')
>(`${baseRealm.url}string`);
let { CatalogEntry } = await loader.import<
typeof import('https://cardstack.com/base/catalog-entry')
>(`${baseRealm.url}catalog-entry`);
class Index extends CardDef {
static isolated = class Isolated extends Component<typeof this> {
<template>
<div data-test-index-card>
Hello, world!
</div>
</template>
};
}
class Person extends CardDef {
@field firstName = contains(StringField);
@field lastName = contains(StringField);
@field title = contains(StringField, {
computeVia: function (this: Person) {
return [this.firstName, this.lastName].filter(Boolean).join(' ');
},
});
static isolated = class Isolated extends Component<typeof this> {
<template>
<div data-test-person>
<p>First name: <@fields.firstName /></p>
<p>Last name: <@fields.lastName /></p>
<p>Title: <@fields.title /></p>
</div>
<style>
div {
color: green;
content: '';
}
</style>
</template>
};
}
await setupAcceptanceTestRealm({
loader,
contents: {
'index.gts': { Index },
'person.gts': { Person },
'person-entry.json': new CatalogEntry({
title: 'Person',
description: 'Catalog entry',
ref: {
module: `./person`,
name: 'Person',
},
}),
'index.json': new Index(),
'Person/1.json': new Person({
firstName: 'Hassan',
lastName: 'Abdel-Rahman',
}),
},
});
});
test('visiting realm root', async function (assert) {
await visit('/test/');
assert.strictEqual(currentURL(), '/test/');
assert.dom('[data-test-index-card]').containsText('Hello, world');
});
test('glimmer-scoped-css smoke test', async function (assert) {
await visit('/');
const cardContainerElement = find('[data-test-boxel-card-container]');
assert.ok(cardContainerElement);
if (!cardContainerElement) {
throw new Error('[data-test-boxel-card-container] element not found');
}
const buttonElementScopedCssAttribute = Array.from(
cardContainerElement.attributes,
)
.map((attribute) => attribute.localName)
.find((attributeName) => attributeName.startsWith('data-scopedcss'));
if (!buttonElementScopedCssAttribute) {
throw new Error(
'Scoped CSS attribute not found on [data-test-boxel-card-container]',
);
}
assert.dom('[data-test-boxel-card-container] + style').doesNotExist();
});
});