Skip to content

Commit 7607cbc

Browse files
committed
SpreadsheetMetadataPropertyNameViewportTest.testParseUrlFragmentSaveValue2
1 parent 0276956 commit 7607cbc

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

src/main/java/walkingkooka/spreadsheet/meta/SpreadsheetMetadataPropertyNameViewport.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
import walkingkooka.locale.LocaleContext;
22+
import walkingkooka.net.UrlFragment;
2223
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
2324
import walkingkooka.spreadsheet.viewport.SpreadsheetViewport;
2425

@@ -77,6 +78,8 @@ void accept(final SpreadsheetViewport value,
7778

7879
@Override
7980
SpreadsheetViewport parseUrlFragmentSaveValueNonNull(final String value) {
80-
return this.failParseUrlFragmentSaveValueUnsupported();
81+
return SpreadsheetViewport.fromUrlFragment(
82+
UrlFragment.parse(value)
83+
);
8184
}
8285
}

src/test/java/walkingkooka/spreadsheet/meta/SpreadsheetMetadataPropertyNameTestCase.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,32 +182,41 @@ final void extractLocaleValueAwareAndCheck(final LocaleContext context,
182182
public final void testParseUrlFragmentSaveValue() {
183183
final SpreadsheetMetadataPropertyName<V> propertyName = this.createName();
184184

185-
final String text;
186-
187-
final V value = this.propertyValue();
188-
if (value instanceof HasUrlFragment) {
189-
final HasUrlFragment has = (HasUrlFragment) value;
190-
text = has.urlFragment().value();
191-
} else {
192-
if (value instanceof HasText) {
193-
final HasText has = (HasText) value;
194-
text = has.text();
185+
if (false == propertyName instanceof SpreadsheetMetadataPropertyNameAuditInfo &&
186+
false == propertyName instanceof SpreadsheetMetadataPropertyNameSpreadsheetId &&
187+
false == propertyName instanceof SpreadsheetMetadataPropertyNameStyle) {
188+
final String text;
189+
190+
final V value = this.propertyValue();
191+
if (value instanceof HasUrlFragment) {
192+
final HasUrlFragment has = (HasUrlFragment) value;
193+
text = has.urlFragment().value();
195194
} else {
196-
text = String.valueOf(value);
195+
if (value instanceof HasText) {
196+
final HasText has = (HasText) value;
197+
text = has.text();
198+
} else {
199+
text = String.valueOf(value);
200+
}
197201
}
198-
}
199202

200-
try {
201-
this.checkEquals(
202-
value,
203-
propertyName.parseUrlFragmentSaveValue(text),
204-
() -> "parseUrlFragmentSaveValue " + CharSequences.quoteAndEscape(text)
203+
this.parseUrlFragmentSaveValueAndCheck(
204+
propertyName,
205+
text,
206+
value
205207
);
206-
} catch (final UnsupportedOperationException ignore) {
207-
208208
}
209209
}
210210

211+
final void parseUrlFragmentSaveValueAndCheck(final SpreadsheetMetadataPropertyName<V> propertyName,
212+
final String urlFragment,
213+
final V value) {
214+
this.checkEquals(
215+
value,
216+
propertyName.parseUrlFragmentSaveValue(urlFragment)
217+
);
218+
}
219+
211220
// isConverterSelector...................................................................................
212221

213222
@Test

src/test/java/walkingkooka/spreadsheet/meta/SpreadsheetMetadataPropertyNameViewportTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
2424
import walkingkooka.spreadsheet.viewport.SpreadsheetViewport;
2525
import walkingkooka.spreadsheet.viewport.SpreadsheetViewportAnchor;
26+
import walkingkooka.spreadsheet.viewport.SpreadsheetViewportNavigationList;
27+
import walkingkooka.spreadsheet.viewport.SpreadsheetViewportRectangle;
2628

2729
import java.util.Locale;
2830
import java.util.Optional;
@@ -104,6 +106,31 @@ public void testExtractLocaleAwareValue() {
104106
);
105107
}
106108

109+
@Test
110+
public void testParseUrlFragmentSaveValue2() {
111+
final SpreadsheetViewport viewport = SpreadsheetViewportRectangle.with(
112+
SpreadsheetSelection.A1,
113+
200,
114+
300
115+
).viewport()
116+
.setIncludeFrozenColumnsRows(true)
117+
.setAnchoredSelection(
118+
Optional.of(
119+
SpreadsheetSelection.parseCellRange("B2:C3")
120+
.setAnchor(SpreadsheetViewportAnchor.TOP_LEFT)
121+
)
122+
).setNavigations(
123+
SpreadsheetViewportNavigationList.parse("right 400px")
124+
);
125+
126+
this.parseUrlFragmentSaveValueAndCheck(
127+
SpreadsheetMetadataPropertyNameViewport.instance(),
128+
viewport.urlFragment()
129+
.value(),
130+
viewport
131+
);
132+
}
133+
107134
@Test
108135
public void testToString() {
109136
this.toStringAndCheck(

0 commit comments

Comments
 (0)