Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use theforeman github actions for JavaScript tests #137

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions .github/workflows/js_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
<SCCGenericExpander
setInParent={() => {}}
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(
<SCCGenericExpander
setInParent={() => {}}
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');
});
});