Skip to content

Commit

Permalink
Refactor HTML attribute tests to be more succinct.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Mar 28, 2017
1 parent 3bc5016 commit 322a968
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 181 deletions.
34 changes: 5 additions & 29 deletions ui_framework/components/button/__snapshots__/button.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`KuiButton Baseline is rendered 1`] = `
<button
class="kuiButton"
>
<span />
</button>
`;

exports[`KuiButton HTML attributes aria-label is rendered 1`] = `
exports[`KuiButton Baseline HTML attributes are rendered 1`] = `
<button
aria-label="aria label"
class="kuiButton"
>
<span />
</button>
`;

exports[`KuiButton HTML attributes className renders the classes 1`] = `
<button
class="kuiButton testClass1 testClass2"
>
<span />
</button>
`;

exports[`KuiButton HTML attributes data-test-subj is rendered 1`] = `
<button
class="kuiButton"
class="kuiButton testClass1 testClass2 kuiButton-isDisabled"
data-test-subj="test subject string"
disabled=""
>
<span />
</button>
`;

exports[`KuiButton HTML attributes disabled sets the disabled attribute and class 1`] = `
exports[`KuiButton Baseline is rendered 1`] = `
<button
class="kuiButton kuiButton-isDisabled"
disabled=""
class="kuiButton"
>
<span />
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`KuiLinkButton Baseline is rendered 1`] = `
<a
class="kuiButton"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes aria-label is rendered 1`] = `
exports[`KuiLinkButton Baseline HTML attributes are rendered (and disabled renders a class) 1`] = `
<a
aria-label="aria label"
class="kuiButton"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes className renders the classes 1`] = `
<a
class="kuiButton testClass1 testClass2"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes data-test-subj is rendered 1`] = `
<a
class="kuiButton"
class="kuiButton testClass1 testClass2 kuiButton-isDisabled"
data-test-subj="test subject string"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes disabled sets the disabled class 1`] = `
<a
class="kuiButton kuiButton-isDisabled"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes href is rendered 1`] = `
<a
class="kuiButton"
href="#"
target="_blank"
>
<span />
</a>
`;

exports[`KuiLinkButton HTML attributes target is rendered 1`] = `
exports[`KuiLinkButton Baseline is rendered 1`] = `
<a
class="kuiButton"
target="_blank"
>
<span />
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`KuiSubmitButton Baseline HTML attributes are rendered 1`] = `
<input
aria-label="aria label"
class="kuiButton testClass1 testClass2 kuiButton-isDisabled"
data-test-subj="test subject string"
disabled=""
type="submit"
/>
`;

exports[`KuiSubmitButton Baseline is rendered 1`] = `
<input
class="kuiButton"
Expand Down
54 changes: 11 additions & 43 deletions ui_framework/components/button/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,19 @@ describe('KuiButton', () => {
expect($button)
.toMatchSnapshot();
});
});

describe('HTML attributes', () => {
describe('aria-label', () => {
test('is rendered', () => {
const $button = render(
<KuiButton aria-label="aria label" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('disabled', () => {
test('sets the disabled attribute and class', () => {
const $button = render(
<KuiButton disabled />
);

expect($button)
.toMatchSnapshot();
});
});

describe('data-test-subj', () => {
test('is rendered', () => {
const $button = render(
<KuiButton data-test-subj="test subject string" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('className', () => {
test('renders the classes', () => {
const $button = render(
<KuiButton className="testClass1 testClass2" />
);
test('HTML attributes are rendered', () => {
const $button = render(
<KuiButton
aria-label="aria label"
className="testClass1 testClass2"
data-test-subj="test subject string"
disabled
/>
);

expect($button)
.toMatchSnapshot();
});
expect($button)
.toMatchSnapshot();
});
});

Expand Down
78 changes: 13 additions & 65 deletions ui_framework/components/button/link_button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,73 +17,21 @@ describe('KuiLinkButton', () => {
expect($button)
.toMatchSnapshot();
});
});

describe('HTML attributes', () => {
describe('href', () => {
test('is rendered', () => {
const $button = render(
<KuiLinkButton href="#" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('target', () => {
test('is rendered', () => {
const $button = render(
<KuiLinkButton target="_blank" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('aria-label', () => {
test('is rendered', () => {
const $button = render(
<KuiLinkButton aria-label="aria label" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('disabled', () => {
test('sets the disabled class', () => {
const $button = render(
<KuiLinkButton disabled />
);

expect($button)
.toMatchSnapshot();
});
});

describe('data-test-subj', () => {
test('is rendered', () => {
const $button = render(
<KuiLinkButton data-test-subj="test subject string" />
);

expect($button)
.toMatchSnapshot();
});
});

describe('className', () => {
test('renders the classes', () => {
const $button = render(
<KuiLinkButton className="testClass1 testClass2" />
);
test('HTML attributes are rendered (and disabled renders a class)', () => {
const $button = render(
<KuiLinkButton
aria-label="aria label"
className="testClass1 testClass2"
data-test-subj="test subject string"
disabled
href="#"
target="_blank"
/>
);

expect($button)
.toMatchSnapshot();
});
expect($button)
.toMatchSnapshot();
});
});

Expand Down
14 changes: 14 additions & 0 deletions ui_framework/components/button/submit_button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ describe('KuiSubmitButton', () => {
expect($button)
.toMatchSnapshot();
});

test('HTML attributes are rendered', () => {
const $button = render(
<KuiSubmitButton
aria-label="aria label"
className="testClass1 testClass2"
data-test-subj="test subject string"
disabled
/>
);

expect($button)
.toMatchSnapshot();
});
});

describe('HTML attributes', () => {
Expand Down

0 comments on commit 322a968

Please sign in to comment.