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 1 commit
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,14 +1,15 @@
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()
})

Expand All @@ -21,13 +22,93 @@ describe("DialogChangelogController", () => {
}

describe("constructor", () => {
it("should extract the changes from changelog since last time visited", () => {
Storage.prototype.getItem = jest.fn(() => "1.70.0")
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"
rebuildController()
IhsenBouallegue marked this conversation as resolved.
Show resolved Hide resolved
expect(dialogChangelogController["_viewModel"].changes).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes["Added 🚀"]).not.toBeNull()
expect(dialogChangelogController["_viewModel"].changes["Fixed 🐞"]).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>')
IhsenBouallegue marked this conversation as resolved.
Show resolved Hide resolved
})
it("should extract the changes from changelog for 2 versions", () => {
packageJson.version = "1.77.0"
Storage.prototype.getItem = jest.fn(() => "1.75.0")
rebuildController()
expect(dialogChangelogController["_viewModel"].changes).not.toBeNull()
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(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()
})
})

describe("find version line", () => {
it("should find the first version line", () => {
const versionLine = dialogChangelogController.findVersionLine(
["</ul>", "<h2>[1.77.0] - 2021-07-30</h2>", "<h3>Fixed 🐞</h3>", "<h2>[1.76.0] - 2021-06-30</h2>"],
"1.77.0"
)

expect(versionLine).toBe(1)
})
})

describe("find changes end line", () => {
it("should find the end line of the given changes before another change list ", () => {
const versionLine = dialogChangelogController.findEndChangesLine(
["<ul>", '<a href="">#7</a>)</li>\n', '<li>8 (<a href="">#8</a>)</li>', "</ul>", "<h3>Fixed 🐞</h3>"],
0
)

expect(versionLine).toBe(3)
})
it("should find the end line of the given changes before a new version ", () => {
const versionLine = dialogChangelogController.findEndChangesLine(
["<ul>", '<a href="">#7</a>)</li>\n', '<li>8 (<a href="">#8</a>)</li>', "</ul>", "<h2>[1.76.0] - 2021-06-30</h2>"],
0
)

expect(versionLine).toBe(3)
})
})

describe("get all indexes", () => {
it("should find the indexes of every occurrence of the pattern", () => {
const indexes = dialogChangelogController.getAllIndexes(
IhsenBouallegue marked this conversation as resolved.
Show resolved Hide resolved
[
"</ul>",
"<h2>[1.77.0] - 2021-07-30</h2>",
"<h3>Fixed 🐞</h3>",
"<h2>[1.76.0] - 2021-06-30</h2>",
"</ul>",
"<h2>[1.77.0] - 2021-07-30</h2>",
"<h3>Fixed 🐞</h3>"
],
/Fixed 🐞/
)

expect(indexes).toEqual([2, 6])
})
})

Expand Down
Expand Up @@ -22,6 +22,7 @@ export class DialogChangelogController {
const currentVersionFirstLine = this.findVersionLine(changelogLines, this._viewModel.currentVersion)
const lastOpenedVersionFirstLine = this.findVersionLine(changelogLines, this._viewModel.lastOpenedVersion)

//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 = {}
Expand All @@ -46,19 +47,19 @@ export class DialogChangelogController {
this.$mdDialog.hide()
}

private getAllIndexes(titles: string[], pattern: RegExp) {
getAllIndexes(titles: string[], pattern: RegExp) {
return titles.reduce((matchingTitleIndexes, title, index) => {
if (pattern.test(title)) matchingTitleIndexes.push(index)
return matchingTitleIndexes
}, [])
}

private findVersionLine(lines: string[], version: string): number {
findVersionLine(lines: string[], version: string): number {
const versionPattern = new RegExp(version.replace(".", "\\."))
return lines.findIndex(element => versionPattern.test(element))
}

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