Commit 35d7d3fa authored by Dallas Reedy's avatar Dallas Reedy

Reduce code duplication in the Jest specs

parent 65adfc5b
......@@ -10,6 +10,8 @@ describe('PaidFeatureCalloutPopover', () => {
let trackingSpy;
let wrapper;
const trackingExperimentKey = 'experiment:highlight_paid_features_during_active_trial';
const findGlPopover = () => wrapper.findComponent(GlPopover);
const defaultProps = {
......@@ -22,50 +24,50 @@ describe('PaidFeatureCalloutPopover', () => {
targetId: 'some-feature-callout-target',
};
const createComponent = (props = defaultProps) => {
const createComponent = (extraProps = {}) => {
return extendedWrapper(
shallowMount(PaidFeatureCalloutPopover, {
propsData: props,
propsData: {
...defaultProps,
...extraProps,
},
}),
);
};
beforeEach(() => {
wrapper = createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('GlPopover attributes', () => {
describe('with some default props', () => {
beforeEach(() => {
wrapper = createComponent();
});
const sharedAttrs = {
boundary: 'viewport',
placement: 'top',
target: 'some-feature-callout-target',
};
describe('with some default props', () => {
it('sets attributes on the GlPopover component', () => {
const attributes = findGlPopover().attributes();
expect(attributes).toMatchObject({
boundary: 'viewport',
placement: 'top',
target: 'some-feature-callout-target',
});
expect(attributes).toMatchObject(sharedAttrs);
expect(attributes.containerId).toBeUndefined();
});
});
describe('with additional, optional props', () => {
beforeEach(() => {
wrapper = createComponent({
...defaultProps,
containerId: 'some-container-id',
});
wrapper = createComponent({ containerId: 'some-container-id' });
});
it('sets more attributes on the GlPopover component', () => {
expect(findGlPopover().attributes()).toMatchObject({
boundary: 'viewport',
...sharedAttrs,
container: 'some-container-id',
placement: 'top',
target: 'some-feature-callout-target',
});
});
});
......@@ -73,16 +75,12 @@ describe('PaidFeatureCalloutPopover', () => {
describe('popoverTitle', () => {
it('renders the title text', () => {
wrapper = createComponent();
expect(wrapper.vm.popoverTitle).toEqual('12 days remaining to enjoy some feature');
});
});
describe('popoverContent', () => {
it('renders the content text', () => {
wrapper = createComponent();
expect(wrapper.vm.popoverContent).toEqual(
'Enjoying your GitLab Awesomesauce trial? To continue using some feature after your trial ends, upgrade to ' +
'GitLab Amazing.',
......@@ -91,14 +89,13 @@ describe('PaidFeatureCalloutPopover', () => {
});
describe('promo image', () => {
const promoImagePathForTest = 'path/to/some/image.svg';
const findPromoImage = () => wrapper.findByTestId('promo-img');
describe('with the optional promoImagePath prop', () => {
beforeEach(() => {
wrapper = createComponent({
...defaultProps,
promoImagePath: 'path/to/some/image.svg',
});
wrapper = createComponent({ promoImagePath: promoImagePathForTest });
});
it('renders the promo image', () => {
......@@ -108,8 +105,7 @@ describe('PaidFeatureCalloutPopover', () => {
describe('with the optional promoImageAltText prop', () => {
beforeEach(() => {
wrapper = createComponent({
...defaultProps,
promoImagePath: 'path/to/some/image.svg',
promoImagePath: promoImagePathForTest,
promoImageAltText: 'My fancy alt text',
});
});
......@@ -120,13 +116,6 @@ describe('PaidFeatureCalloutPopover', () => {
});
describe('without the optional promoImageAltText prop', () => {
beforeEach(() => {
wrapper = createComponent({
...defaultProps,
promoImagePath: 'path/to/some/image.svg',
});
});
it('renders the promo image with default alt text', () => {
expect(findPromoImage().attributes('alt')).toBe('SVG illustration');
});
......@@ -134,10 +123,6 @@ describe('PaidFeatureCalloutPopover', () => {
});
describe('without the optional promoImagePath prop', () => {
beforeEach(() => {
wrapper = createComponent();
});
it('does not render a promo image', () => {
expect(findPromoImage().exists()).toBe(false);
});
......@@ -145,27 +130,27 @@ describe('PaidFeatureCalloutPopover', () => {
});
describe('call-to-action buttons', () => {
const sharedAttrs = {
target: '_blank',
variant: 'confirm',
size: 'small',
block: '',
'data-track-action': 'click_button',
'data-track-property': trackingExperimentKey,
};
const findUpgradeBtn = () => wrapper.findByTestId('upgradeBtn');
const findCompareBtn = () => wrapper.findByTestId('compareBtn');
beforeEach(() => {
wrapper = createComponent();
});
it('correctly renders an Upgrade button', () => {
const upgradeBtn = findUpgradeBtn();
expect(upgradeBtn.text()).toEqual('Upgrade to GitLab Amazing');
expect(upgradeBtn.attributes()).toMatchObject({
...sharedAttrs,
href: '/-/subscriptions/new?namespace_id=123&plan_id=abc456',
target: '_blank',
category: 'primary',
variant: 'confirm',
size: 'small',
block: '',
'data-track-action': 'click_button',
'data-track-label': 'upgrade_to_ultimate',
'data-track-property': 'experiment:highlight_paid_features_during_active_trial',
});
});
......@@ -174,15 +159,10 @@ describe('PaidFeatureCalloutPopover', () => {
expect(compareBtn.text()).toEqual('Compare all plans');
expect(compareBtn.attributes()).toMatchObject({
...sharedAttrs,
href: '/group/test-group/-/billings',
target: '_blank',
category: 'secondary',
variant: 'confirm',
size: 'small',
block: '',
'data-track-action': 'click_button',
'data-track-label': 'compare_all_plans',
'data-track-property': 'experiment:highlight_paid_features_during_active_trial',
});
});
});
......@@ -197,16 +177,12 @@ describe('PaidFeatureCalloutPopover', () => {
it('tracks that the popover has been shown', () => {
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'popover_shown', {
label: 'feature_highlight_popover:some feature',
property: 'experiment:highlight_paid_features_during_active_trial',
property: trackingExperimentKey,
});
});
});
describe('onResize', () => {
beforeEach(() => {
wrapper = createComponent();
});
it.each`
bp | disabled
${'xs'} | ${'true'}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment