File size: 3,966 Bytes
f9f6cee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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