diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index 4a74e948..a4c03e02 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -2,27 +2,21 @@ name: JavaScript Testing on: push: branches: - - main + - master pull_request: paths: - 'webpack/**' - 'package.json' - 'package-lock.json' - '.github/workflows/js_tests.yml' + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + jobs: - test_js: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - node-version: [12, 14] - steps: - - uses: actions/checkout@v2 - - name: Setup Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Npm install - run: npm install - - name: Run plugin linter - run: npm run lint + test: + name: JavaScript + uses: theforeman/actions/.github/workflows/foreman_plugin_js.yml@v0 + with: + plugin: foreman_scc_manager diff --git a/package.json b/package.json index 713ba705..abbc1a73 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "lint": "tfm-lint --plugin -d /webpack", - "test": "echo \"Error: no test specified\" && exit 1", + "test": "tfm-test --plugin", "create-react-component": "yo react-domain" }, "repository": { diff --git a/webpack/components/SCCProductPage/components/common/SCCGenericExpander/SCCGenericExpander.test.js b/webpack/components/SCCProductPage/components/common/SCCGenericExpander/SCCGenericExpander.test.js new file mode 100644 index 00000000..7757d3e4 --- /dev/null +++ b/webpack/components/SCCProductPage/components/common/SCCGenericExpander/SCCGenericExpander.test.js @@ -0,0 +1,47 @@ +/* eslint-disable promise/prefer-await-to-then */ +// Configure Enzyme +import { mount, shallow } from '@theforeman/test'; +import React from 'react'; +import SCCGenericExpander from './index'; + +describe('SCCGenericExpander', () => { + it('renders default properties', () => { + const wrapper = mount( + {}} + selectOptionOpen="open" + selectOptionClose="close" + initLabel="open/close" + /> + ); + + expect(wrapper.find('SCCGenericExpander')).toHaveLength(1); + expect(wrapper.find('Flex')).toHaveLength(1); + expect(wrapper.find('FlexItem')).toHaveLength(1); + expect(wrapper.find('Select')).toHaveLength(1); + }); + + it('passes properties', () => { + const wrapper = shallow( + {}} + selectOptionOpen="open" + selectOptionClose="close" + initLabel="open/close" + /> + ); + + // Select + const select = wrapper.find('Select'); + expect(select.exists()).toBe(true); + expect(select.props()).toHaveProperty('selections'); + expect(select.prop('selections')).toContain('open/close'); + + // SelectOptions + const selectOptions = wrapper.find('SelectOption'); + expect(selectOptions).toHaveLength(2); + const optionValues = selectOptions.map((option) => option.prop('value')); + expect(optionValues).toContain('open'); + expect(optionValues).toContain('close'); + }); +});