From 3ab9f0423e97af63da4bf6a13ffd786955bd5b3b Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Thu, 26 Oct 2023 21:55:55 +0200
Subject: refactor(hooks,providers): rewrite useAckee hook and AckeeProvider

---
 .../ackee-provider/ackee-provider.test.tsx         | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 src/utils/providers/ackee-provider/ackee-provider.test.tsx

(limited to 'src/utils/providers/ackee-provider/ackee-provider.test.tsx')

diff --git a/src/utils/providers/ackee-provider/ackee-provider.test.tsx b/src/utils/providers/ackee-provider/ackee-provider.test.tsx
new file mode 100644
index 0000000..7ba11dc
--- /dev/null
+++ b/src/utils/providers/ackee-provider/ackee-provider.test.tsx
@@ -0,0 +1,46 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { type FC, useContext } from 'react';
+import type { AckeeTrackerValue } from '../../../types';
+import { AckeeContext, AckeeProvider } from './ackee-provider';
+
+const bodyPrefix = 'Tracking is set to:';
+
+const ComponentTest: FC = () => {
+  const { tracking } = useContext(AckeeContext);
+
+  return (
+    <div>
+      {bodyPrefix} {tracking}
+    </div>
+  );
+};
+
+describe('AckeeProvider', () => {
+  it('uses the default value when the provider is not used', () => {
+    render(<ComponentTest />);
+
+    expect(rtlScreen.getByText(new RegExp(bodyPrefix))).toHaveTextContent(
+      `${bodyPrefix} full`
+    );
+  });
+
+  it('provides the given tracking value to its children', () => {
+    const tracking: AckeeTrackerValue = 'partial';
+
+    render(
+      <AckeeProvider
+        domainId="some-id"
+        server="https://example.com"
+        storageKey="facilis"
+        tracking={tracking}
+      >
+        <ComponentTest />
+      </AckeeProvider>
+    );
+
+    expect(rtlScreen.getByText(new RegExp(bodyPrefix))).toHaveTextContent(
+      `${bodyPrefix} ${tracking}`
+    );
+  });
+});
-- 
cgit v1.2.3

