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
|
// -*- mode: js; indent-tabs-mode: nil -*-
/* eslint-disable no-restricted-properties */
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2013 Giovanni Campagna <gcampagna@src.gnome.org>
imports.gi.versions.Gtk = '3.0';
const ByteArray = imports.byteArray;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const template = `
<interface>
<template class="Gjs_MyComplexGtkSubclass" parent="GtkGrid">
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="margin_start">10</property>
<property name="margin_end">10</property>
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="label-child">
<property name="label">Complex!</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label-child2">
<property name="label">Complex as well!</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkLabel" id="internal-label-child">
<property name="label">Complex and internal!</property>
<property name="visible">True</property>
</object>
</child>
</template>
</interface>`;
const MyComplexGtkSubclass = new Lang.Class({
Name: 'MyComplexGtkSubclass',
Extends: Gtk.Grid,
Template: ByteArray.fromString(template),
Children: ['label-child', 'label-child2'],
InternalChildren: ['internal-label-child'],
CssName: 'complex-subclass',
testChildrenExist() {
this._internalLabel = this.get_template_child(MyComplexGtkSubclass, 'label-child');
expect(this._internalLabel).toEqual(jasmine.anything());
expect(this.label_child2).toEqual(jasmine.anything());
expect(this._internal_label_child).toEqual(jasmine.anything());
},
});
const MyComplexGtkSubclassFromResource = new Lang.Class({
Name: 'MyComplexGtkSubclassFromResource',
Extends: Gtk.Grid,
Template: 'resource:///org/gjs/jsunit/complex3.ui',
Children: ['label-child', 'label-child2'],
InternalChildren: ['internal-label-child'],
testChildrenExist() {
expect(this.label_child).toEqual(jasmine.anything());
expect(this.label_child2).toEqual(jasmine.anything());
expect(this._internal_label_child).toEqual(jasmine.anything());
},
templateCallback() {},
boundCallback() {},
});
function validateTemplate(description, ClassName) {
describe(description, function () {
let win, content;
beforeEach(function () {
win = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
content = new ClassName();
win.add(content);
});
it('sets up internal and public template children', function () {
content.testChildrenExist();
});
it('sets up public template children with the correct widgets', function () {
expect(content.label_child.get_label()).toEqual('Complex!');
expect(content.label_child2.get_label()).toEqual('Complex as well!');
});
it('sets up internal template children with the correct widgets', function () {
expect(content._internal_label_child.get_label())
.toEqual('Complex and internal!');
});
afterEach(function () {
win.destroy();
});
});
}
describe('Legacy Gtk overrides', function () {
beforeAll(function () {
Gtk.init(null);
});
validateTemplate('UI template', MyComplexGtkSubclass);
validateTemplate('UI template from resource', MyComplexGtkSubclassFromResource);
it('sets CSS names on classes', function () {
expect(Gtk.Widget.get_css_name.call(MyComplexGtkSubclass)).toEqual('complex-subclass');
});
});
|