/Tests/AppKit/CPTabViewTest.j

http://github.com/cacaodev/cappuccino · Unknown · 96 lines · 74 code · 22 blank · 0 comment · 0 complexity · 79a8ac940bbd010bfb2e82cdb7d986d7 MD5 · raw file

  1. @import <Foundation/Foundation.j>
  2. @import <AppKit/AppKit.j>
  3. @implementation CPTabView (TEST)
  4. - (CPSegmentedControl)tabs
  5. {
  6. return _tabs;
  7. }
  8. - (CPBox)box
  9. {
  10. return _box;
  11. }
  12. @end
  13. @implementation CPTabViewTest : OJTestCase
  14. {
  15. CPTabView _tabView;
  16. CPTabViewItem _tabItem1;
  17. CPTabViewItem _tabItem2;
  18. }
  19. - (void)setUp
  20. {
  21. _tabView = [[CPTabView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)];
  22. _tabItem1 = [[CPTabViewItem alloc] initWithIdentifier:@"id1"];
  23. [_tabItem1 setLabel:@"Item A"];
  24. [_tabItem1 setView:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]]
  25. _tabItem2 = [[CPTabViewItem alloc] initWithIdentifier:@"id2"];
  26. [_tabItem2 setLabel:@"Item B"];
  27. [_tabItem2 setView:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]]
  28. [_tabView addTabViewItem:_tabItem1];
  29. [_tabView addTabViewItem:_tabItem2];
  30. }
  31. - (void)testCreate
  32. {
  33. [self assertNotNull:_tabView];
  34. }
  35. - (void)testMiddle
  36. {
  37. var tabs = [_tabView tabs];
  38. [self assert:([_tabView frameSize].width / 2) equals:CGRectGetMidX([tabs frame])];
  39. }
  40. - (void)testMiddleAfterMoveFrame
  41. {
  42. var tabs = [_tabView tabs];
  43. [_tabView setFrame:CGRectMake(10, 100, 1000, 200)];
  44. // Perform this manually for the sake of the unit test.
  45. [_tabView layoutIfNeeded];
  46. [self assert:([_tabView frameSize].width / 2) equals:CGRectGetMidX([tabs frame])];
  47. }
  48. - (void)testMiddleAfterMoveBound
  49. {
  50. var tabs = [_tabView tabs];
  51. [_tabView setBounds:CGRectMake(100, 100, 20, 300)];
  52. // Perform this manually for the sake of the unit test.
  53. [_tabView layoutIfNeeded];
  54. [self assert:([tabs boundsSize].width / 2) equals:CGRectGetMidX([tabs bounds])];
  55. }
  56. - (void)testBoxHeight
  57. {
  58. var box = [_tabView box],
  59. tabs = [_tabView tabs];
  60. [_tabView setFrame:CGRectMake(0, 0, 800, 800)];
  61. // Perform this manually for the sake of the unit test.
  62. [_tabView layoutIfNeeded];
  63. [self assert:[box frameSize].height equals:800 - [tabs frameSize].height / 2];
  64. }
  65. - (void)testTabViewGetsSetOnViewItem
  66. {
  67. [self assert:[_tabItem1 tabView] equals:_tabView];
  68. }
  69. - (void)testTabViewGetsRemoveOnViewItem
  70. {
  71. [_tabView removeTabViewItem:_tabItem1];
  72. [self assertNull:[_tabItem1 tabView]];
  73. }
  74. @end