Skip to content

Commit

Permalink
update cypress + fix cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JStruk committed Sep 6, 2023
1 parent f928b54 commit 2e9ea74
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 154 deletions.
9 changes: 5 additions & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
}
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173',
experimentalRunAllSpecs: true
},
})
2 changes: 1 addition & 1 deletion cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Navigation', () => {
it('can visit the tools page', () => {
cy.visit('/tools')

cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools`)
cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools/json-formatter`)

// TODO: dynamically check for util tabs based on registry of utils
cy.contains('JSON Format')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/pages/HomeView.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('HomeView', () => {
cy.visit('/')
cy.contains('View Tools').click()

cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools`)
cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools/json-formatter`)
})

it('allows the user to go to the Tools page via navbar', () => {
cy.visit('/')
cy.contains('Tools').click()

cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools`)
cy.url().should('be.equal', `${Cypress.config('baseUrl')}/tools/json-formatter`)
})
})
6 changes: 3 additions & 3 deletions cypress/e2e/utils/StringInspector.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ describe('String Inspector', () => {


it('should allow the user to enter text', () => {
cy.get('textarea').type(text)
cy.get('textarea[aria-label="string-inspector"]').type(text, { scrollBehavior: 'center' })
})

it('should display the results of the inspected string', () => {
cy.get('textarea').type(sentence)
cy.get('textarea[aria-label="string-inspector"]').type(sentence, { scrollBehavior: 'center' })

const inspectorResult: InspectionResult = inspect(sentence)

Expand All @@ -25,7 +25,7 @@ describe('String Inspector', () => {
})

it('should display the word distribution for the inspected string', function () {
cy.get('textarea').type(sentence)
cy.get('textarea[aria-label="string-inspector"]').type(sentence, { scrollBehavior: 'center' })

const inspectorResult: InspectionResult = inspect(sentence)

Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/utils/csvtojson.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import { CSVToJSON } from '../../../src/utilities/CSVToJSON'

describe('CSV to JSON', () => {
beforeEach(() => {
cy.visit('/tools/csvtojson')
cy.visit('/tools/csv-to-json')
})

it('should allow the user to type text into textarea', () => {
cy.get('textarea[placeholder="CSV Data"]').type('I am the walrus')
cy.get('textarea[placeholder="CSV Data"]').type('I am the walrus', { scrollBehavior: 'center' })
})

it('should accept user CSV and output converted JSON', () => {
const CSVData = "Name,Age,Height\nJoe,25,5'10\nMike,30,6'0"

cy.get('textarea[placeholder="CSV Data"]').type(CSVData)
cy.get('textarea[placeholder="CSV Data"]').type(CSVData, { scrollBehavior: 'center' })
cy.contains('Convert').click()

const expectedJSON = CSVToJSON(CSVData)
cy.get('textarea[placeholder="JSON format"]').invoke('val').should('equal', expectedJSON)
})

it('should return an empty array if the CSV data cannot be parsed', () => {
cy.get('textarea[placeholder="CSV Data"]').type('I am the walrus')
cy.get('textarea[placeholder="CSV Data"]').type('I am the walrus', { scrollBehavior: 'center' })
cy.contains('Convert').click()
cy.get('textarea[placeholder="JSON format"]').invoke('val').should('equal', '[]')
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/utils/jsontocsv.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JSONtoCSV } from '../../../src/utilities/JSONToCSV'

describe('CSV to JSON', () => {
beforeEach(() => {
cy.visit('/tools/jsontocsv')
cy.visit('/tools/json-to-csv')
})

it('should allow the user to type text into textarea', () => {
Expand Down
Loading

0 comments on commit 2e9ea74

Please sign in to comment.