Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove feature and cypress ci #71

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: cypress-io/github-action@v2
- uses: actions/checkout@v2
- uses: cypress-io/github-action@v4
with:
record: true
browser: chrome
Expand Down
14 changes: 14 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'cypress'

export default defineConfig({
projectId: '8759xt',
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:3000/',
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
},
})
4 changes: 0 additions & 4 deletions cypress.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,14 @@ context('Scene Deletion', () => {
cy.get(`[data-testid=${currentSceneId}]`).should("have.css", "border", SelectedSceneBorder)
})

})
it('Make 2nd to current and then delete second', () => {
const currentSceneId = getSceneId(scenes[1]);
const nextSceneId = getSceneId(scenes[2]);
cy.get(`[data-testid=${currentSceneId}]`).click();
const sceneIdToDelete = getSceneId(scenes[1]);
cy.get(`[data-testid=${sceneIdToDelete}]`).contains(`${DeleteButtonText}`).click({ force: true })
cy.get(`[data-testid=${sceneIdToDelete}]`).should("not.exist")
cy.get(`[class=Claymate-scenes]`).first()
.get(`[data-testid=${nextSceneId}]`).should("have.css", "border", SelectedSceneBorder)
})
})
File renamed without changes.
54 changes: 26 additions & 28 deletions src/Claymate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,33 @@ const Claymate = ({
};

const deleteScene = (id: string) => {
const index = scenes.findIndex((sc) => sc.id === id);
if (index >= 0) {
const remainingScenes = scenes.length - 1;
if (remainingScenes > 0) {
let newCurrent;
if (currentIndex !== undefined) {
const deletingCurrentScene = index === currentIndex;
if (currentIndex > index || deletingCurrentScene) {
let sourceIndex = currentIndex;
if (deletingCurrentScene) {
if (currentIndex === remainingScenes) {
sourceIndex = currentIndex - 1;
} else if (currentIndex === 0) {
sourceIndex = 1;
}
}
newCurrent = {
index: currentIndex > 0 ? currentIndex - 1 : currentIndex,
drawing: scenes[sourceIndex].drawing,
};
}
}
updateScenes(
(prev: Scene[]) => prev.filter((item) => item.id !== id),
newCurrent
);
}
const deletedSceneIndex = scenes.findIndex((item) => item.id === id);
if(deletedSceneIndex < 0) return;
let nextSelectedScene = undefined;

if (currentIndex !== undefined){
const remainingScenesCount = scenes.length - 1;
const nextIndex = currentIndex === remainingScenesCount || currentIndex > deletedSceneIndex
? currentIndex - 1
: currentIndex;

const nextDrawingIndex = deletedSceneIndex <= currentIndex && remainingScenesCount !== deletedSceneIndex
? nextIndex + 1
: nextIndex;

nextSelectedScene = {
index: nextIndex,
drawing: scenes[nextDrawingIndex].drawing
};
}
};

updateScenes((prev) => {
const next = [...prev];
next.splice(deletedSceneIndex, 1);
return next;
}, nextSelectedScene
);
}

const moveLeft = (id: string) => {
const index = scenes.findIndex((item) => item.id === id);
Expand Down