diff options
Diffstat (limited to 'spec/frontend/ide/components/cannot_push_code_alert_spec.js')
-rw-r--r-- | spec/frontend/ide/components/cannot_push_code_alert_spec.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/frontend/ide/components/cannot_push_code_alert_spec.js b/spec/frontend/ide/components/cannot_push_code_alert_spec.js new file mode 100644 index 00000000000..ff659ecdf3f --- /dev/null +++ b/spec/frontend/ide/components/cannot_push_code_alert_spec.js @@ -0,0 +1,72 @@ +import { GlButton, GlAlert } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import { stubComponent } from 'helpers/stub_component'; +import CannotPushCodeAlert from '~/ide/components/cannot_push_code_alert.vue'; + +const TEST_MESSAGE = 'Hello test message!'; +const TEST_HREF = '/test/path/to/fork'; +const TEST_BUTTON_TEXT = 'Fork text'; + +describe('ide/components/cannot_push_code_alert', () => { + let wrapper; + + afterEach(() => { + wrapper.destroy(); + }); + + const createComponent = (props = {}) => { + wrapper = shallowMount(CannotPushCodeAlert, { + propsData: { + message: TEST_MESSAGE, + ...props, + }, + stubs: { + GlAlert: { + ...stubComponent(GlAlert), + template: `<div><slot></slot><slot name="actions"></slot></div>`, + }, + }, + }); + }; + + const findAlert = () => wrapper.findComponent(GlAlert); + const findButtonData = () => { + const button = findAlert().findComponent(GlButton); + + if (!button.exists()) { + return null; + } + + return { + href: button.attributes('href'), + method: button.attributes('data-method'), + text: button.text(), + }; + }; + + describe('without actions', () => { + beforeEach(() => { + createComponent(); + }); + + it('shows alert with message', () => { + expect(findAlert().props()).toMatchObject({ dismissible: false }); + expect(findAlert().text()).toBe(TEST_MESSAGE); + }); + }); + + describe.each` + action | buttonData + ${{}} | ${null} + ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }} | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }} + ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, isForm: true }} | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, method: 'post' }} + `('with action=$action', ({ action, buttonData }) => { + beforeEach(() => { + createComponent({ action }); + }); + + it(`show button=${JSON.stringify(buttonData)}`, () => { + expect(findButtonData()).toEqual(buttonData); + }); + }); +}); |