Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Address output component test file to new format #3308

Merged
merged 36 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
405253b
modified test cases as per the ticket
SriHV Aug 21, 2024
c5b55b4
changes in the given statements
SriHV Aug 21, 2024
c31a74b
Merge branch 'main' into enhancement/133/testing-refactor-address-output
SriHV Aug 22, 2024
0c9d6ba
changes as per comments
SriHV Aug 22, 2024
4284cfe
commiting latest changes
SriHV Sep 3, 2024
3ecbead
Changes as per comments
SriHV Sep 3, 2024
1e070c1
Merge branch 'main' into enhancement/133/testing-refactor-address-output
SriHV Sep 3, 2024
0f06420
removing no params example
SriHV Sep 5, 2024
94f8349
Merge branch 'main' into enhancement/133/testing-refactor-address-output
alessioventuriniAND Sep 11, 2024
45e365d
Update src/components/address-output/_test_examples.js
SriHV Sep 13, 2024
b5299ab
Update src/components/address-output/_macro.spec.js
SriHV Sep 13, 2024
15e1393
Merge branch 'main' into enhancement/133/testing-refactor-address-output
alessioventuriniAND Sep 13, 2024
bd2606e
Merge branch 'main' into enhancement/133/testing-refactor-address-output
SriHV Sep 17, 2024
76bb9db
Merge branch 'main' into enhancement/133/testing-refactor-address-output
alessioventuriniAND Sep 25, 2024
999c4f7
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
ea2c0e5
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
fe023bb
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
317bffa
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
20cec66
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
4697127
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
12d8e0c
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
7aff671
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
894d32d
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
3b4d693
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
a7f4253
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
2fb31fd
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
6e69fc8
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
389c41e
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
c810622
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
f0a1ca6
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
d50ec2b
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
d206b26
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
5c5b3bf
Update src/components/address-output/_macro.spec.js
SriHV Sep 30, 2024
eb0f189
Merge branch 'main' into enhancement/133/testing-refactor-address-output
SriHV Sep 30, 2024
ae73c66
Merge branch 'main' into enhancement/133/testing-refactor-address-output
SriHV Oct 4, 2024
f7fdf05
Merge branch 'main' into enhancement/133/testing-refactor-address-output
rmccar Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 87 additions & 60 deletions src/components/address-output/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,121 @@ import * as cheerio from 'cheerio';
import axe from '../../tests/helpers/axe';
import { renderComponent } from '../../tests/helpers/rendering';

const EXAMPLE_ADDRESS_OUTPUT_FULL = {
unit: 'Unit 5',
organisation: 'Trescos',
line1: 'Abingdon Road',
line2: 'Goathill',
town: 'Barry',
postcode: 'AB12 6UH',
};

const EXAMPLE_ADDRESS_OUTPUT_NONE = {};

describe('macro: address-output', () => {
it('passes jest-axe checks', async () => {
const $ = cheerio.load(renderComponent('address-output', EXAMPLE_ADDRESS_OUTPUT_FULL));

const results = await axe($.html());
expect(results).toHaveNoViolations();
import { EXAMPLE_ADDRESS_OUTPUT_FULL, EXAMPLE_ADDRESS_OUTPUT_NONE } from './_test_examples';

describe('FOR: address-output', () => {
SriHV marked this conversation as resolved.
Show resolved Hide resolved
describe('GIVEN: Params: none', () => {
rmccar marked this conversation as resolved.
Show resolved Hide resolved
describe('WHEN: All params are at default state', () => {
rmccar marked this conversation as resolved.
Show resolved Hide resolved
const $ = cheerio.load(renderComponent('address-output', EXAMPLE_ADDRESS_OUTPUT_FULL));

test('THEN: jest-axe tests pass', async () => {
const results = await axe($.html());
expect(results).toHaveNoViolations();
});
});
});

it('has additionally provided container style classes', () => {
const $ = cheerio.load(
renderComponent('address-output', {
...EXAMPLE_ADDRESS_OUTPUT_FULL,
classes: 'extra-class another-extra-class',
}),
);

expect($('.ons-address-output').hasClass('extra-class')).toBe(true);
expect($('.ons-address-output').hasClass('another-extra-class')).toBe(true);
describe('GIVEN: Params: classes', () => {
describe('WHEN: classes are provided', () => {
const $ = cheerio.load(
renderComponent('address-output', {
...EXAMPLE_ADDRESS_OUTPUT_FULL,
classes: 'extra-class another-extra-class',
}),
);

test('THEN: renders additionally provided classes', async () => {
rmccar marked this conversation as resolved.
Show resolved Hide resolved
expect($('.ons-address-output').hasClass('extra-class')).toBe(true);
expect($('.ons-address-output').hasClass('another-extra-class')).toBe(true);
});
});
});

it('renders no lines when no parameters are provided', () => {
const $ = cheerio.load(renderComponent('address-output', EXAMPLE_ADDRESS_OUTPUT_NONE));
describe('GIVEN: Params: none', () => {
rmccar marked this conversation as resolved.
Show resolved Hide resolved
describe('WHEN: no address lines are provided in the parameters', () => {
const $ = cheerio.load(renderComponent('address-output', EXAMPLE_ADDRESS_OUTPUT_NONE));

expect($('.ons-address-output__lines *').length).toBe(0);
test('THEN: renders no lines', () => {
expect($('.ons-address-output__lines *').length).toBe(0);
});
});
});

it.each([
describe.each([
rmccar marked this conversation as resolved.
Show resolved Hide resolved
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { unit: 'Unit 5' }],
])('renders `unit` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__unit').text().trim()).toBe('Unit 5');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));
rmccar marked this conversation as resolved.
Show resolved Hide resolved

test('THEN: renders `unit` correctly', () => {
expect($('.ons-address-output__unit').text().trim()).toBe('Unit 5');
});
});
});

it.each([
describe.each([
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { organisation: 'Trescos' }],
])('renders `organisation` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__organisation').text().trim()).toBe('Trescos');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));

test('THEN: renders `organisation` correctly', () => {
expect($('.ons-address-output__organisation').text().trim()).toBe('Trescos');
});
});
});

it.each([
describe.each([
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { line1: 'Abingdon Road' }],
])('renders `line1` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__line1').text().trim()).toBe('Abingdon Road');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));

test('THEN: renders `line1` correctly', () => {
expect($('.ons-address-output__line1').text().trim()).toBe('Abingdon Road');
});
});
});

it.each([
describe.each([
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { line2: 'Goathill' }],
])('renders `line2` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__line2').text().trim()).toBe('Goathill');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));

test('THEN: renders `line2` correctly', () => {
expect($('.ons-address-output__line2').text().trim()).toBe('Goathill');
});
});
});

it.each([
describe.each([
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { town: 'Barry' }],
])('renders `town` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__town').text().trim()).toBe('Barry');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));

test('THEN: renders the `town` correctly', () => {
expect($('.ons-address-output__town').text().trim()).toBe('Barry');
});
});
});

it.each([
describe.each([
['all address lines', EXAMPLE_ADDRESS_OUTPUT_FULL],
['single line', { postcode: 'AB12 6UH' }],
])('renders `postcode` with %s', (_, params) => {
const $ = cheerio.load(renderComponent('address-output', params));

expect($('.ons-address-output__postcode').text().trim()).toBe('AB12 6UH');
])('GIVEN: %s', (scenario, params) => {
describe(`WHEN: the address-output with ${scenario}`, () => {
const $ = cheerio.load(renderComponent('address-output', params));

test('THEN: renders the `postcode` correctly', () => {
expect($('.ons-address-output__postcode').text().trim()).toBe('AB12 6UH');
});
});
});
});
12 changes: 12 additions & 0 deletions src/components/address-output/_test_examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export { EXAMPLE_ADDRESS_OUTPUT_FULL, EXAMPLE_ADDRESS_OUTPUT_NONE };

const EXAMPLE_ADDRESS_OUTPUT_FULL = {
unit: 'Unit 5',
organisation: 'Trescos',
line1: 'Abingdon Road',
line2: 'Goathill',
town: 'Barry',
postcode: 'AB12 6UH',
};

const EXAMPLE_ADDRESS_OUTPUT_NONE = {};
rmccar marked this conversation as resolved.
Show resolved Hide resolved
Loading