From 85545f6c2a0b02af3835aabd262632cc1e67172c Mon Sep 17 00:00:00 2001 From: Dylan Companjen Date: Tue, 27 Dec 2022 22:08:20 +0100 Subject: [PATCH] fix!: move GAM-exclusive FLUID type to new GAMBanner const --- __tests__/banner.test.tsx | 29 +++++++++++++++++++++++++++++ package.json | 2 ++ src/BannerAdSize.ts | 14 +++++++++----- src/ads/BaseAd.tsx | 8 +++++--- src/types/BannerAdProps.ts | 4 ++-- yarn.lock | 25 ++++++++++++++++++++++++- 6 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 __tests__/banner.test.tsx diff --git a/__tests__/banner.test.tsx b/__tests__/banner.test.tsx new file mode 100644 index 00000000..99be754c --- /dev/null +++ b/__tests__/banner.test.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { render } from '@testing-library/react-native'; +import { BannerAd, BannerAdSize } from '../src'; + +const MOCK_ID = 'MOCK_ID'; + +describe('Google Mobile Ads Banner', function () { + it('throws if no unit ID was provided.', function () { + let errorMsg; + try { + render(); + } catch (e) { + errorMsg = e.message; + } + expect(errorMsg).toEqual("BannerAd: 'unitId' expected a valid string unit ID."); + }); + + it('throws if size does not exist.', function () { + let errorMsg; + try { + render(); + } catch (e) { + errorMsg = e.message; + } + expect(errorMsg).toEqual( + "BannerAd: 'size(s)' expected a valid BannerAdSize or custom size string.", + ); + }); +}); diff --git a/package.json b/package.json index 66409a99..7d4be815 100644 --- a/package.json +++ b/package.json @@ -118,6 +118,7 @@ "@semantic-release/github": "^8.0.6", "@semantic-release/npm": "^9.0.1", "@semantic-release/release-notes-generator": "^10.0.3", + "@testing-library/react-native": "^11.5.0", "@types/jest": "^29.2.0", "@types/node": "^18.11.7", "@types/react": "^18.0.24", @@ -142,6 +143,7 @@ "react": "^18.2.0", "react-native": "0.70.4", "react-native-builder-bob": "^0.20.0", + "react-test-renderer": "^18.2.0", "rimraf": "^3.0.2", "semantic-release": "^19.0.5", "shelljs": "^0.8.5", diff --git a/src/BannerAdSize.ts b/src/BannerAdSize.ts index 9a584bd4..4f4d14f8 100644 --- a/src/BannerAdSize.ts +++ b/src/BannerAdSize.ts @@ -58,13 +58,17 @@ export enum BannerAdSize { */ INLINE_ADAPTIVE_BANNER = 'INLINE_ADAPTIVE_BANNER', - /** - * A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes. - */ - FLUID = 'FLUID', - /** * IAB wide skyscraper ad size (160x600 density-independent pixels). This size is currently not supported by the Google Mobile Ads network; this is intended for mediation ad networks only. */ WIDE_SKYSCRAPER = 'WIDE_SKYSCRAPER', } + +export const GAMBannerAdSize = { + ...BannerAdSize, + + /** + * A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes. + */ + FLUID: 'FLUID', +} as const; diff --git a/src/ads/BaseAd.tsx b/src/ads/BaseAd.tsx index c7a1ea14..20352548 100644 --- a/src/ads/BaseAd.tsx +++ b/src/ads/BaseAd.tsx @@ -20,7 +20,7 @@ import React, { useState, useEffect } from 'react'; import { NativeMethods, requireNativeComponent } from 'react-native'; import { isFunction } from '../common'; import { NativeError } from '../internal/NativeError'; -import { BannerAdSize } from '../BannerAdSize'; +import { BannerAdSize, GAMBannerAdSize } from '../BannerAdSize'; import { validateAdRequestOptions } from '../validateAdRequestOptions'; import { GAMBannerAdProps } from '../types/BannerAdProps'; import { RequestOptions } from '../types/RequestOptions'; @@ -58,7 +58,9 @@ export const BaseAd = React.forwardRef { if ( sizes.length === 0 || - !sizes.every(size => size in BannerAdSize || sizeRegex.test(size)) + !sizes.every( + size => size in BannerAdSize || size in GAMBannerAdSize || sizeRegex.test(size), + ) ) { throw new Error("BannerAd: 'size(s)' expected a valid BannerAdSize or custom size string."); } @@ -113,7 +115,7 @@ export const BaseAd = React.forwardRef { * * Inventory must be available for the banner sizes specified, otherwise a no-fill error will be sent to `onAdFailedToLoad`. */ - sizes: BannerAdSize[] | string[]; + sizes: typeof GAMBannerAdSize[keyof typeof GAMBannerAdSize][] | string[]; /** * Whether to enable the manual impression counting. diff --git a/yarn.lock b/yarn.lock index 9a3b4236..bde0a5f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2808,6 +2808,13 @@ dependencies: "@sinonjs/commons" "^1.7.0" +"@testing-library/react-native@^11.5.0": + version "11.5.0" + resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-11.5.0.tgz#b043c5db7b15eca42a65e95d3f3ae196fab9493b" + integrity sha512-seV+qebsbX4E5CWk/wizU1+2wVLsPyqEzG7sTgrhJ81cgAawg7ay06fIZR9IS75pDeWn2KZVd4mGk1pjJ3i3Zw== + dependencies: + pretty-format "^29.0.0" + "@tootallnate/once@2": version "2.0.0" resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" @@ -9335,7 +9342,7 @@ react-devtools-core@4.24.0: shell-quote "^1.6.1" ws "^7" -"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0: +"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== @@ -9443,6 +9450,15 @@ react-shallow-renderer@^16.15.0: object-assign "^4.1.1" react-is "^16.12.0 || ^17.0.0 || ^18.0.0" +react-test-renderer@^18.2.0: + version "18.2.0" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-18.2.0.tgz#1dd912bd908ff26da5b9fca4fd1c489b9523d37e" + integrity sha512-JWD+aQ0lh2gvh4NM3bBM42Kx+XybOxCpgYK7F8ugAlpaTSnWsX+39Z4XkOykGZAHrjwwTZT3x3KxswVWxHPUqA== + dependencies: + react-is "^18.2.0" + react-shallow-renderer "^16.15.0" + scheduler "^0.23.0" + react@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5" @@ -9858,6 +9874,13 @@ scheduler@^0.22.0: dependencies: loose-envify "^1.1.0" +scheduler@^0.23.0: + version "0.23.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe" + integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw== + dependencies: + loose-envify "^1.1.0" + semantic-release@^19.0.5: version "19.0.5" resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-19.0.5.tgz#d7fab4b33fc20f1288eafd6c441e5d0938e5e174"