/* eslint-env jest */ import { CONTENT_SITE_QUICK_ACTIONS, DEFAULT_QUICK_ACTIONS, defaultQuickActions, savedQuickActionSlots, } from '../quickAction'; describe('defaultQuickActions', () => { it("starts a store from the shop's menu and a content site from a visitor's questions", () => { expect(defaultQuickActions(false)).toBe(DEFAULT_QUICK_ACTIONS); expect(defaultQuickActions(true)).toBe(CONTENT_SITE_QUICK_ACTIONS); const labels = CONTENT_SITE_QUICK_ACTIONS.map(chip => chip.label).join(' '); expect(labels).not.toMatch(/popular|arrivals|discounted|choose/i); }); }); describe('savedQuickActionSlots', () => { it('puts chips saved under the shipped keys back in their slots', () => { const slots = savedQuickActionSlots( [ { label: 'On sale', key: 'discounted_products', query: 'Sale', visible: true, }, ], DEFAULT_QUICK_ACTIONS ); expect(slots.map(slot => slot.label)).toEqual([ 'Help me choose', "What's popular?", 'Latest arrivals', 'On sale', ]); }); // A proposal from HQ slugs its keys from the labels: matched by key it // matched nothing, and the shop's chips were shown, then saved, instead. it('keeps a set saved under keys of its own, in the order it was saved', () => { const saved = [ { label: 'Open vs Enclosed', key: 'what_is_the_difference_between_open_and_enclosed_car_shipping?', query: 'What is the difference between open and enclosed car shipping?', visible: true, }, { label: 'Get a Quote', key: 'how_can_i_get_a_car_shipping_quote_for_my_vehicle?', query: 'How can I get a car shipping quote for my vehicle?', visible: true, }, ]; const slots = savedQuickActionSlots(saved, CONTENT_SITE_QUICK_ACTIONS); expect(slots.map(slot => slot.label)).toEqual([ 'Open vs Enclosed', 'Get a Quote', 'How does it work?', 'How can I contact you?', ]); expect(slots[0].key).toBe(saved[0].key); }); });