-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26afb67
commit c424a4c
Showing
13 changed files
with
2,643 additions
and
1,823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
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(); | ||
}); | ||
|
||
// test('Title page contact and release does not open in edit mode', async () => { | ||
// await screen.findByText('Legg til telefon'); | ||
// | ||
// expect(screen.getByText('Kontaktinformasjon', {exact: false})).toBeTruthy(); | ||
// expect(screen.getByText('Avleverer:', {exact: false})).toBeTruthy(); | ||
// expect(screen.getByText('Kontaktperson:', {exact: false})).toBeTruthy(); | ||
// expect(screen.getByText('E-post:', {exact: false})).toBeTruthy(); | ||
// expect(screen.getByText('Telefon:', {exact: false})).toBeTruthy(); | ||
// | ||
// expect(screen.queryByRole('textbox', {name: 'Avleverer'})).toBeNull(); | ||
// expect(screen.queryByRole('textbox', {name: 'Navn'})).toBeNull(); | ||
// expect(screen.queryByRole('textbox', {name: 'E-post'})).toBeNull(); | ||
// expect(screen.queryByRole('textbox', {name: 'Telefon'})).toBeNull(); | ||
// }); | ||
// | ||
// test('Title page contact and release can be edited after button press', async () => { | ||
// screen.getByRole('button', {name: 'Rediger'}).click(); | ||
// await vi.waitFor(() => screen.getByRole('textbox', {name: 'Avleverer'})); | ||
// | ||
// expect(screen.getByRole('textbox', {name: 'Avleverer'})).toBeTruthy(); | ||
// expect(screen.getByRole('textbox', {name: 'Navn'})).toBeTruthy(); | ||
// expect(screen.getByRole('textbox', {name: 'E-post'})).toBeTruthy(); | ||
// expect(screen.getByRole('textbox', {name: 'Telefon'})).toBeTruthy(); | ||
// }); | ||
// | ||
// test('Title page contact and release shows success on successful button press', async () => { | ||
// screen.getByRole('button', {name: 'Rediger'}).click(); | ||
// await vi.waitFor(() => screen.getByRole('textbox', {name: 'Avleverer'})); | ||
// | ||
// screen.getByRole('button', {name: 'Lagre'}).click(); | ||
// await vi.waitFor(() => screen.getByText('Kontakt- og utgivelsesinformasjon lagret!')); | ||
// }); | ||
// | ||
// test('Title page contact and release should have release pattern', async () => { | ||
// 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(); | ||
// | ||
// screen.getByRole('button', {name: 'Rediger'}).click(); | ||
// await vi.waitFor(() => screen.getByRole('heading', {name: 'Utgivelsesmønster:'})); | ||
// expect(screen.getAllByRole('gridcell', {name: '1'})).toBeTruthy(); | ||
// expect(screen.getAllByRole('gridcell', {name: '0'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Mandag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Tirsdag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Onsdag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Torsdag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Fredag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Lørdag'})).toBeTruthy(); | ||
// expect(screen.getByRole('rowheader', {name: 'Søndag'})).toBeTruthy(); | ||
// }); | ||
// | ||
// test('Title page contact and release should show error message on unsuccessful submit', async () => { | ||
// cleanup(); | ||
// render(<Page params={{id: MockTitle.id.toString()}} />); | ||
// // Mock rejected promise | ||
// vi.mocked(putLocalTitle).mockImplementation(() => Promise.reject(new Error('Noe gikk galt ved lagring'))); | ||
// | ||
// screen.getByRole('button', {name: 'Rediger'}).click(); | ||
// await vi.waitFor(() => screen.getByRole('textbox', {name: 'Avleverer'})); | ||
// | ||
// screen.getByRole('button', {name: 'Lagre'}).click(); | ||
// await vi.waitFor(() => screen.getByText('Noe gikk galt ved lagring', {exact: false})); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
|
@@ -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', | ||
}; |
Oops, something went wrong.