Skip to content

Commit

Permalink
banner tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriu Popa authored and vapopa committed Dec 27, 2023
1 parent 5dd7eb8 commit e3da567
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions CriteoPublisherSdk/Tests/UnitTests/Standalone/CRBannerViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ @interface CRBannerViewTests : XCTestCase <WKNavigationDelegate>
@property(strong, nonatomic) Criteo *criteo;
@property(strong, nonatomic) CR_IntegrationRegistry *integrationRegistry;
@property(nonatomic, strong) id loggingMock;
@property(strong, nonatomic) CRBannerView *bannerView;
@end

@implementation CRBannerViewTests
Expand Down Expand Up @@ -84,6 +85,7 @@ - (void)tearDown {
// Not sure why this is needed but without this testWithRendering is failing.
// Maybe this come from OCMock not handling properly partial mock ???
self.criteo = nil;
self.bannerView = nil;
[self.loggingMock stopMocking];
}

Expand All @@ -105,10 +107,10 @@ - (void)testBannerSuccess {
[webViewLoadedExpectation fulfill];
});

CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView];
_bannerView = [self bannerViewWithWebView:mockWebView];
OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Initializing"]]);

[bannerView loadAdWithContext:self.contextData];
[_bannerView loadAdWithContext:self.contextData];
OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Loading"]]);
OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Received"]]);

Expand All @@ -122,10 +124,9 @@ - (void)testBannerSuccess {

- (void)testWebViewAddedToViewHierarchy {
MockWKWebView *mockWebView = [MockWKWebView new];
_bannerView = [self bannerViewWithWebView:mockWebView addWebView:YES];

CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView addWebView:YES];

XCTAssertEqual(mockWebView, bannerView.subviews[0]);
XCTAssertEqual(mockWebView, _bannerView.subviews[0]);
}

- (void)testWithRendering {
Expand All @@ -134,9 +135,9 @@ - (void)testWithRendering {
CR_CdbBid *bid = [self cdbBidWithDisplayUrl:@"-"];
[self mockCriteoWithAdUnit:self.expectedCacheAdUnit respondBid:bid];

CRBannerView *bannerView = [self bannerViewWithWebView:realWebView];
_bannerView = [self bannerViewWithWebView:realWebView];
realWebView.navigationDelegate = self;
[bannerView loadAdWithContext:self.contextData];
[_bannerView loadAdWithContext:self.contextData];

XCTestExpectation __block *marginExpectation =
[self expectationWithDescription:@"WebView body has 0px margin"];
Expand Down Expand Up @@ -180,8 +181,8 @@ - (void)testBannerFail {
WKWebView *realWebView = [WKWebView new];
[self mockCriteoWithAdUnit:self.expectedCacheAdUnit respondBid:nil];

CRBannerView *bannerView = [self bannerViewWithWebView:realWebView];
[bannerView loadAdWithContext:self.contextData];
_bannerView = [self bannerViewWithWebView:realWebView];
[_bannerView loadAdWithContext:self.contextData];
OCMVerify([self.loggingMock logMessage:[OCMArg checkWithBlock:^BOOL(CR_LogMessage *logMessage) {
return [logMessage.tag isEqualToString:@"BannerView"] &&
[logMessage.message containsString:@"Failed"] &&
Expand All @@ -199,11 +200,11 @@ - (void)testAllowNavigationActionPolicyForWebView {
/* Allow navigation Types other than Links from Mainframes in WebView.
eg: Clicking images inside <a> tag generates WKNavigationTypeOther
*/
CRBannerView *bannerView = [self bannerViewWithWebView:nil];
_bannerView = [self bannerViewWithWebView:nil];

WKNavigationAction *mockNavigationAction = OCMStrictClassMock([WKNavigationAction class]);
OCMStub(mockNavigationAction.navigationType).andReturn(WKNavigationTypeOther);
[bannerView webView:nil
[_bannerView webView:nil
decidePolicyForNavigationAction:mockNavigationAction
decisionHandler:^(WKNavigationActionPolicy actionPolicy) {
XCTAssertEqual(actionPolicy, WKNavigationActionPolicyAllow);
Expand All @@ -216,7 +217,7 @@ - (void)testAllowNavigationActionPolicyForWebView {
OCMStub([mockFrame isMainFrame]).andReturn(YES);
NSURLRequest *request = [[NSURLRequest alloc] init];
OCMStub(mockNavigationAction.request).andReturn(request);
[bannerView webView:nil
[_bannerView webView:nil
decidePolicyForNavigationAction:mockNavigationAction
decisionHandler:^(WKNavigationActionPolicy actionPolicy) {
XCTAssertEqual(actionPolicy, WKNavigationActionPolicyAllow);
Expand All @@ -237,8 +238,8 @@ - (void)testCancelNavigationActionPolicyForWebView {
XCTestExpectation *openInBrowserExpectation =
[self expectationWithDescription:@"URL opened in browser expectation"];

CRBannerView *bannerView = [self bannerViewWithWebView:nil];
[bannerView webView:nil
_bannerView = [self bannerViewWithWebView:nil];
[_bannerView webView:nil
decidePolicyForNavigationAction:mockNavigationAction
decisionHandler:^(WKNavigationActionPolicy actionPolicy) {
XCTAssertEqual(actionPolicy, WKNavigationActionPolicyCancel);
Expand Down Expand Up @@ -270,8 +271,8 @@ - (void)testCreateWebViewWithConfiguration {
XCTestExpectation *openInBrowserExpectation =
[self expectationWithDescription:@"URL opened in browser expectation"];

CRBannerView *bannerView = [self bannerViewWithWebView:realWebView];
[bannerView webView:realWebView
_bannerView = [self bannerViewWithWebView:realWebView];
[_bannerView webView:realWebView
createWebViewWithConfiguration:nil
forNavigationAction:mockNavigationAction
windowFeatures:nil];
Expand All @@ -297,8 +298,8 @@ - (void)testDisplayAdWithDataSuccess {
[webViewLoadedExpectation fulfill];
});

CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView];
[bannerView loadAdWithDisplayData:TEST_DISPLAY_URL];
_bannerView = [self bannerViewWithWebView:mockWebView];
[_bannerView loadAdWithDisplayData:TEST_DISPLAY_URL];

[self cr_waitForExpectations:@[ webViewLoadedExpectation ]];
OCMVerifyAll(mockWebView);
Expand All @@ -322,14 +323,13 @@ - (void)testLoadingWithBidSuccess {
CR_CdbBid *cdbBid = [self cdbBidWithDisplayUrl:TEST_DISPLAY_URL];
CRBid *bid = [[CRBid alloc] initWithCdbBid:cdbBid adUnit:self.adUnit];

CRBannerView *bannerView =
[[CRBannerView alloc] initWithFrame:CGRectMake(13.0f, 17.0f, 47.0f, 57.0f)
criteo:self.criteo
webView:mockWebView
addWebView:NO
adUnit:nil
urlOpener:self.urlOpener];
[bannerView loadAdWithBid:bid];
_bannerView = [[CRBannerView alloc] initWithFrame:CGRectMake(13.0f, 17.0f, 47.0f, 57.0f)
criteo:self.criteo
webView:mockWebView
addWebView:NO
adUnit:nil
urlOpener:self.urlOpener];
[_bannerView loadAdWithBid:bid];

[self cr_waitForExpectations:@[ webViewLoadedExpectation ]];
OCMVerifyAll(mockWebView);
Expand All @@ -355,8 +355,8 @@ - (void)testTemplatingFromConfig {
CR_CdbBid *cdbBid = [self cdbBidWithDisplayUrl:displayURL];
CRBid *bid = [[CRBid alloc] initWithCdbBid:cdbBid adUnit:self.adUnit];

CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView];
[bannerView loadAdWithBid:bid];
_bannerView = [self bannerViewWithWebView:mockWebView];
[_bannerView loadAdWithBid:bid];

[self cr_waitForExpectations:@[ webViewLoadedExpectation ]];
OCMVerifyAll(mockWebView);
Expand All @@ -378,13 +378,13 @@ - (CRBannerView *)testbannerViewWithMRAID:(BOOL)mraidFlag {
}

- (void)testMRAIDOffOnConfig {
CRBannerView *bannerView = [self testbannerViewWithMRAID:NO];
XCTAssertNil(bannerView.mraidHandler);
_bannerView = [self testbannerViewWithMRAID:NO];
XCTAssertNil(_bannerView.mraidHandler);
}

- (void)testMRAIDActiveOnConfig {
CRBannerView *bannerView = [self testbannerViewWithMRAID:YES];
XCTAssertNotNil(bannerView.mraidHandler);
_bannerView = [self testbannerViewWithMRAID:YES];
XCTAssertNotNil(_bannerView.mraidHandler);
}

#pragma mark - Private
Expand Down

0 comments on commit e3da567

Please sign in to comment.