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

What's new section includes last opened version #2453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

### Fixed 🐞

- Fix what's new section including the last opened version ([#2447](https://github.com/MaibornWolff/codecharta/pull/2453))
- Fix unfocus button text not showing correctly ([#2439](https://github.com/MaibornWolff/codecharta/pull/2439))

### Changed
Expand Down
@@ -1,33 +1,72 @@
import "./dialog.module.ts"
import { DialogChangelogController } from "./dialog.changelog.component"
import { getService, instantiateModule } from "../../../../mocks/ng.mockhelper"
import packageJson from "../../../../package.json"

describe("DialogChangelogController", () => {
let dialogChangelogController: DialogChangelogController
let $mdDialog

beforeEach(() => {
Storage.prototype.getItem = jest.fn(() => "1.76.0")
restartSystem()
Storage.prototype.getItem = jest.fn(() => "1.70.0")
rebuildController()
dialogChangelogController = new DialogChangelogController($mdDialog)
})

function restartSystem() {
instantiateModule("app.codeCharta.ui.dialog")
$mdDialog = getService("$mdDialog")
}
function rebuildController() {
dialogChangelogController = new DialogChangelogController($mdDialog)
}

describe("constructor", () => {
it("should extract the changes from changelog since last time visited", () => {
Storage.prototype.getItem = jest.fn(() => "1.70.0")
rebuildController()
const added = "Added 🚀"
const fixed = "Fixed 🐞"
const removed = "Removed 🗑"
const changed = "Changed"
const chore = "Chore 👨‍💻 👩‍💻"

it("should extract the changes from changelog only for the last version", () => {
Storage.prototype.getItem = jest.fn(() => "1.76.0")
packageJson.version = "1.77.0"
dialogChangelogController = new DialogChangelogController($mdDialog)

expect(dialogChangelogController["_viewModel"].changes).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes[added]).toBeUndefined()
expect(dialogChangelogController["_viewModel"].changes[fixed]).toBe(
'<li>3 (<a href="">#3</a>)</li>\n' + '<li>4 (<a href="">#4</a>)</li>\n' + '<li>5 (<a href="">#5</a>)</li>'
)
expect(dialogChangelogController["_viewModel"].changes[removed]).toBeUndefined()
expect(dialogChangelogController["_viewModel"].changes[changed]).toBeUndefined()
expect(dialogChangelogController["_viewModel"].changes[chore]).toBe('<li>6 (<a href="">#6</a>)</li>')
})

it("should extract the changes from changelog for 2 versions", () => {
packageJson.version = "1.77.0"
Storage.prototype.getItem = jest.fn(() => "1.75.0")
dialogChangelogController = new DialogChangelogController($mdDialog)

expect(dialogChangelogController["_viewModel"].changes).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes["Added 🚀"]).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes["Fixed 🐞"]).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes["Removed 🗑"]).toBeUndefined()
expect(dialogChangelogController["_viewModel"].changes[added]).toBe(
'<li>7 (<a href="">#7</a>)</li>\n' + '<li>8 (<a href="">#8</a>)</li>'
)
expect(dialogChangelogController["_viewModel"].changes[fixed]).toBe(
'<li>3 (<a href="">#3</a>)</li>\n' + '<li>4 (<a href="">#4</a>)</li>\n' + '<li>5 (<a href="">#5</a>)</li>'
)
expect(dialogChangelogController["_viewModel"].changes[chore]).toBe('<li>6 (<a href="">#6</a>)</li>')
// Expect nested list to be correctly parsed
expect(dialogChangelogController["_viewModel"].changes[changed]).toBe(
"<li>\n" +
'<p>9 (<a href="">#9</a>)</p>\n' +
"</li>\n" +
"<li>\n" +
'<p>10 (<a href="">#10</a>)</p>\n' +
"<ul>\n" +
"<li>10.1</li>\n" +
"<li>10.2</li>\n" +
"</ul>\n" +
"</li>"
)
expect(dialogChangelogController["_viewModel"].changes[removed]).toBeUndefined()
})
})

Expand Down
Expand Up @@ -21,10 +21,9 @@ export class DialogChangelogController {
let changelogLines = markdownFile.split("\n")
const currentVersionFirstLine = this.findVersionLine(changelogLines, this._viewModel.currentVersion)
const lastOpenedVersionFirstLine = this.findVersionLine(changelogLines, this._viewModel.lastOpenedVersion)
const lastOpenedVersionLastLine = this.findEndVersionLine(changelogLines, lastOpenedVersionFirstLine)

changelogLines = changelogLines.slice(currentVersionFirstLine, lastOpenedVersionLastLine)

//Add 1 to keep the version line so that it detects the end of the last set of changes
changelogLines = changelogLines.slice(currentVersionFirstLine, lastOpenedVersionFirstLine + 1)
IhsenBouallegue marked this conversation as resolved.
Show resolved Hide resolved
const titles = ["Added 🚀", "Fixed 🐞", "Changed", "Removed 🗑", "Chore 👨‍💻 👩‍💻"]
const changes = {}
for (const title of titles) {
Expand Down Expand Up @@ -61,11 +60,7 @@ export class DialogChangelogController {
}

private findEndChangesLine(lines: string[], startLine: number): number {
return startLine + lines.slice(startLine + 1).findIndex(element => /<h3>/.test(element))
}

private findEndVersionLine(lines: string[], versionLine: number): number {
return versionLine + lines.slice(versionLine + 1).findIndex(element => /<h2>/.test(element))
return startLine + lines.slice(startLine + 1).findIndex(element => /<h3>/.test(element) || /<h2>/.test(element))
}
}

Expand Down