aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/213-layout-restore-simple.t
blob: c2c533ff1e55ba7fe5b40ebd9eba326736bfdb60 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Restores a simple layout from a JSON file.
use i3test;
use File::Temp qw(tempfile);
use IO::Handle;

################################################################################
# empty layout file.
################################################################################

my ($fh, $filename) = tempfile(UNLINK => 1);
cmd "append_layout $filename";

does_i3_live;

close($fh);

################################################################################
# simple vsplit layout
################################################################################

my $ws = fresh_workspace;

my @content = @{get_ws_content($ws)};
is(@content, 0, 'no nodes on the new workspace yet');

($fh, $filename) = tempfile(UNLINK => 1);
print $fh <<EOT;
{
    "layout": "splitv",
    "nodes": [
        {
        },
        {
        }
    ]
}
EOT
$fh->flush;
cmd "append_layout $filename";

does_i3_live;

@content = @{get_ws_content($ws)};
is(@content, 1, 'one node on the workspace now');
is($content[0]->{layout}, 'splitv', 'node has splitv layout');
is(@{$content[0]->{nodes}}, 2, 'node has two children');

close($fh);

################################################################################
# two simple vsplit containers in the same file
################################################################################

$ws = fresh_workspace;

@content = @{get_ws_content($ws)};
is(@content, 0, 'no nodes on the new workspace yet');

($fh, $filename) = tempfile(UNLINK => 1);
print $fh <<EOT;
{
    "layout": "splitv",
    "nodes": [
        {
        },
        {
        }
    ]
}

{
    "layout": "splitv"
}
EOT
$fh->flush;
cmd "append_layout $filename";

does_i3_live;

@content = @{get_ws_content($ws)};
is(@content, 2, 'one node on the workspace now');
is($content[0]->{layout}, 'splitv', 'first node has splitv layout');
is(@{$content[0]->{nodes}}, 2, 'first node has two children');
is($content[1]->{layout}, 'splitv', 'second node has splitv layout');
is(@{$content[1]->{nodes}}, 0, 'first node has no children');

close($fh);

################################################################################
# simple vsplit layout with swallow specifications
################################################################################

$ws = fresh_workspace;

@content = @{get_ws_content($ws)};
is(@content, 0, 'no nodes on the new workspace yet');

($fh, $filename) = tempfile(UNLINK => 1);
print $fh <<EOT;
{
    "layout": "splitv",
    "nodes": [
        {
            "swallows": [
                {
                    "class": "top"
                }
            ]
        },
        {
            "swallows": [
                {
                    "class": "bottom"
                }
            ]
        }
    ]
}
EOT
$fh->flush;
cmd "append_layout $filename";

does_i3_live;

@content = @{get_ws_content($ws)};
is(@content, 1, 'one node on the workspace now');

my $top = open_window(
    name => 'top window',
    wm_class => 'top',
    instance => 'top',
);

my $bottom = open_window(
    name => 'bottom window',
    wm_class => 'bottom',
    instance => 'bottom',
);

@content = @{get_ws_content($ws)};
is(@content, 1, 'still one node on the workspace now');
my @nodes = @{$content[0]->{nodes}};
is($nodes[0]->{name}, 'top window', 'top window on top');

close($fh);

done_testing;