Files
cappuccino/Tests/AppKit/CPBoxTest.j
T
David Richardson f468d483ff AppKit, Foundation: Fix view archiving and add regression tests
Keyed archiving preserves view hierarchies created in code. Decoded views
retain their content, subviews and state, and each view class is verified
against its own description before archiving.

* CPAccordionView: Add CPCoding to CPAccordionView and CPAccordionViewItem.

* CPBox:
  * Encode the content, title and box views unconditionally.
  * Clear the superviews of the box and title views during decoding.

* CPButton: Initialize the value to CPOffState.

* CPMapTable: Add CPCoding.

* CPPopUpButton: Clear the inherited button value.

* CPSearchField: Update the cancel button when the object value changes.

* CPSplitView: Return nil from dividerColor when the theme defines no divider
  image.

* CPStepper: Discard the decoded buttons before recreating them.

* CPTabView:
  * Encode the current tab view items.
  * Exclude the tabs from the encoded subviews.

* CPTokenField:
  * Discard the decoded scroll view before recreating it.
  * Add the decoded tokens to the new document view.

* CPVisualEffectView: Resolve the backdrop filter property only when a DOM is
  available.

* CPBoxTest: Verify preservation of the content view, hierarchy and title, and
  decoding of an untitled box without warnings.

* CPButtonTest: Verify the initial value of a button.

* CPMapTableTest: Verify preservation of entries through archiving.

* DropInArchiveFixtures: Add populated view fixtures, tree comparison, and
  round trip and saved archive helpers.

* DropInArchiveGenerator: Save cib descriptions and view archives, and write no
  archive data if any view fails its round trip.

* DropInArchiveTest: Verify new archives, saved archives and reference cibs, and
  treat decoding warnings as failures.

* DropInSnapshot:
  * Describe the view hierarchy through private views, with state and content.
  * Add DropInWithFixedScrollerStyle.

* DropInArchives, DropInCibs: Add saved view archives, cib descriptions and
  reference cibs.
2026-10-31 20:51:13 -06:00

115 lines
3.1 KiB
Plaintext

/*
* CPBoxTest.j
* AppKit
*
* Created by David Richardson on 31/10/2026.
* Copyright David Richardson 2026.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <AppKit/AppKit.j>
/*
A box that is archived and read back must keep its content view, its title and
its internal views, and the content view must remain inside the box.
*/
@implementation CPBoxTest : OJTestCase
{
CPBox box;
CPView contentView;
Function logWarning;
CPArray warnings;
}
- (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
warnings = [];
logWarning = CPLog.warn;
CPLog.warn = function(aMessage)
{
warnings.push(String(aMessage));
};
box = [[CPBox alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
contentView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 40.0)];
[contentView addSubview:[[CPView alloc] initWithFrame:CGRectMake(3.0, 5.0, 20.0, 10.0)]];
[box setContentView:contentView];
}
- (void)tearDown
{
CPLog.warn = logWarning;
}
- (CPBox)archivedBox
{
return [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:box]];
}
- (void)testArchivingKeepsTheContentView
{
var decodedContentView = [[self archivedBox] contentView];
[self assertNotNull:decodedContentView];
[self assert:1 equals:[[decodedContentView subviews] count]];
[self assertTrue:CGRectEqualToRect([contentView frame], [decodedContentView frame])];
}
- (void)testArchivingKeepsTheContentViewInsideTheBox
{
var decodedBox = [self archivedBox],
boxView = [[decodedBox contentView] superview];
[self assertNotNull:boxView];
[self assert:decodedBox equals:[boxView superview]];
[self assertTrue:[[decodedBox subviews] containsObject:boxView]];
}
- (void)testArchivingLeavesTheBoxUnchanged
{
var subviews = [box subviews];
[self archivedBox];
[self assert:subviews equals:[box subviews]];
[self assert:contentView equals:[box contentView]];
}
- (void)testArchivingKeepsTheTitle
{
[box setTitle:@"Title"];
[box setTitlePosition:CPAtTop];
var decodedBox = [self archivedBox];
[self assert:@"Title" equals:[decodedBox title]];
[self assert:CPAtTop equals:[decodedBox titlePosition]];
}
- (void)testUntitledBoxDecodesWithoutAWarning
{
[self archivedBox];
[self assert:[] equals:warnings];
}
@end