Skip to content

Commit

Permalink
Cypress: added missing mocks
Browse files Browse the repository at this point in the history
Also fixed some unit tests that needed to be updated
  • Loading branch information
warpdesign committed May 15, 2024
1 parent 8784b23 commit a1ba3f1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 57 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x]
node-version: [16.x]
os: [ubuntu-latest]
experimental: [false]
# include:
Expand All @@ -26,9 +26,15 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -y libsdl-pango-dev libgif-dev
fi
shell: bash
- name: Install node_modules
working-directory: ./
run: npm ci
run: npm ci && npm rebuild canvas --update-binary
- name: Install e2e node_modules
run: npm ci
- name: Build E2E version
Expand Down
5 changes: 5 additions & 0 deletions e2e/cypress/mocks/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ module.exports = {
writeText: function(text) {
//
}
},
webFrame: {
setVisualZoomLevelLimits: function (minimumLevel, maximumLevel) {
//
}
}
};
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
preset: 'ts-jest',
setupFilesAfterEnv: [
"<rootDir>/setupTests.ts",
'jest-canvas-mock'
],
moduleDirectories: [
'node_modules',
Expand Down
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"husky": "^3.0.9",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.3.1",
"jest-canvas-mock": "^2.4.0",
"jest-cli": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lint-staged": "^10.4.2",
Expand Down
18 changes: 18 additions & 0 deletions setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ import '@testing-library/jest-dom'
import '@testing-library/jest-dom/extend-expect'

global.console.error = jest.fn()

interface KeyboardIterator extends Iterator<[string, string]> {
length: number
[key: number]: [string, string]
}

interface KeyboardMap {
entries: () => KeyboardIterator
}

// some tests are not executed with dom so won't have navigator property defined
if (global.navigator)
global.navigator.keyboard = {
getLayoutMap: () =>
Promise.resolve(<KeyboardMap>({
entries: () => [] as unknown as [string, string],
} as unknown as KeyboardMap)),
}
4 changes: 2 additions & 2 deletions src/components/dialogs/__tests__/shortcutsDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('ShortcutsDialog', () => {
beforeEach(() => jest.resetAllMocks())

describe('shortcuts list', () => {
it('should render shortcuts', () => {
it('should render shortcuts', async () => {
render(<ShortcutsDialog {...DEFAULT_PROPS} />)
expect(screen.getByText(exitLabel)).toBeInTheDocument()
expect(await screen.findByText(exitLabel)).toBeInTheDocument()
expect(screen.getByText(reloadViewLabel)).toBeInTheDocument()
})

Expand Down
36 changes: 12 additions & 24 deletions src/services/__tests__/FsSort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const files: Array<FileDescriptor> = [
mode: 16877,
isDir: true,
readonly: false,
id: {
ino: 0n,
dev: 1n,
},
id: '0-1',
isSym: false,
target: '',
type: '',
Expand All @@ -37,10 +34,7 @@ const files: Array<FileDescriptor> = [
mode: 33188,
isDir: false,
readonly: false,
id: {
ino: 1n,
dev: 1n,
},
id: '1-1',
isSym: false,
target: '',
type: '',
Expand All @@ -57,10 +51,7 @@ const files: Array<FileDescriptor> = [
mode: 33188,
isDir: false,
readonly: false,
id: {
ino: 2n,
dev: 1n,
},
id: '2-1',
isSym: false,
target: '',
type: '',
Expand All @@ -77,10 +68,7 @@ const files: Array<FileDescriptor> = [
mode: 33188,
isDir: false,
readonly: false,
id: {
ino: 3n,
dev: 1n,
},
id: '3-1',
isSym: false,
target: '',
type: '',
Expand All @@ -90,25 +78,25 @@ const files: Array<FileDescriptor> = [
describe('sorting methods', () => {
it('sort by Name/Asc', () => {
const sortMethod = getSortMethod('name', 'asc')
const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino)
expect(sorted_ids).toEqual([2n, 0n, 1n, 3n])
const sorted_ids = files.sort(sortMethod).map((file) => file.id)
expect(sorted_ids).toEqual(['2-1', '0-1', '1-1', '3-1'])
})

it('sort by Name/Desc', () => {
const sortMethod = getSortMethod('name', 'desc')
const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino)
expect(sorted_ids).toEqual([3n, 1n, 0n, 2n])
const sorted_ids = files.sort(sortMethod).map((file) => file.id)
expect(sorted_ids).toEqual(['3-1', '1-1', '0-1', '2-1'])
})

it('sort by Size/Asc', () => {
const sortMethod = getSortMethod('size', 'asc')
const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino)
expect(sorted_ids).toEqual([1n, 0n, 3n, 2n])
const sorted_ids = files.sort(sortMethod).map((file) => file.id)
expect(sorted_ids).toEqual(['1-1', '0-1', '3-1', '2-1'])
})

it('sort by Size/Asc', () => {
const sortMethod = getSortMethod('size', 'desc')
const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino)
expect(sorted_ids).toEqual([2n, 3n, 0n, 1n])
const sorted_ids = files.sort(sortMethod).map((file) => file.id)
expect(sorted_ids).toEqual(['2-1', '3-1', '0-1', '1-1'])
})
})
5 changes: 1 addition & 4 deletions src/services/plugins/__tests__/FsLocal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,7 @@ describe('FsLocal', () => {
length: fsStat.size,
isDir: false,
isSym: false,
id: {
dev: fsStat.dev,
ino: fsStat.ino,
},
id: `${fsStat.ino}-${fsStat.dev}`,
mode: fsStat.mode,
readonly: false,
target: null,
Expand Down

0 comments on commit a1ba3f1

Please sign in to comment.