AdithyaSK's picture
AdithyaSK HF Staff
Add files using upload-large-folder tool
f9f6cee verified
Raw
History Blame Contribute Delete
3.97 kB
diff --git a/packages/components/psammead-social-embed/src/Notice/index.test.jsx b/packages/components/psammead-social-embed/src/Notice/index.test.jsx
new file mode 100644
index 000000000..ad2a67723
--- /dev/null
+++ b/packages/components/psammead-social-embed/src/Notice/index.test.jsx
@@ -0,0 +1,103 @@
+import React from 'react';
+import { render } from '@testing-library/react';
+import 'jest-styled-components';
+import Notice from './index';
+
+const renderNotice = () =>
+ render(
+ <Notice
+ provider="twitter"
+ service="news"
+ text="Sorry but we're having trouble displaying this content"
+ linkText="View content on %provider_name%"
+ linkTextSuffixVisuallyHidden=", external"
+ linkHref="embed-url"
+ warningText="Warning: BBC is not responsible for third party content"
+ />,
+ );
+
+const KNOWN_COLOR_VALUES = [
+ '#222222',
+ '#3F3F42',
+ '#6E6E73',
+ '#AEAEB5',
+ '#404040',
+ '#000000',
+ '#FFFFFF',
+ 'inherit',
+ 'transparent',
+ 'currentColor',
+];
+
+const hasRule = (element, property, value, modifier) => {
+ try {
+ if (modifier) {
+ expect(element).toHaveStyleRule(property, value, { modifier });
+ } else {
+ expect(element).toHaveStyleRule(property, value);
+ }
+ return true;
+ } catch (e) {
+ return false;
+ }
+};
+
+const getExplicitColor = (wrapper, modifier) => {
+ for (let i = 0; i < KNOWN_COLOR_VALUES.length; i += 1) {
+ const c = KNOWN_COLOR_VALUES[i];
+ if (hasRule(wrapper, 'color', c, modifier)) return c;
+ }
+ return null;
+};
+
+const getWrapperColor = wrapper => {
+ for (let i = 0; i < KNOWN_COLOR_VALUES.length; i += 1) {
+ const c = KNOWN_COLOR_VALUES[i];
+ if (hasRule(wrapper, 'color', c)) return c;
+ }
+ return null;
+};
+
+
+const effectiveColorIs = (wrapper, modifier, color) => {
+ if (!modifier) return hasRule(wrapper, 'color', color);
+ const explicit = getExplicitColor(wrapper, modifier);
+ if (explicit && explicit !== 'inherit') return explicit === color;
+ return getWrapperColor(wrapper) === color;
+};
+
+describe('Notice fallback colours', () => {
+ it('paragraph text should render as C_SHADOW (#3F3F42)', () => {
+ const { container } = renderNotice();
+ expect(effectiveColorIs(container.firstChild, 'p', '#3F3F42')).toBe(true);
+ });
+
+ it('warning (small) text should render as C_SHADOW (#3F3F42)', () => {
+ const { container } = renderNotice();
+ expect(effectiveColorIs(container.firstChild, 'small', '#3F3F42')).toBe(
+ true,
+ );
+ });
+
+ it('paragraph text should no longer render as C_EBON (#222222)', () => {
+ const { container } = renderNotice();
+ expect(effectiveColorIs(container.firstChild, 'p', '#222222')).toBe(false);
+ });
+
+ it('link should render as C_EBON (#222222)', () => {
+ const { container } = renderNotice();
+ expect(effectiveColorIs(container.firstChild, 'a', '#222222')).toBe(true);
+ });
+
+ it('link should not render as C_SHADOW (#3F3F42)', () => {
+ const { container } = renderNotice();
+ expect(effectiveColorIs(container.firstChild, 'a', '#3F3F42')).toBe(false);
+ });
+
+ it('visited link should remain C_METAL (#6E6E73)', () => {
+ const { container } = renderNotice();
+ expect(container.firstChild).toHaveStyleRule('color', '#6E6E73', {
+ modifier: 'a:visited',
+ });
+ });
+});
diff --git a/test_commands.json b/test_commands.json
new file mode 100644
index 000000000..4d8854ef1
--- /dev/null
+++ b/test_commands.json
@@ -0,0 +1,3 @@
+{
+ "test_commands": ["npx jest packages/components/psammead-social-embed/src/Notice/index.test.jsx --no-coverage --ci"]
+}
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed
+rc=0
+npx jest packages/components/psammead-social-embed/src/Notice/index.test.jsx --no-coverage --ci
+rc=$(( rc | $? ))
+exit $rc