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

feat: allow multiple phone and email records for contact information #63

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions __tests__/app/[id]/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {beforeEach, expect, test, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
import Page from '@/app/[id]/page';
import {fetchNewspaperTitleFromCatalog, getLinkToNewspaperInCatalog} from '@/services/catalog.data';
import {MockBox1, MockCatalogTitle1, MockNewspaper1, MockTitle} from '../../mockdata';
import {getBoxForTitle, getLocalTitle, getNewspapersForBoxOnTitle} from '@/services/local.data';
import {MockBox1, MockCatalogTitle1, MockContactEmail1, MockContactPhone1, MockNewspaper1, MockTitle} from '../../mockdata';
import {getBoxForTitle, getContactInfoForTitle, getLocalTitle, getNewspapersForBoxOnTitle} from '@/services/local.data';
import {NotFoundError} from '@/models/Errors';

beforeEach(() => {
Expand All @@ -12,6 +12,7 @@ beforeEach(() => {
vi.mocked(getLocalTitle).mockImplementation(() => Promise.resolve(MockTitle));
vi.mocked(getBoxForTitle).mockImplementation(() => Promise.resolve(MockBox1));
vi.mocked(getNewspapersForBoxOnTitle).mockImplementation(() => Promise.resolve([MockNewspaper1]));
vi.mocked(getContactInfoForTitle).mockImplementation(() => Promise.resolve([MockContactEmail1, MockContactPhone1]));
render(<Page params={{id: ''}}/>);
});

Expand All @@ -31,8 +32,8 @@ test('Title page displays shelf', async () => {
test('Title page displays contact info', async () => {
await screen.findByText('Kontaktinformasjon:');
expect(screen.findByText(MockTitle.contact_name!)).toBeTruthy();
expect(screen.findByText(MockTitle.contact_email!)).toBeTruthy();
expect(screen.findByText(MockTitle.contact_phone!)).toBeTruthy();
expect(screen.findByText(MockContactEmail1.contact_value)).toBeTruthy();
expect(screen.findByText(MockContactPhone1.contact_value)).toBeTruthy();
expect(screen.findByText(MockTitle.vendor!)).toBeTruthy();
});

Expand Down
73 changes: 0 additions & 73 deletions __tests__/components/ContactAndReleaseInfo.test.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions __tests__/components/ContactInformation.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {beforeEach, expect, test} from 'vitest';
import {render, screen} from '@testing-library/react';
import {MockContactEmail1, MockContactPhone1, MockTitle} from '../mockdata';
import ContactInformation from '@/components/ContactInformation';

beforeEach(() => {
render(
<ContactInformation
vendor={MockTitle.vendor}
contactName={MockTitle.contact_name}
contactInformation={[MockContactEmail1, MockContactPhone1]}
/>);
});

test('ContactInformation should render vendor', () => {
expect(screen.getByText('Avleverer:')).toBeTruthy();
expect(screen.getByText(MockTitle.vendor!)).toBeTruthy();
});

test('ContactInformation should render contact name', () => {
expect(screen.getByText('Kontaktperson:')).toBeTruthy();
expect(screen.getByText(MockTitle.contact_name!)).toBeTruthy();
});

test('ContactInformation should render phone numbers', () => {
expect(screen.getByText('Telefonnummer')).toBeTruthy();
expect(screen.getByText(MockContactPhone1.contact_value)).toBeTruthy();
});

test('ContactInformation should render emails', () => {
expect(screen.getByText('E-postadresse')).toBeTruthy();
expect(screen.getByText(MockContactEmail1.contact_value)).toBeTruthy();
});
61 changes: 61 additions & 0 deletions __tests__/components/ContactInformationForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {beforeEach, expect, test, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
import ContactInformationForm from '@/components/ContactInformationForm';
import {MockContactEmail1, MockContactPhone1, MockTitle} from '../mockdata';
import {Form, Formik} from 'formik';
import {TitleContactInfo} from '@/models/TitleContactInfo';

beforeEach(() => {
const titleContact: TitleContactInfo = {
title: MockTitle,
contactInfo: [MockContactEmail1, MockContactPhone1]
};
render(
<Formik
enableReinitialize
initialValues={titleContact}
onSubmit={() => {}}
>
{({
values,
handleChange,
handleBlur,
}) => (
<Form>
<ContactInformationForm
values={values}
handleChange={handleChange}
handleBlur={handleBlur}
handleAdd={vi.fn()}
handleRemove={vi.fn()}
/>
</Form>
)}
</Formik>
);
});

test('ContactInformation should render vendor', () => {
expect(screen.getByText('Avleverer')).toBeTruthy();
expect(screen.getByDisplayValue(MockTitle.vendor!)).toBeTruthy();
});

test('ContactInformation should render contact name', () => {
expect(screen.getByText('Navn')).toBeTruthy();
expect(screen.getByDisplayValue(MockTitle.contact_name!)).toBeTruthy();
});

test('ContactInformation should render phone numbers', () => {
expect(screen.getByText('Telefon')).toBeTruthy();
expect(screen.getByDisplayValue(MockContactPhone1.contact_value)).toBeTruthy();
});

test('ContactInformation should render emails', () => {
expect(screen.getByText('E-post')).toBeTruthy();
expect(screen.getByDisplayValue(MockContactEmail1.contact_value)).toBeTruthy();
});

test('ContactInformation should render add buttons', () => {
expect(screen.getByRole('button', {name: '+ Legg til telefon'})).toBeTruthy();
expect(screen.getByRole('button', {name: '+ Legg til e-post'})).toBeTruthy();
});
21 changes: 21 additions & 0 deletions __tests__/components/ReleasePattern.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {beforeEach, expect, test, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
import {MockTitle} from '../mockdata';
import ReleasePattern from '@/components/ReleasePattern';

beforeEach(() => {
render(<ReleasePattern releasePattern={MockTitle.release_pattern}/>);
});

test('ReleasePattern should render', async () => {
await vi.waitFor(() => expect(screen.getByRole('table')).toBeTruthy());

expect(screen.getByText('Utgivelsesmønster:')).toBeTruthy();
expect(screen.getByText('Mandag:')).toBeTruthy();
expect(screen.getByText('Tirsdag:')).toBeTruthy();
expect(screen.getByText('Onsdag:')).toBeTruthy();
expect(screen.getByText('Torsdag:')).toBeTruthy();
expect(screen.getByText('Fredag:')).toBeTruthy();
expect(screen.getByText('Lørdag:')).toBeTruthy();
expect(screen.getByText('Søndag:')).toBeTruthy();
});
47 changes: 47 additions & 0 deletions __tests__/components/ReleasePatternForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {beforeEach, expect, test, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
import {MockTitle} from '../mockdata';
import {Form, Formik} from 'formik';
import ReleasePatternForm from '@/components/ReleasePatternForm';

beforeEach(() => {
render(
<Formik
enableReinitialize
initialValues={MockTitle.release_pattern}
onSubmit={() => {}}
>
{({
values,
handleChange,
handleBlur,
}) => (
<Form>
<ReleasePatternForm
releasePattern={values}
handleChange={handleChange}
handleBlur={handleBlur}
/>
</Form>
)}
</Formik>
);
});

test('ReleasePatternForm should render all day labels', () => {
expect(screen.getByText('Mandag')).toBeTruthy();
expect(screen.getByText('Tirsdag')).toBeTruthy();
expect(screen.getByText('Onsdag')).toBeTruthy();
expect(screen.getByText('Torsdag')).toBeTruthy();
expect(screen.getByText('Fredag')).toBeTruthy();
expect(screen.getByText('Lørdag')).toBeTruthy();
expect(screen.getByText('Søndag')).toBeTruthy();
});

test('ReleasePatternForm should render all input fields with correct values', () => {
const inputsWith1: number = MockTitle.release_pattern.filter(val => val === 1).length;
const inputsWith0: number = MockTitle.release_pattern.filter(val => val === 0).length;

expect(screen.getAllByRole('gridcell', {name: '1'}).length).toEqual(inputsWith1);
expect(screen.getAllByRole('gridcell', {name: '0'}).length).toEqual(inputsWith0);
});
2 changes: 1 addition & 1 deletion __tests__/components/SearchBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('SearchBar should render', async () => {
await vi.waitFor(() => expect(screen.getByRole('combobox')).toBeTruthy());
});

test('SearchBar should have help test', async () => {
test('SearchBar should have help text', async () => {
await vi.waitFor(() => expect(screen.getByText('Søk etter avistittel')).toBeTruthy());
});

Expand Down
24 changes: 13 additions & 11 deletions __tests__/mockdata.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {box, newspaper, title} from '@prisma/client';
import {box, contact_info, newspaper, title} from '@prisma/client';
import {CatalogTitle} from '@/models/CatalogTitle';

/* eslint-disable @typescript-eslint/naming-convention */

export const MockTitle: title = {
id: 987,
contact_email: '[email protected]',
contact_name: 'Hugin Huginson',
contact_phone: '12345678',
vendor: 'Hugin AS',
release_pattern: [1, 0, 1, 0, 1, 0, 0],
shelf: '1-1',
Expand Down Expand Up @@ -50,12 +48,16 @@ export const MockNewspaper1: newspaper = {
catalog_id: '123456'
};

export const MockNewspaper2: newspaper = {
edition: '2',
date: new Date(2024, 1, 2),
received: true,
username: 'testuser',
notes: 'notater på avis',
box_id: MockBox1.id,
catalog_id: '123456'
export const MockContactEmail1: contact_info = {
id: 'c15d58c6-bc44-49d9-9cbb-e4df84748fde',
title_id: MockTitle.id,
contact_type: 'email',
contact_value: '[email protected]',
};

export const MockContactPhone1: contact_info = {
id: 'd712ce79-f51a-49ed-b7e6-0df2552d325c',
title_id: MockTitle.id,
contact_type: 'phone',
contact_value: '12345678',
};
3 changes: 2 additions & 1 deletion __tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ beforeAll(() => {
getNewspapersForBoxOnTitle: vi.fn(),
postNewBoxForTitle: vi.fn(),
postNewIssuesForTitle: vi.fn(),
deleteIssue: vi.fn()
deleteIssue: vi.fn(),
getContactInfoForTitle: vi.fn(),
}));

const ResizeObserverMock = vi.fn(() => ({
Expand Down
Loading