Skip to content

Commit

Permalink
Refactor tests to separate different behaviors.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Oct 4, 2023
1 parent ecbc37f commit a8baa75
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions src/www/views/contact_view/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {fixture, html, nextFrame, oneEvent} from '@open-wc/testing';
import {SupportForm} from './support_form';
import {OutlineErrorReporter, SentryErrorReporter} from '../../shared/error_reporter';
import {localize} from '../../testing/localize';
import {ListItem} from '@material/mwc-list';
import {ListItemBase} from '@material/mwc-list/mwc-list-item-base';
import {Select} from '@material/mwc-select';

describe('ContactView client variant', () => {
let el: ContactView;
Expand Down Expand Up @@ -59,20 +60,30 @@ describe('ContactView client variant', () => {
expect(exitCard.textContent).toContain('experiencing high support volume');
});

it('shows issue selector if the user selects that they have no open tickets', async () => {
const radioButton = el.shadowRoot!.querySelectorAll('mwc-formfield mwc-radio')[1] as HTMLElement;
radioButton.click();
await nextFrame();
describe('when the user selects that they have no open tickets', () => {
let issueSelector: Select;

beforeEach(async () => {
const radioButton = el.shadowRoot!.querySelectorAll('mwc-formfield mwc-radio')[1] as HTMLElement;
radioButton.click();
await nextFrame();

issueSelector = el.shadowRoot!.querySelector('mwc-select')!;
});

it('shows the issue selector', () => {
expect(issueSelector.hasAttribute('hidden')).toBeFalse();
});

const issueSelector = el.shadowRoot!.querySelector('mwc-select')!;
expect(issueSelector.hasAttribute('hidden')).toBeFalse();
const issueItemEls = issueSelector.querySelectorAll('mwc-list-item');
const issueTypes = Array.from(issueItemEls).map((el: ListItem) => el.value);
expect(issueTypes).toEqual(['no-server', 'cannot-add-server', 'connection', 'performance', 'general']);
it('shows the correct items in the selector', () => {
const issueItemEls = issueSelector.querySelectorAll('mwc-list-item');
const issueTypes = Array.from(issueItemEls).map((el: ListItemBase) => el.value);
expect(issueTypes).toEqual(['no-server', 'cannot-add-server', 'connection', 'performance', 'general']);
});
});

describe('when the user selects issue', () => {
let issueSelector: HTMLElement;
let issueSelector: Select;

beforeEach(async () => {
issueSelector = el.shadowRoot!.querySelector('mwc-select')!;
Expand Down Expand Up @@ -158,23 +169,37 @@ describe('ContactView client variant', () => {
});

describe('ContactView manager variant', () => {
it('shows issue selector if the user selects that they have no open tickets', async () => {
const mockErrorReporter: jasmine.SpyObj<OutlineErrorReporter> = jasmine.createSpyObj(
'SentryErrorReporter',
Object.getOwnPropertyNames(SentryErrorReporter.prototype)
);
const el = await fixture(
html` <contact-view .localize=${localize} variant="manager" .errorReporter=${mockErrorReporter}></contact-view> `
);
let el: ContactView;

const radioButton = el.shadowRoot!.querySelectorAll('mwc-formfield mwc-radio')[1] as HTMLElement;
radioButton.click();
await nextFrame();
describe('when the user selects that they have no open tickets', () => {
let issueSelector: Select;

beforeEach(async () => {
const mockErrorReporter: jasmine.SpyObj<OutlineErrorReporter> = jasmine.createSpyObj(
'SentryErrorReporter',
Object.getOwnPropertyNames(SentryErrorReporter.prototype)
);
el = await fixture(
html`
<contact-view .localize=${localize} variant="manager" .errorReporter=${mockErrorReporter}></contact-view>
`
);

const radioButton = el.shadowRoot!.querySelectorAll('mwc-formfield mwc-radio')[1] as HTMLElement;
radioButton.click();
await nextFrame();

issueSelector = el.shadowRoot!.querySelector('mwc-select')!;
});

it('shows the issue selector', () => {
expect(issueSelector.hasAttribute('hidden')).toBeFalse();
});

const issueSelector = el.shadowRoot!.querySelector('mwc-select')!;
expect(issueSelector.hasAttribute('hidden')).toBeFalse();
const issueItemEls = issueSelector.querySelectorAll('mwc-list-item');
const issueTypes = Array.from(issueItemEls).map((el: ListItem) => el.value);
expect(issueTypes).toEqual(['cannot-add-server', 'connection', 'managing', 'general']);
it('shows the correct items in the selector', () => {
const issueItemEls = issueSelector.querySelectorAll('mwc-list-item');
const issueTypes = Array.from(issueItemEls).map((el: ListItemBase) => el.value);
expect(issueTypes).toEqual(['cannot-add-server', 'connection', 'managing', 'general']);
});
});
});

0 comments on commit a8baa75

Please sign in to comment.