Skip to content

Commit

Permalink
Added unit test for CSS merging Cocoanetics#280
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik authored and jachenry committed Feb 20, 2013
1 parent 2c6ae28 commit 88065a9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Core/Test/Source/DTCSSStylesheetTest.m
Expand Up @@ -9,6 +9,9 @@
#import "DTCSSStyleSheetTest.h"

#import "DTCSSStylesheet.h"
#import "DTHTMLElement.h"
#import "DTCoreTextFontDescriptor.h"
#import "DTCoreTextParagraphStyle.h"

@implementation DTCSSStyleSheetTest

Expand Down Expand Up @@ -39,4 +42,22 @@ - (void)testAttributeWithWhitespace
STAssertEqualObjects(empty2, @"", @"empty2 should match");
}

- (void)testMerging
{
DTCSSStylesheet *stylesheet = [[DTCSSStylesheet defaultStyleSheet] copy];
DTCSSStylesheet *otherStyleSheet = [[DTCSSStylesheet alloc] initWithStyleBlock:@"p {margin-bottom:30px;font-size:40px;}"];
[stylesheet mergeStylesheet:otherStyleSheet];

DTHTMLElement *element = [DTHTMLElement elementWithName:@"p" attributes:nil options:nil];
element.fontDescriptor = [[DTCoreTextFontDescriptor alloc] init]; // need to have just any font descriptor
element.textScale = 1.0;

NSDictionary *styles = [stylesheet mergedStyleDictionaryForElement:element];
[element applyStyleDictionary:styles];

STAssertEquals(element.displayStyle, DTHTMLElementDisplayStyleBlock, @"Style merging lost block display style");

STAssertEquals((float)element.fontDescriptor.pointSize, (float)40.0f, @"font size should be 40px");
}

@end

0 comments on commit 88065a9

Please sign in to comment.