-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBusinessThemeTest.java
More file actions
235 lines (207 loc) · 10.4 KB
/
Copy pathBusinessThemeTest.java
File metadata and controls
235 lines (207 loc) · 10.4 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package com.demcha.compose.document.theme;
import com.demcha.compose.document.style.DocumentColor;
import com.demcha.compose.document.style.DocumentTextDecoration;
import org.junit.jupiter.api.Test;
import java.awt.Color;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.within;
class BusinessThemeTest {
private static final double EPS = 1e-6;
@Test
void spacingScaleDefaultIsMonotonicAndProducesSymmetricInsets() {
SpacingScale scale = SpacingScale.defaultScale();
assertThat(scale.xs()).isEqualTo(4.0, within(EPS));
assertThat(scale.sm()).isEqualTo(8.0, within(EPS));
assertThat(scale.md()).isEqualTo(12.0, within(EPS));
assertThat(scale.lg()).isEqualTo(20.0, within(EPS));
assertThat(scale.xl()).isEqualTo(32.0, within(EPS));
assertThat(scale.insetsMd().top()).isEqualTo(12.0, within(EPS));
assertThat(scale.insetsMd().left()).isEqualTo(12.0, within(EPS));
assertThat(scale.insetsMd().right()).isEqualTo(12.0, within(EPS));
assertThat(scale.insetsMd().bottom()).isEqualTo(12.0, within(EPS));
}
@Test
void spacingScaleRejectsNonMonotonicSteps() {
assertThatThrownBy(() -> new SpacingScale(8.0, 4.0, 12.0, 20.0, 32.0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("non-decreasing");
}
@Test
void spacingScaleRejectsNegativeOrInfiniteStep() {
assertThatThrownBy(() -> new SpacingScale(-1.0, 4.0, 8.0, 12.0, 16.0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("non-negative");
assertThatThrownBy(() -> new SpacingScale(4.0, 8.0, Double.NaN, 12.0, 16.0))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
void documentPaletteOfFactoryWrapsAwtColors() {
DocumentPalette palette = DocumentPalette.of(
Color.BLUE, Color.RED, Color.WHITE, Color.LIGHT_GRAY,
Color.BLACK, Color.GRAY, Color.DARK_GRAY);
assertThat(palette.primary().color()).isEqualTo(Color.BLUE);
assertThat(palette.accent().color()).isEqualTo(Color.RED);
assertThat(palette.surface().color()).isEqualTo(Color.WHITE);
}
@Test
void documentPaletteRejectsNullToken() {
assertThatThrownBy(() -> new DocumentPalette(
null, DocumentColor.BLACK, DocumentColor.WHITE, DocumentColor.WHITE,
DocumentColor.BLACK, DocumentColor.BLACK, DocumentColor.BLACK))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("primary");
}
@Test
void classicThemeHasAllTokensNonNull() {
BusinessTheme theme = BusinessTheme.classic();
assertThat(theme.name()).isEqualTo("classic");
assertThat(theme.palette()).isNotNull();
assertThat(theme.spacing()).isNotNull();
assertThat(theme.text()).isNotNull();
assertThat(theme.table()).isNotNull();
assertThat(theme.pageBackground()).isNull();
}
@Test
void modernThemeAppliesCreamPageBackground() {
BusinessTheme theme = BusinessTheme.modern();
assertThat(theme.name()).isEqualTo("modern");
assertThat(theme.pageBackground()).isNotNull();
assertThat(theme.pageBackground()).isEqualTo(theme.palette().surface());
}
@Test
void executiveThemeUsesTimesRomanForHeadings() {
BusinessTheme theme = BusinessTheme.executive();
assertThat(theme.name()).isEqualTo("executive");
assertThat(theme.text().h1().fontName().name()).isEqualTo("Times-Roman");
assertThat(theme.text().h1().decoration()).isEqualTo(DocumentTextDecoration.BOLD);
}
@Test
void textScaleResolvesAccentToBoldAccentColor() {
BusinessTheme theme = BusinessTheme.classic();
assertThat(theme.text().accent().color()).isEqualTo(theme.palette().accent());
assertThat(theme.text().accent().decoration()).isEqualTo(DocumentTextDecoration.BOLD);
}
@Test
void textScaleBodyAndCaptionShareTheBodyFont() {
BusinessTheme theme = BusinessTheme.classic();
assertThat(theme.text().body().fontName()).isEqualTo(theme.text().caption().fontName());
assertThat(theme.text().body().decoration()).isEqualTo(DocumentTextDecoration.DEFAULT);
assertThat(theme.text().caption().decoration()).isEqualTo(DocumentTextDecoration.DEFAULT);
assertThat(theme.text().body().size()).isGreaterThan(theme.text().caption().size());
}
@Test
void tablePresetCellsShareTheSpacingMdPaddingAndRuleStroke() {
BusinessTheme theme = BusinessTheme.classic();
assertThat(theme.table().defaultCellStyle().padding().top())
.isEqualTo(theme.spacing().sm(), within(EPS));
assertThat(theme.table().defaultCellStyle().stroke().color())
.isEqualTo(theme.palette().rule());
assertThat(theme.table().headerStyle().fillColor())
.isEqualTo(theme.palette().surfaceMuted());
}
@Test
void withPageBackgroundReturnsForkedThemeWithoutMutatingOriginal() {
BusinessTheme classic = BusinessTheme.classic();
DocumentColor cream = DocumentColor.of(new Color(252, 248, 240));
BusinessTheme withBg = classic.withPageBackground(cream);
assertThat(withBg.pageBackground()).isEqualTo(cream);
assertThat(classic.pageBackground()).isNull();
assertThat(withBg.palette()).isSameAs(classic.palette());
assertThat(withBg.name()).isEqualTo(classic.name());
}
@Test
void withNameReturnsForkedThemeWithoutMutatingOriginal() {
BusinessTheme classic = BusinessTheme.classic();
BusinessTheme renamed = classic.withName("acme-classic");
assertThat(renamed.name()).isEqualTo("acme-classic");
assertThat(classic.name()).isEqualTo("classic");
assertThat(renamed.palette()).isSameAs(classic.palette());
}
@Test
void allThreeBuiltInThemesAreDistinct() {
BusinessTheme classic = BusinessTheme.classic();
BusinessTheme modern = BusinessTheme.modern();
BusinessTheme executive = BusinessTheme.executive();
assertThat(classic.palette()).isNotEqualTo(modern.palette());
assertThat(modern.palette()).isNotEqualTo(executive.palette());
assertThat(classic.text().h1()).isNotEqualTo(modern.text().h1());
}
// --- Contemporary themes added in v1.6.8 -------------------------------
@Test
void nordicThemeHasAllTokensNonNullAndUsesGenerousSpacing() {
BusinessTheme theme = BusinessTheme.nordic();
assertThat(theme.name()).isEqualTo("nordic");
assertThat(theme.palette()).isNotNull();
assertThat(theme.spacing()).isNotNull();
assertThat(theme.text()).isNotNull();
assertThat(theme.table()).isNotNull();
assertThat(theme.pageBackground()).isNull();
// Nordic is tuned for whitespace — every step is at least as wide
// as the default scale, and md is strictly wider.
SpacingScale standard = SpacingScale.defaultScale();
assertThat(theme.spacing().md()).isGreaterThan(standard.md());
assertThat(theme.spacing().xl()).isGreaterThan(standard.xl());
}
@Test
void editorialThemeUsesTimesRomanBodyAndCreamPageBackground() {
BusinessTheme theme = BusinessTheme.editorial();
assertThat(theme.name()).isEqualTo("editorial");
assertThat(theme.text().body().fontName().name()).isEqualTo("Times-Roman");
assertThat(theme.text().h1().fontName().name()).isEqualTo("Times-Roman");
// Cream page background distinguishes editorial from the
// strictly-white classic theme.
assertThat(theme.pageBackground()).isNotNull();
assertThat(theme.pageBackground()).isEqualTo(theme.palette().surface());
}
@Test
void cinematicThemeInvertsPaletteToLightTextOnDarkSurface() {
BusinessTheme theme = BusinessTheme.cinematic();
assertThat(theme.name()).isEqualTo("cinematic");
// The defining trait: surface is dark, primary/text is light.
Color surface = theme.palette().surface().color();
Color textPrimary = theme.palette().textPrimary().color();
int surfaceLuminance = (surface.getRed() + surface.getGreen() + surface.getBlue()) / 3;
int textLuminance = (textPrimary.getRed() + textPrimary.getGreen() + textPrimary.getBlue()) / 3;
assertThat(surfaceLuminance).isLessThan(64); // genuinely dark surface
assertThat(textLuminance).isGreaterThan(192); // genuinely light text
// And the surface doubles as the page background so the moody
// look fills the page edges too.
assertThat(theme.pageBackground()).isEqualTo(theme.palette().surface());
}
@Test
void monochromeThemeIsPureBlackOnWhiteWithBoldYellowAccent() {
BusinessTheme theme = BusinessTheme.monochrome();
assertThat(theme.name()).isEqualTo("monochrome");
assertThat(theme.palette().primary().color()).isEqualTo(Color.BLACK);
assertThat(theme.palette().surface().color()).isEqualTo(Color.WHITE);
// The single accent is the entire identity of the theme — assert
// it leans yellow (R and G high, B low) rather than pinning the
// exact RGB, so a future shade tweak does not break the test.
Color accent = theme.palette().accent().color();
assertThat(accent.getRed()).isGreaterThan(200);
assertThat(accent.getGreen()).isGreaterThan(150);
assertThat(accent.getBlue()).isLessThan(80);
}
@Test
void allSevenBuiltInThemesArePairwiseDistinctByPalette() {
BusinessTheme[] all = {
BusinessTheme.classic(),
BusinessTheme.modern(),
BusinessTheme.executive(),
BusinessTheme.nordic(),
BusinessTheme.editorial(),
BusinessTheme.cinematic(),
BusinessTheme.monochrome()
};
for (int i = 0; i < all.length; i++) {
for (int j = i + 1; j < all.length; j++) {
assertThat(all[i].palette())
.as("Themes '%s' and '%s' must have distinct palettes",
all[i].name(), all[j].name())
.isNotEqualTo(all[j].palette());
assertThat(all[i].name()).isNotEqualTo(all[j].name());
}
}
}
}