Skip to content

Commit

Permalink
Implemented Data Editor Svelte Test Structure
Browse files Browse the repository at this point in the history
- Added yarn script to run data editor tests using Mocha.
- Added example function and Svelte store tests.

Closes #915
  • Loading branch information
stricklandrbls committed Jan 1, 2024
1 parent d7f7088 commit 4e45b16
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"prewatch": "yarn gen-version-ts && yarn sbt",
"watch": "run-func build/yarn-scripts.ts watch",
"watch:svelte": "yarn webpack --env development=true -w -c ./src/svelte/webpack.config.js",
"watch:svelte-tests" : "mocha -r ts-node/register -w ./src/svelte/tests/**/*.test.ts",
"webpack": "webpack --mode production --config ./webpack/ext-dev.webpack.config.js",
"webpack:pkg": "webpack --mode production --config ./webpack/ext-package.webpack.config.js",
"webpack:svelte": "webpack -c ./src/svelte/webpack.config.js",
"prepackage": "yarn install && yarn compile && yarn webpack:pkg",
"package": "run-func build/yarn-scripts.ts package && yarn --cwd dist/package install && yarn --cwd dist/package vsce package --out ../../",
"pretest": "yarn compile && yarn webpack",
"test": "sbt test && node ./out/tests/runTest.js",
"test": "sbt test && yarn test:svelte && node ./out/tests/runTest.js",
"test:svelte": "mocha -r ts-node/register ./src/svelte/tests/**/*.test.ts",
"sbt": "sbt debugger/Universal/packageBin",
"svelte:check": "svelte-check --tsconfig ./tsconfig.json"
},
Expand Down
2 changes: 1 addition & 1 deletion src/svelte/src/components/Header/fieldsets/FileMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import { SimpleWritable } from '../../../stores/localStore'

class FileMetricsData {
export class FileMetricsData {
name: string = ''
type: string = ''
language: string = ''
Expand Down
62 changes: 62 additions & 0 deletions src/svelte/tests/stores/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, it } from 'mocha'
import { fileMetrics, regularSizedFile, saveable } from '../../src/stores/index'
import assert from 'assert'
import { get } from 'svelte/store'
import { FileMetricsData } from '../../src/components/Header/fieldsets/FileMetrics'

describe('Data Editor Stores ( Derived )', () => {
describe('regularSizedFile', () => {
const TruthySize = 1024
const FalsySize = 1

it('should return true on regular computed sized viewports', () => {
fileMetrics.update((metrics) => {
metrics.computedSize = TruthySize
return metrics
})
assert.equal(get(regularSizedFile), true)
})
it('should return false on non-regular computed sized viewports', () => {
fileMetrics.update((metrics) => {
metrics.computedSize = FalsySize
return metrics
})
assert.equal(get(regularSizedFile), false)
})
after(() => {
fileMetrics.set(new FileMetricsData())
})
})

describe('saveable', () => {
it('should report boolean value derived from fileMetrics.changeCount', () => {
;[
{ count: 2, expect: true },
{ count: 0, expect: false },
].forEach((testValues) => {
fileMetrics.update((metrics) => {
metrics.changeCount = testValues.count
return metrics
})
assert.equal(get(saveable), testValues.expect)
})
})
})
})
55 changes: 55 additions & 0 deletions src/svelte/tests/utilities/display.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, it } from 'mocha'
import { radixBytePad, radixToString } from '../../src/utilities/display'
import { RadixValues } from '../../src/stores/configuration'
import assert from 'assert'

describe('Display Functions', () => {
describe('radixBytePad', () => {
it('should return the appropriate text length per radix value given', () => {
;[
{ radix: 2, pad: 8 },
{ radix: 8, pad: 3 },
{ radix: 10, pad: 3 },
{ radix: 16, pad: 2 },
].forEach((assertionPair) => {
assert.equal(
radixBytePad(assertionPair.radix as RadixValues),
assertionPair.pad
)
})
})
})

describe('radixToString', () => {
it('should return the correct radix index string from RadixValue', () => {
;[
{ radix: 2, str: 'bin' },
{ radix: 8, str: 'oct' },
{ radix: 10, str: 'dec' },
{ radix: 16, str: 'hex' },
].forEach((assertionPair) => {
assert.equal(
radixToString(assertionPair.radix as RadixValues),
assertionPair.str
)
})
})
})
})

0 comments on commit 4e45b16

Please sign in to comment.