|
1 |
| -import {masterSelection} from '#3p/ampcontext-integration'; |
| 1 | +import { |
| 2 | + IntegrationAmpContext, |
| 3 | + masterSelection, |
| 4 | +} from '#3p/ampcontext-integration'; |
2 | 5 |
|
3 | 6 | describes.fakeWin('#masterSelect', {}, (env) => {
|
4 | 7 | it('should allow sharing between configured networks', () =>
|
5 | 8 | expect(masterSelection(env.win, 'fake_network').name).to.equal(
|
6 | 9 | 'frame_fake_network_master'
|
7 | 10 | ));
|
8 | 11 | });
|
| 12 | + |
| 13 | +describes.sandboxed('IntegrationAmpContext aliases', {}, (env) => { |
| 14 | + let context; |
| 15 | + |
| 16 | + beforeEach(() => { |
| 17 | + // Create a minimal context object that implements the needed methods |
| 18 | + context = { |
| 19 | + master_: env.sandbox.stub().returns('master-window'), |
| 20 | + isMaster_: env.sandbox.stub().returns(true), |
| 21 | + computeInMasterFrame: env.sandbox.stub(), |
| 22 | + }; |
| 23 | + |
| 24 | + // Apply the getters from IntegrationAmpContext prototype |
| 25 | + Object.defineProperty(context, 'coordinator', { |
| 26 | + get() { return this.master_(); } |
| 27 | + }); |
| 28 | + Object.defineProperty(context, 'isCoordinator', { |
| 29 | + get() { return this.isMaster_(); } |
| 30 | + }); |
| 31 | + context.computeInCoordinatingFrame = function(global, taskId, work, cb) { |
| 32 | + return this.computeInMasterFrame(global, taskId, work, cb); |
| 33 | + }; |
| 34 | + }); |
| 35 | + |
| 36 | + it('should delegate coordinator to master', () => { |
| 37 | + const result = context.coordinator; |
| 38 | + expect(context.master_).to.have.been.calledOnce; |
| 39 | + expect(result).to.equal('master-window'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should delegate isCoordinator to isMaster', () => { |
| 43 | + const result = context.isCoordinator; |
| 44 | + expect(context.isMaster_).to.have.been.calledOnce; |
| 45 | + expect(result).to.equal(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should delegate computeInCoordinatingFrame to computeInMasterFrame', () => { |
| 49 | + const global = {test: 'global'}; |
| 50 | + const taskId = 'test-task'; |
| 51 | + const work = () => {}; |
| 52 | + const cb = () => {}; |
| 53 | + |
| 54 | + context.computeInCoordinatingFrame(global, taskId, work, cb); |
| 55 | + |
| 56 | + expect(context.computeInMasterFrame).to.have.been.calledOnceWith(global, taskId, work, cb); |
| 57 | + }); |
| 58 | +}); |
0 commit comments