@@ -2,7 +2,8 @@ import type { WalkerOS } from '@elbwalker/types';
22import type { DestinationGoogleGTM } from '.' ;
33import { mockDataLayer } from '@elbwalker/jest/web.setup' ;
44import { elb , Walkerjs } from '@elbwalker/walker.js' ;
5- import { createEvent } from '@elbwalker/utils' ;
5+ import { createEvent , getEvent } from '@elbwalker/utils' ;
6+ import { events , mapping } from '../examples' ;
67
78describe ( 'destination google-tag-manager' , ( ) => {
89 const w = window ;
@@ -81,23 +82,27 @@ describe('destination google-tag-manager', () => {
8182 expect ( mockDataLayer ) . toHaveBeenLastCalledWith ( event ) ;
8283 } ) ;
8384
84- test ( 'push mapping data' , ( ) => {
85- elb ( 'walker destination' , destination , {
86- mapping : {
87- entity : {
88- action : {
89- data : {
90- map : {
91- foo : { value : 'bar' } ,
92- } ,
93- } ,
94- } ,
95- } ,
96- } ,
97- } ) ;
85+ test ( 'event entity_action' , ( ) => {
86+ const event = getEvent ( ) ;
87+ elb ( 'walker destination' , destination , { mapping : mapping . config } ) ;
88+ elb ( event ) ;
89+
90+ expect ( mockDataLayer ) . toHaveBeenLastCalledWith ( events . entity_action ( ) ) ;
91+ } ) ;
92+
93+ test ( 'event add_to_cart' , ( ) => {
94+ const event = getEvent ( 'product add' ) ;
95+ elb ( 'walker destination' , destination , { mapping : mapping . config } ) ;
96+ elb ( event ) ;
97+
98+ expect ( mockDataLayer ) . toHaveBeenLastCalledWith ( events . add_to_cart ( ) ) ;
99+ } ) ;
100+
101+ test ( 'event purchase' , ( ) => {
102+ const event = getEvent ( 'order complete' ) ;
103+ elb ( 'walker destination' , destination , { mapping : mapping . config } ) ;
98104 elb ( event ) ;
99- expect ( w . dataLayer ) . toBeDefined ( ) ;
100105
101- expect ( mockDataLayer ) . toHaveBeenLastCalledWith ( { foo : 'bar' } ) ;
106+ expect ( mockDataLayer ) . toHaveBeenLastCalledWith ( events . purchase ( ) ) ;
102107 } ) ;
103108} ) ;
0 commit comments