Skip to content

Commit

Permalink
added Cypress tests for project (rest), see #225
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron Valstar committed May 15, 2020
1 parent e7a52b0 commit c394958
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "project-invoice",
"version": "3.0.11",
"version": "3.0.12",
"description": "Invoicing without sharing data.",
"keywords": [],
"main": "src/index.js",
Expand Down
2 changes: 1 addition & 1 deletion public/static/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"quotation": "quotation",
"quotationAfter": "text after",
"quotationBefore": "text before",
"quotationDate": "datum",
"quotationDate": "date",
"quotationDuration": "project duration",
"quotationStartDate": "start date",
"quotationSubject": "project subject",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Tab = styled.button`
line-height: 100%;
}`

export const Tabs = ({ currentIndex=0, children }) => {
export const Tabs = ({ currentIndex=0, children, ...attr }) => {
const [selectedChildIndex, setSelectedChildIndex] = useState(currentIndex)
const tabs = children
.map(section=>firstChildType(section, 'h3'))
Expand All @@ -64,7 +64,7 @@ export const Tabs = ({ currentIndex=0, children }) => {
><h3>{children}</h3></Tab>)
;
const selectedChild = children[selectedChildIndex]
return <StyledTabs>
return <StyledTabs {...attr}>
<nav>{tabs}</nav>
{selectedChild}
</StyledTabs>
Expand Down
11 changes: 6 additions & 5 deletions src/views/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ export const Project = withRouter(
</Table>
</section>

<Tabs currentIndex={project.invoices.length?0:1}>
<section>
<Tabs currentIndex={project.invoices.length?0:1} data-cy="tabs">
<section data-cy="tabInvoices">
<Button onClick={onClickAddInvoiceButton} className="float-right" data-cy="addInvoice"><T>{project.invoices.length&&'addReminder'||'addInvoice'}</T></Button>
<h3 className="invisible"><T>invoices</T></h3>
<TransitionGroup component="ol" data-cy="invoices">
Expand All @@ -291,7 +291,7 @@ export const Project = withRouter(
>
<li className="row no-gutters" key={index}>
<div className="col-4">
<ButtonLink to={`${getProjectHref(project)}/${invoice.type}${index!==0?'/'+index:''}`}>
<ButtonLink to={`${getProjectHref(project)}/${index===0?'invoice':'reminder'}${index!==0?'/'+index:''}`}>
<T>{index===0?'invoice':'reminder'}</T>
{index!==0?nbsp + index:''}
</ButtonLink>
Expand All @@ -313,8 +313,8 @@ export const Project = withRouter(
</TransitionGroup>
</section>

<section>
<ButtonLink to={`${getProjectHref(project)}/quotation`} className="float-right"><T>show quotation</T></ButtonLink>
<section data-cy="tabQuotation">
<ButtonLink to={`${getProjectHref(project)}/quotation`} className="float-right" data-cy="showQuotation"><T>show quotation</T></ButtonLink>
<h3 className="invisible"><T>quotation</T></h3>
{[
{ key: 'quotationDate', Element: InputDate }
Expand Down Expand Up @@ -345,6 +345,7 @@ export const Project = withRouter(
const {bottom, height, left, right, top, width, x, y} = r
return {bottom: bottom-4, height, left, right, top, width, x, y}
}}
data-cy="dialog"
>
<Label><T>date</T><InputDate value={invoice.date} setter={getInvoiceSetter('date')}/></Label>
{invoice.type!=='invoice'&&<>
Expand Down
67 changes: 61 additions & 6 deletions src/views/project.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

const clientUri = '/client/20'
const projectUri = `${clientUri}/114`
const projectUriQuotation = `${clientUri}/114/quotation`
const projectUriInvoice = `${clientUri}/114/invoice`
const projectUriReminder = `${clientUri}/114/reminder/1`
const projectUriClone = `${clientUri}/115`
const projectUriPrevious = `${clientUri}/73`
const projectDescription = 'Two barrels of pig food'
const projectLine1 = 'Digging up a ton of potatoes'
const projectLine2 = 'Peeling all the potatoes'
const projectDescription = 'Pig food'
const projectLine1 = 'Get potatoes'
const projectLine2 = 'Peel potatoes'
const quotationDate = '2020-03-15'
const invoiceDate = '2020-04-15'

before(() => cy
.visitPage(clientUri)
Expand Down Expand Up @@ -91,9 +96,59 @@ describe('project', () => {
.get('@totalIncVAT').should('have.text', (400*1.21 + 700*1.06).toFixed(2))
)

// it('should have quotation tab selected without invoices', () => cy
//
// )
it('should have quotation tab selected without invoices', () => cy
.get('[data-cy=tabInvoices]').should('not.exist')
.get('@tabQuotation').should('be.visible')
.get('@tabs').find('nav button:contains(invoices)').click()
.get('[data-cy=tabInvoices]').should('be.visible')
.get('@tabs').find('nav button:contains(quotation)').click()
)

it('should able to create a quotation', () => cy
.get('@tabQuotation').find('label:contains(date) input').first()
.type(quotationDate)
.tab().type(quotationDate)
.tab().type('14')
.tab().type(projectDescription)
.tab().type('Here is the quotation')
.get('@tabQuotation').find('label:contains(text after) input').first()
.type('Kind regards etc')
.get('@save').click()
.get('@showQuotation').click()
.expectPathname(projectUriQuotation)
.get(`:contains(${projectDescription})`)
.go('back')
)

it('should be able to add invoices', () => cy
.get('@tabs').find('nav button:contains(invoices)').click()
.asAll()
.get('@tabInvoices').should('be.visible')
.get('@invoices').find('li').should('have.length', 0)
.get('@addInvoice').click()
.get('@save').click()
.get('@invoices').find('li').should('have.length', 1)
.find('a:contains(invoice)').click()
.expectPathname(projectUriInvoice)
.go('back')
)

it('should be able to add reminder', () => cy
.get('@addInvoice').click()
.get('@save').click()
.get('@invoices').find('li').should('have.length', 2)
.find('a:contains(reminder)').click()
.expectPathname(projectUriReminder)
.go('back')
)

it('should be able set invoice date', () => cy
.get('@invoices').find('li').first().find('button').last().click()
.get('[data-cy=dialog]').find('input').first().type(invoiceDate)
.get('[data-cy=dialog]').find('button:contains(ok)').click()
.get('@save').click()
.get('@invoices').find('li').first().find(`div:contains(${invoiceDate})`).should('exist')
)


})

0 comments on commit c394958

Please sign in to comment.