Skip to content

Commit

Permalink
UpdateS
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfarrell76 committed Aug 8, 2024
1 parent f6a865b commit 0a24be2
Show file tree
Hide file tree
Showing 19 changed files with 714 additions and 194 deletions.
25 changes: 20 additions & 5 deletions src/tests/AcceptAll.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@ import { test, expect, describe, beforeEach } from '@jest/globals';

import { AcceptAll } from '../components/AcceptAll';
import { fireEvent } from '@testing-library/preact';
import { MOCK_PURPOSES_OPTED_OUT } from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock'
import {
MOCK_PURPOSES_OPTED_OUT,
MOCK_TEMPLATE_VARIABLES,
} from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock';

describe('AcceptAll', () => {
beforeEach(() => {
initMockAirgap(MOCK_PURPOSES_OPTED_OUT);
});

test('matches snapshot', () => {
const { snapshot } = render(<AcceptAll handleSetViewState={() => null} />);
const { snapshot } = render(
<AcceptAll
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);
expect(snapshot).toMatchSnapshot();
});

test('submission affects stored consent', () => {
const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptAll handleSetViewState={() => null} />);
const { container } = render(
<AcceptAll
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const submitButton = container.querySelector('button');
Expand All @@ -30,7 +43,9 @@ describe('AcceptAll', () => {
const consent = { ...testWindow.airgap.getConsent() };

Object.entries(MOCK_PURPOSES_OPTED_OUT).forEach(([, purpose]) => {
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(!consent.purposes?.[purpose.name]);
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(
!consent.purposes?.[purpose.name],
);
});
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
Expand Down
50 changes: 38 additions & 12 deletions src/tests/AcceptAllOrMoreChoices.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { test, expect, describe, beforeEach } from '@jest/globals';

import { AcceptAllOrMoreChoices } from '../components/AcceptAllOrMoreChoices';
import { fireEvent } from '@testing-library/preact';
import { MOCK_PURPOSES_OPTED_OUT } from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock'
import {
MOCK_PURPOSES_OPTED_OUT,
MOCK_TEMPLATE_VARIABLES,
} from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock';
import { messages } from '../messages';

describe('AcceptAllOrMoreChoices', () => {
Expand All @@ -16,17 +19,26 @@ describe('AcceptAllOrMoreChoices', () => {
});

test('matches snapshot', () => {
const { snapshot } = render(<AcceptAllOrMoreChoices handleSetViewState={() => null} />);
const { snapshot } = render(
<AcceptAllOrMoreChoices
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);
expect(snapshot).toMatchSnapshot();
});

test('button ordering is consistent', () => {
const { container } = render(<AcceptAllOrMoreChoices handleSetViewState={() => null} />);
const { container } = render(
<AcceptAllOrMoreChoices
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

const domLabels = [...container.querySelectorAll('button')]
?.map((span) =>
span.children[0].childNodes.item(0).textContent
)
const domLabels = [...container.querySelectorAll('button')]?.map(
(span) => span.children[0].childNodes.item(0).textContent,
);

expect(domLabels).toStrictEqual([
messages.acceptAllButtonPrimary.defaultMessage,
Expand All @@ -36,7 +48,12 @@ describe('AcceptAllOrMoreChoices', () => {

test('submission affects stored consent', () => {
const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptAllOrMoreChoices handleSetViewState={() => null} />);
const { container } = render(
<AcceptAllOrMoreChoices
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const submitButton = container.querySelector('button');
Expand All @@ -45,19 +62,28 @@ describe('AcceptAllOrMoreChoices', () => {
const consent = { ...testWindow.airgap.getConsent() };

Object.entries(MOCK_PURPOSES_OPTED_OUT).forEach(([, purpose]) => {
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(!consent.purposes?.[purpose.name]);
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(
!consent.purposes?.[purpose.name],
);
});
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
});

test('that CompleteOptions is opened', () => {
let calledArg;
const { container } = render(<AcceptAllOrMoreChoices handleSetViewState={(state) => { calledArg = state }} />);
const { container } = render(
<AcceptAllOrMoreChoices
handleSetViewState={(state) => {
calledArg = state;
}}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

const moreChoicesButton = container.querySelector('button:nth-of-type(2)');
if (moreChoicesButton) fireEvent.click(moreChoicesButton);

expect(calledArg).toEqual('CompleteOptions')
expect(calledArg).toEqual('CompleteOptions');
});
});
40 changes: 33 additions & 7 deletions src/tests/AcceptAllRejectAllToggle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@ import { test, expect, describe } from '@jest/globals';

import { AcceptAllRejectAllToggle } from '../components/AcceptAllRejectAllToggle';
import { fireEvent } from '@testing-library/preact';
import { MOCK_PURPOSES_OPTED_IN, MOCK_PURPOSES_OPTED_OUT } from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock'
import {
MOCK_PURPOSES_OPTED_IN,
MOCK_PURPOSES_OPTED_OUT,
MOCK_TEMPLATE_VARIABLES,
} from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock';

describe('AcceptAllRejectAllToggle', () => {
test('matches snapshot', () => {
const { snapshot } = render(<AcceptAllRejectAllToggle fontColor="#000" handleSetViewState={() => null} />);
const { snapshot } = render(
<AcceptAllRejectAllToggle
fontColor="#000"
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);
expect(snapshot).toMatchSnapshot();
});

test('submission affects stored consent (opted out)', () => {
initMockAirgap(MOCK_PURPOSES_OPTED_OUT);

const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptAllRejectAllToggle fontColor="#000" handleSetViewState={() => null} />);
const { container } = render(
<AcceptAllRejectAllToggle
fontColor="#000"
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const toggleCheckbox = container.querySelector('input');
Expand All @@ -29,7 +45,9 @@ describe('AcceptAllRejectAllToggle', () => {
const consent = { ...testWindow.airgap.getConsent() };

Object.entries(MOCK_PURPOSES_OPTED_OUT).forEach(([, purpose]) => {
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(!consent.purposes?.[purpose.name]);
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(
!consent.purposes?.[purpose.name],
);
});
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
Expand All @@ -39,7 +57,13 @@ describe('AcceptAllRejectAllToggle', () => {
initMockAirgap(MOCK_PURPOSES_OPTED_IN);

const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptAllRejectAllToggle fontColor="#000" handleSetViewState={() => null} />);
const { container } = render(
<AcceptAllRejectAllToggle
fontColor="#000"
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const toggleCheckbox = container.querySelector('input');
Expand All @@ -49,7 +73,9 @@ describe('AcceptAllRejectAllToggle', () => {
const consent = { ...testWindow.airgap.getConsent() };

Object.entries(MOCK_PURPOSES_OPTED_IN).forEach(([, purpose]) => {
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(!consent.purposes?.[purpose.name]);
expect(!!prevConsent.purposes?.[purpose.name]).toEqual(
!consent.purposes?.[purpose.name],
);
});
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
Expand Down
51 changes: 39 additions & 12 deletions src/tests/AcceptOrRejectAdvertising.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@ import { test, expect, describe } from '@jest/globals';

import { AcceptOrRejectAdvertising } from '../components/AcceptOrRejectAdvertising';
import { fireEvent } from '@testing-library/preact';
import { MOCK_PURPOSES_OPTED_IN, MOCK_PURPOSES_OPTED_OUT } from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock'
import {
MOCK_PURPOSES_OPTED_IN,
MOCK_PURPOSES_OPTED_OUT,
MOCK_TEMPLATE_VARIABLES,
} from './utils/constants';
import { init as initMockAirgap } from './utils/ag-mock';
import { messages } from '../messages';

describe('AcceptOrRejectAdvertising', () => {
test('matches snapshot', () => {
const { snapshot } = render(<AcceptOrRejectAdvertising handleSetViewState={() => null} />);
const { snapshot } = render(
<AcceptOrRejectAdvertising
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);
expect(snapshot).toMatchSnapshot();
});

test('button ordering is consistent', () => {
initMockAirgap(MOCK_PURPOSES_OPTED_OUT);
const { container } = render(<AcceptOrRejectAdvertising handleSetViewState={() => null} />);
const { container } = render(
<AcceptOrRejectAdvertising
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

const domLabels = [...container.querySelectorAll('button')]
?.map((span) =>
span.children[0].childNodes.item(0).textContent
)
const domLabels = [...container.querySelectorAll('button')]?.map(
(span) => span.children[0].childNodes.item(0).textContent,
);

expect(domLabels).toStrictEqual([
messages.acceptAdvertising.defaultMessage,
Expand All @@ -34,31 +47,45 @@ describe('AcceptOrRejectAdvertising', () => {
test('submission affects stored consent (opted out)', () => {
initMockAirgap(MOCK_PURPOSES_OPTED_OUT);
const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptOrRejectAdvertising handleSetViewState={() => null} />);
const { container } = render(
<AcceptOrRejectAdvertising
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const acceptButton = container.querySelector('button');
if (acceptButton) fireEvent.click(acceptButton);

const consent = { ...testWindow.airgap.getConsent() };

expect(!!prevConsent.purposes?.Advertising).toEqual(!consent.purposes?.Advertising);
expect(!!prevConsent.purposes?.Advertising).toEqual(
!consent.purposes?.Advertising,
);
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
});

test('submission affects stored consent (opted in)', () => {
initMockAirgap(MOCK_PURPOSES_OPTED_IN);
const prevConsent = { ...testWindow.airgap.getConsent() };
const { container } = render(<AcceptOrRejectAdvertising handleSetViewState={() => null} />);
const { container } = render(
<AcceptOrRejectAdvertising
handleSetViewState={() => null}
globalUiVariables={MOCK_TEMPLATE_VARIABLES}
/>,
);

// Ensure submission reflects purpose selection in airgap
const rejectButton = container.querySelector('button:nth-of-type(2)');
if (rejectButton) fireEvent.click(rejectButton);

const consent = { ...testWindow.airgap.getConsent() };

expect(!!prevConsent.purposes?.Advertising).toEqual(!consent.purposes?.Advertising);
expect(!!prevConsent.purposes?.Advertising).toEqual(
!consent.purposes?.Advertising,
);
expect(prevConsent.confirmed).toEqual(false);
expect(consent.confirmed).toEqual(true);
});
Expand Down
Loading

0 comments on commit 0a24be2

Please sign in to comment.