|
| 1 | +import { shallowMount } from '@vue/test-utils'; |
| 2 | +import { createPinia, setActivePinia } from 'pinia'; |
| 3 | +import Header from '~/components/Header.vue'; |
| 4 | + |
| 5 | +const mockEnsureLoaded = jest.fn().mockResolvedValue(undefined); |
| 6 | +const passthroughStub = { template: '<div><slot /></div>' }; |
| 7 | + |
| 8 | +jest.mock('~/stores/buckets', () => ({ |
| 9 | + useBucketsStore: () => ({ |
| 10 | + ensureLoaded: mockEnsureLoaded, |
| 11 | + buckets: [], |
| 12 | + }), |
| 13 | +})); |
| 14 | + |
| 15 | +describe('Header research edition badge', () => { |
| 16 | + afterEach(() => { |
| 17 | + delete global.AW_RESEARCH_EDITION; |
| 18 | + }); |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + setActivePinia(createPinia()); |
| 22 | + mockEnsureLoaded.mockClear(); |
| 23 | + }); |
| 24 | + |
| 25 | + function mountHeader(buildFlag) { |
| 26 | + if (buildFlag === undefined) { |
| 27 | + delete global.AW_RESEARCH_EDITION; |
| 28 | + } else { |
| 29 | + global.AW_RESEARCH_EDITION = buildFlag; |
| 30 | + } |
| 31 | + |
| 32 | + return shallowMount(Header, { |
| 33 | + mocks: { |
| 34 | + $isAndroid: false, |
| 35 | + $t: key => key, |
| 36 | + }, |
| 37 | + stubs: { |
| 38 | + 'b-navbar': passthroughStub, |
| 39 | + 'b-navbar-nav': passthroughStub, |
| 40 | + 'b-navbar-brand': passthroughStub, |
| 41 | + 'b-navbar-toggle': passthroughStub, |
| 42 | + 'b-collapse': passthroughStub, |
| 43 | + 'b-nav-item': passthroughStub, |
| 44 | + 'b-nav-item-dropdown': passthroughStub, |
| 45 | + 'b-dropdown-item': passthroughStub, |
| 46 | + 'b-badge': passthroughStub, |
| 47 | + icon: passthroughStub, |
| 48 | + }, |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + test('renders a badge in both brand sites for research builds', () => { |
| 53 | + const wrapper = mountHeader(true); |
| 54 | + |
| 55 | + expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(2); |
| 56 | + }); |
| 57 | + |
| 58 | + test('renders no badge for standard builds', () => { |
| 59 | + const wrapper = mountHeader(false); |
| 60 | + |
| 61 | + expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(0); |
| 62 | + }); |
| 63 | + |
| 64 | + test('renders no badge when the build flag is absent', () => { |
| 65 | + const wrapper = mountHeader(undefined); |
| 66 | + |
| 67 | + expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(0); |
| 68 | + }); |
| 69 | +}); |
0 commit comments