Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Component] GPT component #26

Merged
merged 38 commits into from
Jul 10, 2017
Merged

[Component] GPT component #26

merged 38 commits into from
Jul 10, 2017

Conversation

JGAntunes
Copy link
Contributor

An ad component and its related parts, already supporting header biding also. It's still a work in progress, probably lacking further tests for the ad-manager.

@sericaia
Copy link
Contributor

@craigbilner can you please review and merge?

@foliveira foliveira requested a review from craigbilner June 27, 2017 11:18
Copy link
Contributor

@craigbilner craigbilner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think:

Testing needs to be a little clearer with a lot less theatre around setting everything up. It's very unit test heavy and would be nice to have integration tests to verify the whole piece

The components don't seem like they all belong under the one gpt package? There's clearly a separation between the managers and the react component. The story has a Wrapper component which seems to glue everything together, how does this work in the real world? Would you not import the components separately?

I appreciate working within the storybook with the iframe is a bit of a hassle but would be good to see multiple ads and making sure the managers are doing their jobs? Also do we need different types/sizes of ads?

import gptManager from "./gpt-manager";
import pbjsManager from "./pbjs-manager";

function AdManager(options = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ES2015 classes across the board for consistency/readability etc.?

import pbjsManager from "./pbjs-manager";

function AdManager(options = {}) {
if (!(this instanceof AdManager)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image

Should we use this anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're quite far from serving ES2015+ code to the browser? So there'll be a transpile step - https://www.npmjs.com/package/babel-plugin-transform-class

}

this.adQueue = [];
this.adUnit = options.adUnit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use Object.assign(this, {...props}) here

this.initialised = false;
}

AdManager.prototype.isReady = function isReady() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change to a get

gptManager.loadScript();
pbjsManager.loadScript();

series(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these libraries here? What's their value add?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. async helps to avoid callback hell and to better structure and organise your code and thinking. So, I would say yes, we need.

AdManager.prototype._pushAdToGPT = function pushAdToGPT(
adSlotId,
sizingMap,
options = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

let AdManager;

beforeEach(() => {
const window = new JSDOM().window;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we didn't do any integration testing like this at all. Everything ideally should be injectable and mockable through HOCs or other patterns. Also I'd probably make more use of jest/enzyme here to render into real DOMs and mock things in perhaps a more elegant way

it("constructor returns an AdManager instance with correct props", () => {
const adManager = AdManager(managerOptions);
expect(adManager).toBeInstanceOf(AdManager);
expect(adManager.adUnit).toBe(managerOptions.adUnit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we wouldn't have so many asserts for a single test and at the very least have descriptions so a failure can easily be identified

.create(<GPT adManager={adManager} code="ad-header" />)
.toJSON();

expect(tree).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we snapshot test?


render() {
const props = this.props;
return <div id={props.code} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.props.code?

@sericaia sericaia force-pushed the feature/gpt-component branch 4 times, most recently from 076bafc to d8a014f Compare June 30, 2017 14:31
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling da81ecc on feature/gpt-component into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 71af2ae on feature/gpt-component into ** on master**.

@JGAntunes
Copy link
Contributor Author

I think all the needed changes have been addressed, can you confirm @craigbilner?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 431d9a1 on feature/gpt-component into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 44118f3 on feature/gpt-component into ** on master**.

@JGAntunes JGAntunes changed the title [WIP][Component] GPT component [Component] GPT component Jul 4, 2017
super(props);

this.adManager = new AdManager({
networkId: "25436805",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a prop for different environments

}

display(callback) {
if (!this.initialised) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make an assumption that this won't happen? Can we remove the defensive code to keep things cleaner? Can add a README if devs need to understand how to use it better

slot.addService(this.gptManager.googletag.pubads());
slot.defineSizeMapping(this._generateSizings(sizingMap));

// const targeting = omit(options, 'iuPartsSuffix');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?


const googletag = this.googletag;

googletag.cmd.push(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this all seem quite mysterious, are there some docs we can point to with a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, all the config setup calls are commented (except probably for the first one, whose comment doesn't make much sense (fixing it now). I can also leave a comment with a link for https://developers.google.com/doubleclick-gpt/reference#googletagpubadsservice

const pbs = d.createElement("script");
pbs.async = true;
pbs.type = "text/javascript";
pbs.src = "https://www.thetimes.co.uk/d/js/vendor/prebid.min-4812861170.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we raise an issue to revisit this, as it's open source shouldn't we just bundle the code as a normal vendor dependency?

@JGAntunes JGAntunes force-pushed the feature/gpt-component branch from 44118f3 to eb06190 Compare July 5, 2017 17:41
@coveralls
Copy link

Coverage Status

Coverage decreased (-23.1%) to 76.866% when pulling eb06190 on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-15.8%) to 84.211% when pulling 78b87a7 on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-15.7%) to 84.286% when pulling febfa33 on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-13.6%) to 86.364% when pulling 937e4f3 on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.09%) to 90.909% when pulling 1e92982 on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.09%) to 90.909% when pulling 1e1211a on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.09%) to 90.909% when pulling 5a4e3af on feature/gpt-component into 3d5f45b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 97.129% when pulling c6edee6 on feature/gpt-component into 3d5f45b on master.

@sericaia sericaia force-pushed the feature/gpt-component branch from c6edee6 to c1b1f82 Compare July 7, 2017 14:45
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 98.182% when pulling c1b1f82 on feature/gpt-component into 966d43d on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 98.182% when pulling 2a3c4e1 on feature/gpt-component into 966d43d on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 98.182% when pulling bf64aa5 on feature/gpt-component into 966d43d on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 97.605% when pulling fe0dfb8 on feature/gpt-component into 966d43d on master.

@sericaia sericaia force-pushed the feature/gpt-component branch from fe0dfb8 to acb59a9 Compare July 7, 2017 16:49
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 98.204% when pulling acb59a9 on feature/gpt-component into 7852705 on master.

@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage decreased (-2.4%) to 97.605% when pulling fe0dfb8 on feature/gpt-component into 966d43d on master.

@craigbilner craigbilner merged commit 59b6201 into master Jul 10, 2017
@craigbilner craigbilner deleted the feature/gpt-component branch July 10, 2017 09:50
rjanjua pushed a commit that referenced this pull request Jul 10, 2017
* feature: add gpt component with support for header biding

* fix: deal with some issues in the gpt story

* fix: render ad inside storybook

Storybook relies on iframes to render stories, gpt map sizes, used to
build responsive ads don't seem to work with it. This hack solves it for
now until further developments on storybookjs/storybook#862

* chore: document gpt story hack

* chore: add tests for gpt, pbjs and ad managers

* chore: add more tests for ad manager

* add more tests to ad-manager

* fixes here and there (console.log, typos, etc)

* classes instead of functions

* corrected most comments [WIP]

* snapshot test

* change story to render two ads in article page

* quick refactor on ad manager test

* alternative using react broadcast

* fix tests [WIP]

* snapshot tests; pbjs config; tests adapted

* fix: add missing react-broadcast dep

* chore: redo initialisation checks on ad, gpt and pbjs managers

* remove old test

* fix: jest config on gpt component

* chore: remove unneeded JSDOM dev dep

* fix: add section as a prop of ad composer

* fix: return on all callbacks

* chore: lint gpt component

* fix: network id should be a prop of AdManager

* chore: add comments on gpt config

* chore: use promises on the gpt, pbjs and ad managers

* chore: remove errors on improper class usage

* CC linting err fixed; adUnit as prop

* remove new.target as class constructors need to be called with new anyway

* chore: increase coverage

* one more test

* chore: update jest configuration

* prebid settings unit tests

* fix: change test assumption titles

* fix: test message to remember to turn ad blocker off

* fix: throw error if slot does not exist

* fix: use storybook url and remove transform
fampinheiro pushed a commit that referenced this pull request Jul 14, 2017
* feature: add gpt component with support for header biding

* fix: deal with some issues in the gpt story

* fix: render ad inside storybook

Storybook relies on iframes to render stories, gpt map sizes, used to
build responsive ads don't seem to work with it. This hack solves it for
now until further developments on storybookjs/storybook#862

* chore: document gpt story hack

* chore: add tests for gpt, pbjs and ad managers

* chore: add more tests for ad manager

* add more tests to ad-manager

* fixes here and there (console.log, typos, etc)

* classes instead of functions

* corrected most comments [WIP]

* snapshot test

* change story to render two ads in article page

* quick refactor on ad manager test

* alternative using react broadcast

* fix tests [WIP]

* snapshot tests; pbjs config; tests adapted

* fix: add missing react-broadcast dep

* chore: redo initialisation checks on ad, gpt and pbjs managers

* remove old test

* fix: jest config on gpt component

* chore: remove unneeded JSDOM dev dep

* fix: add section as a prop of ad composer

* fix: return on all callbacks

* chore: lint gpt component

* fix: network id should be a prop of AdManager

* chore: add comments on gpt config

* chore: use promises on the gpt, pbjs and ad managers

* chore: remove errors on improper class usage

* CC linting err fixed; adUnit as prop

* remove new.target as class constructors need to be called with new anyway

* chore: increase coverage

* one more test

* chore: update jest configuration

* prebid settings unit tests

* fix: change test assumption titles

* fix: test message to remember to turn ad blocker off

* fix: throw error if slot does not exist

* fix: use storybook url and remove transform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants