diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js')
-rw-r--r-- | third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js new file mode 100644 index 0000000000..a0fa830e4c --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/react-redux/src/components/Footer.spec.js @@ -0,0 +1,102 @@ +import React from 'react' +import TestUtils from 'react-addons-test-utils' +import Footer from './Footer' +import { SHOW_ALL, SHOW_ACTIVE } from '../constants/TodoFilters' + +const setup = propOverrides => { + const props = Object.assign({ + completedCount: 0, + activeCount: 0, + filter: SHOW_ALL, + onClearCompleted: jest.fn(), + onShow: jest.fn() + }, propOverrides) + + const renderer = TestUtils.createRenderer() + renderer.render(<Footer {...props} />) + const output = renderer.getRenderOutput() + + return { + props: props, + output: output + } +} + +const getTextContent = elem => { + const children = Array.isArray(elem.props.children) ? + elem.props.children : [ elem.props.children ] + + return children.reduce((out, child) => + // Concatenate the text + // Children are either elements or text strings + out + (child.props ? getTextContent(child) : child) + , '') +} + +describe('components', () => { + describe('Footer', () => { + it('should render container', () => { + const { output } = setup() + expect(output.type).toBe('footer') + expect(output.props.className).toBe('footer') + }) + + it('should display active count when 0', () => { + const { output } = setup({ activeCount: 0 }) + const [ count ] = output.props.children + expect(getTextContent(count)).toBe('No items left') + }) + + it('should display active count when above 0', () => { + const { output } = setup({ activeCount: 1 }) + const [ count ] = output.props.children + expect(getTextContent(count)).toBe('1 item left') + }) + + it('should render filters', () => { + const { output } = setup() + const [ , filters ] = output.props.children + expect(filters.type).toBe('ul') + expect(filters.props.className).toBe('filters') + expect(filters.props.children.length).toBe(3) + filters.props.children.forEach(function checkFilter(filter, i) { + expect(filter.type).toBe('li') + const a = filter.props.children + expect(a.props.className).toBe(i === 0 ? 'selected' : '') + expect(a.props.children).toBe({ + 0: 'All', + 1: 'Active', + 2: 'Completed' + }[i]) + }) + }) + + it('should call onShow when a filter is clicked', () => { + const { output, props } = setup() + const [ , filters ] = output.props.children + const filterLink = filters.props.children[1].props.children + filterLink.props.onClick({}) + expect(props.onShow).toBeCalledWith(SHOW_ACTIVE) + }) + + it('shouldnt show clear button when no completed todos', () => { + const { output } = setup({ completedCount: 0 }) + const [ , , clear ] = output.props.children + expect(clear).toBe(undefined) + }) + + it('should render clear button when completed todos', () => { + const { output } = setup({ completedCount: 1 }) + const [ , , clear ] = output.props.children + expect(clear.type).toBe('button') + expect(clear.props.children).toBe('Clear completed') + }) + + it('should call onClearCompleted on clear button click', () => { + const { output, props } = setup({ completedCount: 1 }) + const [ , , clear ] = output.props.children + clear.props.onClick({}) + expect(props.onClearCompleted).toBeCalled() + }) + }) +}) |